KiePMMLCompoundPredicate extends KiePMMLPredicate { @Override public boolean evaluate(Map<String, Object> values) { Boolean toReturn = null; for (KiePMMLPredicate kiePMMLPredicate : kiePMMLPredicates) { toReturn = operatorFunction.apply(toReturn, kiePMMLPredicate.evaluate(values)); } return toReturn != null && toReturn; } protected  KiePMMLCompoundPredicate(final String name, final List<KiePMMLExtension> extensions, final BOOLEAN_OPERATOR booleanOperator); static Builder builder(List<KiePMMLExtension> extensions, BOOLEAN_OPERATOR booleanOperator); @Override boolean evaluate(Map<String, Object> values); @Override String getId(); BOOLEAN_OPERATOR getBooleanOperator(); List<KiePMMLPredicate> getKiePMMLPredicates(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void evaluateCompoundPredicateSinglePredicate() { ARRAY_TYPE arrayType = ARRAY_TYPE.STRING; List<Object> stringValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN); KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.AND, Collections.singletonList(kiePMMLSimpleSetPredicateString)); Map<String, Object> inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT"); assertFalse(kiePMMLCompoundPredicate.evaluate(inputData)); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0)); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); arrayType = ARRAY_TYPE.INT; List<Object> intValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN); kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.AND, Collections.singletonList(kiePMMLSimpleSetPredicateInt)); inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0)); assertFalse(kiePMMLCompoundPredicate.evaluate(inputData)); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234"); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); }
@Test public void evaluateCompoundPredicateAnd() { ARRAY_TYPE arrayType = ARRAY_TYPE.STRING; List<Object> stringValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN); arrayType = ARRAY_TYPE.INT; List<Object> intValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN); KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.AND, Arrays.asList(kiePMMLSimpleSetPredicateString, kiePMMLSimpleSetPredicateInt)); Map<String, Object> inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0)); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0)); assertFalse(kiePMMLCompoundPredicate.evaluate(inputData)); inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT"); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234"); assertFalse(kiePMMLCompoundPredicate.evaluate(inputData)); inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0)); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234"); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); }
@Test public void evaluateCompoundPredicateOr() { ARRAY_TYPE arrayType = ARRAY_TYPE.STRING; List<Object> stringValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN); arrayType = ARRAY_TYPE.INT; List<Object> intValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN); KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.OR, Arrays.asList(kiePMMLSimpleSetPredicateString, kiePMMLSimpleSetPredicateInt)); Map<String, Object> inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT"); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0)); assertFalse(kiePMMLCompoundPredicate.evaluate(inputData)); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0)); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0)); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT"); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234"); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues.get(0)); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, "234"); assertTrue(kiePMMLCompoundPredicate.evaluate(inputData)); }
@Test(expected = IllegalArgumentException.class) public void evaluateCompoundPredicateSurrogate() { ARRAY_TYPE arrayType = ARRAY_TYPE.STRING; List<Object> stringValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateString = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_STRING_NAME, stringValues, arrayType, IN_NOTIN.IN); arrayType = ARRAY_TYPE.INT; List<Object> intValues = getObjects(arrayType, 4); KiePMMLSimpleSetPredicate kiePMMLSimpleSetPredicateInt = getKiePMMLSimpleSetPredicate(SIMPLE_SET_PREDICATE_INT_NAME, intValues, arrayType, IN_NOTIN.NOT_IN); KiePMMLCompoundPredicate kiePMMLCompoundPredicate = getKiePMMLCompoundPredicate(BOOLEAN_OPERATOR.SURROGATE, Arrays.asList(kiePMMLSimpleSetPredicateString, kiePMMLSimpleSetPredicateInt)); Map<String, Object> inputData = new HashMap<>(); inputData.put(SIMPLE_SET_PREDICATE_STRING_NAME, "NOT"); inputData.put(SIMPLE_SET_PREDICATE_INT_NAME, intValues.get(0)); kiePMMLCompoundPredicate.evaluate(inputData); }