class KiePMMLPredicateFactory {

    static Map<String, String> getKiePMMLCompoundPredicateSourcesMap(final KiePMMLCompoundPredicate kiePMMLCompoundPredicate, final String packageName) {
        String className = getSanitizedClassName(kiePMMLCompoundPredicate.getId());
        final Map<String, String> toReturn = new HashMap<>();
        if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) {
            kiePMMLCompoundPredicate.getKiePMMLPredicates().forEach(kiePMMLPredicate -> toReturn.putAll(getPredicateSourcesMap(kiePMMLPredicate, packageName)));
        }
        CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName,
                                                                                 KIE_PMML_COMPOUND_PREDICATE_TEMPLATE_JAVA, KIE_PMML_COMPOUND_PREDICATE_TEMPLATE);
        ClassOrInterfaceDeclaration predicateTemplate = cloneCU.getClassByName(className)
                .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
        final ConstructorDeclaration constructorDeclaration = predicateTemplate.getDefaultConstructor()
                .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR,
                                                                              predicateTemplate.getName())));
        Set<String> predicatesClasses = new HashSet<>();
        if (kiePMMLCompoundPredicate.getKiePMMLPredicates() != null) {
            predicatesClasses = kiePMMLCompoundPredicate.getKiePMMLPredicates().stream()
                    .map(predicate ->  packageName + "." + getSanitizedClassName(predicate.getId()))
                    .collect(Collectors.toSet());
        }
        if (!toReturn.keySet().containsAll(predicatesClasses)) {
            String missingClasses = String.join(", ", predicatesClasses);
            throw new KiePMMLException("Expected generated class " + missingClasses + " not found");
        }
        setCompoundPredicateConstructor(className,
                                        kiePMMLCompoundPredicate.getName(),
                                        constructorDeclaration,
                                        kiePMMLCompoundPredicate.getBooleanOperator(),
                                        predicatesClasses);
        toReturn.put(getFullClassName(cloneCU), cloneCU.toString());
        return toReturn;
    }

    private  KiePMMLPredicateFactory();

}