我有这两种几乎相同的方法。唯一的区别是方法签名。最后一个参数可以是一个对象,也可以是一个对象列表。我觉得有一种方法可以将这些结合起来,但我不知道如何。
public Query where(String selection, String operator, Object value) {
WhereClause clause = null;
try {
if (!columns.contains(selection)) {
throw new Exception("No such field for the " + model.getClass().getSimpleName() + " model: " + selection);
}
clause = new WhereClause(selection, operator, value);
} catch (Exception e) {
clause = null;
e.printStackTrace();
}
if (clause != null) {
clauses.add(clause);
}
return this;
}
public Query where(String selection, String operator, List<Object> values) {
WhereClause clause = null;
try {
if (!columns.contains(selection)) {
throw new Exception("No such field for the " + model.getClass().getSimpleName() + " model: " + selection);
}
clause = new WhereClause(selection, operator, values);
} catch (Exception e) {
clause = null;
e.printStackTrace();
}
if (clause != null) {
clauses.add(clause);
}
return this;
}