import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
import eu.etaxonomy.cdm.persistence.query.MatchMode;
public enum Operator {
AND,
- OR;
+ OR,
+ AND_NOT,
+ OR_NOT;
}
+ private static final EnumSet<Operator> NOT_OPERATORS = EnumSet.of(Operator.AND_NOT, Operator.OR_NOT);
+
private String propertyName;
private MatchMode matchMode;
- private boolean not = false;
-
private Operator operator = Operator.AND;
private List<T> values = null;
* @param matchMode is only applied if the <code>value</code> is a <code>String</code> object
*/
public Restriction(String propertyName, MatchMode matchMode, T ... values ) {
- this(propertyName, false, matchMode, values);
+ this(propertyName, Operator.AND, matchMode, values);
}
- public Restriction(String propertyName, boolean not, MatchMode matchMode, T ... values ) {
- this(propertyName, false, Operator.AND, matchMode, values);
- }
-
- public Restriction(String propertyName, boolean not, Operator operator, MatchMode matchMode, T ... values ) {
+ public Restriction(String propertyName, Operator operator, MatchMode matchMode, T ... values ) {
this.propertyName = propertyName;
- this.not = not;
this.operator = operator;
if(values.length > 0){
this.setValues(Arrays.asList(values));
getValues().add(value);
}
- /**
- *
- * @return the not
- */
- public boolean isNot() {
- return not;
- }
-
- /**
- * @param not the not to set
- */
- public void setNot(boolean not) {
- this.not = not;
- }
-
/**
* @return the operator
*/
this.operator = operator;
}
+ /**
+ * @return
+ */
+ public boolean isNot() {
+ return NOT_OPERATORS.contains(operator);
+ }
+
}
result = nameService.findByTitleWithRestrictions(null, "Name2", MatchMode.EXACT, restrictions, null, null, null, null);
assertEquals(0l, result.getCount().longValue());
- restrictions = Arrays.asList(new Restriction<String>("typeDesignations.typeSpecimen.titleCache", false, Restriction.Operator.OR, MatchMode.EXACT, "Specimen1"));
+ restrictions = Arrays.asList(new Restriction<String>("typeDesignations.typeSpecimen.titleCache", Restriction.Operator.OR, MatchMode.EXACT, "Specimen1"));
result = nameService.findByTitleWithRestrictions(null, "Name2", MatchMode.EXACT, restrictions, null, null, null, null);
assertEquals(2l, result.getCount().longValue());