KiePMMLPredicateFactory { public static KiePMMLPredicate getPredicate(Predicate predicate, DataDictionary dataDictionary) { logger.trace("getPredicate {}", predicate); if (predicate instanceof SimplePredicate) { final DataType dataType = dataDictionary.getDataFields().stream() .filter(dataField -> dataField.getName().getValue().equals(((SimplePredicate) predicate).getField().getValue())) .map(DataField::getDataType) .findFirst() .orElseThrow(() -> new KiePMMLException("Failed to find DataField for predicate " + ((SimplePredicate) predicate).getField().getValue())); return getKiePMMLSimplePredicate((SimplePredicate) predicate, dataType); } else if (predicate instanceof SimpleSetPredicate) { return getKiePMMLSimpleSetPredicate((SimpleSetPredicate) predicate); } else if (predicate instanceof CompoundPredicate) { return getKiePMMLCompoundPredicate((CompoundPredicate) predicate, dataDictionary); } else if (predicate instanceof True) { return getKiePMMLTruePredicate(); } else if (predicate instanceof False) { return getKiePMMLFalsePredicate(); } else { throw new KiePMMLException("Predicate of type " + predicate.getClass().getName() + " not managed, yet"); } } private  KiePMMLPredicateFactory(); static List<KiePMMLPredicate> getPredicates(List<Predicate> predicates, DataDictionary dataDictionary); static KiePMMLPredicate getPredicate(Predicate predicate, DataDictionary dataDictionary); static KiePMMLSimplePredicate getKiePMMLSimplePredicate(SimplePredicate predicate, DataType dataType); static KiePMMLSimpleSetPredicate getKiePMMLSimpleSetPredicate(SimpleSetPredicate predicate); static KiePMMLCompoundPredicate getKiePMMLCompoundPredicate(CompoundPredicate predicate,
                                                                       DataDictionary dataDictionary); static KiePMMLTruePredicate getKiePMMLTruePredicate(); static KiePMMLFalsePredicate getKiePMMLFalsePredicate(); static Map<String, String> getPredicateSourcesMap(final KiePMMLPredicate kiePMMLPredicate,
                                                             final String packageName);  }
@Test public void getPredicateSimple() { simplePredicates.forEach(simplePredicate -> { KiePMMLPredicate retrieved = KiePMMLPredicateFactory.getPredicate(simplePredicate, dataDictionary); assertTrue(retrieved instanceof KiePMMLSimplePredicate); }); }
@Test public void getPredicateSimpleSet() { simpleSetPredicates.forEach(simpleSetPredicate -> { KiePMMLPredicate retrieved = KiePMMLPredicateFactory.getPredicate(simpleSetPredicate, dataDictionary); assertTrue(retrieved instanceof KiePMMLSimpleSetPredicate); }); }
@Test public void getPredicateTrue() { True truePredicate = new True(); KiePMMLPredicate retrieved = KiePMMLPredicateFactory.getPredicate(truePredicate, dataDictionary); assertTrue(retrieved instanceof KiePMMLTruePredicate); }
@Test public void getPredicateFalse() { False falsePredicate = new False(); KiePMMLPredicate retrieved = KiePMMLPredicateFactory.getPredicate(falsePredicate, dataDictionary); assertTrue(retrieved instanceof KiePMMLFalsePredicate); }
@Test(expected = KiePMMLException.class) public void getPredicateUnknown() { Predicate unknownPredicate = new Predicate() { @Override public VisitorAction accept(Visitor visitor) { return null; } }; KiePMMLPredicateFactory.getPredicate(unknownPredicate, dataDictionary); }