I need some understanding of what I'm running into with an issue. I have a method with the signature addTerm(enum, String, String...)
but when use it I get an error that says The method addTerm(Comparison, String, String...) in the type FTSearchBuilder is not applicable for the arguments (Comparison, String, String, String) - I also get the same error if I pass only a single string. Initially, I thought this was a problem with my vararg, but through testing I've found that if I change the initial argument from a Comparison to a String, my method works just fine. However, I have not had issues with passing an enum in other methods. Can anyone explain what is going on and how to fix this?
Code below in case it is useful.
Error
FTSearchBuilder sb = new FTSearchBuilder();
sb.addTerm(Comparison.EQ, "Form", "frmClaim", "frmClaimstub");
Works (with slight modification to addTerm to use String instead of enum)
FTSearchBuilder sb = new FTSearchBuilder();
sb.addTerm("=", "Form", "frmClaim", "frmClaimstub");
Comparison
public enum Comparison {
LT("<"), LTE("<="), EQ("="), GTE(">="), GT(">");
private final String text;
private Comparison(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
}
addTerm() (within FTSearchBuilder class)
public class FTSearchBuilder {
private String query;
public FTSearchBuilder() {
query = "";
}
public String getQuery() {
return this.query;
}
public void addTerm(Comparison operator, String fieldName, String... values) {
// Validate input
String queryTerm = "";
if (0 == values.length) {
throw new ArrayIndexOutOfBoundsException("No comparison values given");
}
for (int x = 0; x < values.length; x++) {
if (!StringUtil.isEmpty(values[x])) {
if (queryTerm.equals("")) {
queryTerm += "([" + fieldName + "]" + operator.getText() + enquote(values[x]);
} else {
queryTerm += " | [" + fieldName + "]" + operator.getText() + enquote(values[x]);
}
queryTerm += ")";
}
}
if (!query.equals("")) {
this.query += "&";
}
this.query += queryTerm;
}
public void addDateTerm(Comparison operator, String fieldName, String... values) {
// Validate input
String queryTerm = "";
if (0 == values.length) {
throw new ArrayIndexOutOfBoundsException("No comparison values given");
}
for (int x = 0; x < values.length; x++) {
if (!StringUtil.isEmpty(values[x])) {
if (queryTerm.equals("")) {
queryTerm += "([" + fieldName + "]" + operator.getText() + values[x];
} else {
queryTerm += " | [" + fieldName + "]" + operator.getText() + values[x];
}
queryTerm += ")";
}
}
if (!query.equals("")) {
this.query += "&";
}
this.query += queryTerm;
}
private String enquote(String s) {
return "\"" + s + "\"";
}
}