@SuppressWarnings("cast") public boolean evaluate(T candidate) { Iterator<?> lValues = valueRetriever.retrieve(candidate); if (rValue == null && !lValues.hasNext()) { // if there are no values on the right hand side then it counts as null return true; } while (lValues.hasNext()) { Object lValue = lValues.next(); final boolean comparisonResult; switch (operator) { case EQUAL: comparisonResult = compare((Comparable<?>) lValue, rValue) == 0; break; case GREATER_THAN: comparisonResult = compare((Comparable<?>) lValue, rValue) > 0; break; case GREATER_OR_EQUAL: comparisonResult = compare((Comparable<?>) lValue, rValue) >= 0; break; case LESS_THAN: comparisonResult = compare((Comparable<?>) lValue, rValue) < 0; break; case LESS_OR_EQUAL: comparisonResult = compare((Comparable<?>) lValue, rValue) <= 0; break; default: throw new UnsupportedOperationException(); } if (comparisonResult) { // terminate early return true; } } return false; }
@Override public String toString() { return valueRetriever.toString() + operator + rValue; }
public Cost getCost() { return valueRetriever.getCost(); }