I need some understanding of what I am facing the problem. I have a method with a signature addTerm(enum, String, String...), but when I use it, I get an error message saying that the addTerm method (Comparison, String, String ...) in the FTSearchBuilder type is not applicable for arguments (Comparison, String, String, String). I also get the same error if I pass only one line. Initially, I thought this was a problem with my vararg, but through testing, I found that if I changed the original argument from comparing with a string, my method would work fine. However, I had no problems passing the enumeration in other methods. Can someone explain what is happening and how to fix it?
Code below if useful.
Error
FTSearchBuilder sb = new FTSearchBuilder();
sb.addTerm(Comparison.EQ, "Form", "frmClaim", "frmClaimstub");
Works (with a 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 () (in class FTSearchBuilder)
public class FTSearchBuilder {
private String query;
public FTSearchBuilder() {
query = "";
}
public String getQuery() {
return this.query;
}
public void addTerm(Comparison operator, String fieldName, String... values) {
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) {
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 + "\"";
}
}