KiePMMLSimplePredicate extends KiePMMLPredicate { protected boolean evaluation(Object inputValue) { switch (operator) { case EQUAL: return value.equals(inputValue); case NOT_EQUAL: return !value.equals(inputValue); case LESS_THAN: if (inputValue instanceof Number && value instanceof Number) { return ((Number) inputValue).doubleValue() < ((Number) value).doubleValue(); } else { return false; } case LESS_OR_EQUAL: if (inputValue instanceof Number && value instanceof Number) { return ((Number) inputValue).doubleValue() <= ((Number) value).doubleValue(); } else { return false; } case GREATER_THAN: if (inputValue instanceof Number && value instanceof Number) { return ((Number) inputValue).doubleValue() > ((Number) value).doubleValue(); } else { return false; } case GREATER_OR_EQUAL: if (inputValue instanceof Number && value instanceof Number) { return ((Number) inputValue).doubleValue() >= ((Number) value).doubleValue(); } else { return false; } case IS_MISSING: case IS_NOT_MISSING: throw new IllegalArgumentException(SURROGATE + " not supported, yet"); default: throw new KiePMMLException("Unknown OPERATOR " + operator); } } protected  KiePMMLSimplePredicate(final String name, final List<KiePMMLExtension> extensions, final OPERATOR operator); static Builder builder(String name, List<KiePMMLExtension> extensions, OPERATOR operator); @Override boolean evaluate(Map<String, Object> values); @Override String getName(); OPERATOR getOperator(); Object getValue(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void evaluationStringEqual() { Object value = "43"; KiePMMLSimplePredicate kiePMMLSimplePredicate = getKiePMMLSimplePredicate(OPERATOR.EQUAL, value); assertFalse(kiePMMLSimplePredicate.evaluation("NOT")); assertTrue(kiePMMLSimplePredicate.evaluation(value)); }
@Test public void evaluationStringNotEqual() { Object value = "43"; KiePMMLSimplePredicate kiePMMLSimplePredicate = getKiePMMLSimplePredicate(OPERATOR.NOT_EQUAL, value); assertFalse(kiePMMLSimplePredicate.evaluation(value)); assertTrue(kiePMMLSimplePredicate.evaluation("NOT")); }
@Test(expected = IllegalArgumentException.class) public void evaluationStringIsNotMissing() { Object value = "43"; KiePMMLSimplePredicate kiePMMLSimplePredicate = getKiePMMLSimplePredicate(OPERATOR.IS_NOT_MISSING, value); kiePMMLSimplePredicate.evaluation(value); }
@Test(expected = IllegalArgumentException.class) public void evaluationStringIsMissing() { Object value = "43"; KiePMMLSimplePredicate kiePMMLSimplePredicate = getKiePMMLSimplePredicate(OPERATOR.IS_MISSING, value); kiePMMLSimplePredicate.evaluation(value); }