class KiePMMLRegressionTableRegressionFactory {

    static MethodDeclaration addGroupedCategoricalPredictor(final List<CategoricalPredictor> categoricalPredictors, final ClassOrInterfaceDeclaration tableTemplate, int predictorArity) {
        try {
            templateEvaluate = getFromFileName(KIE_PMML_EVALUATE_METHOD_TEMPLATE_JAVA);
            cloneEvaluate = templateEvaluate.clone();
            ClassOrInterfaceDeclaration evaluateTemplateClass =
                    cloneEvaluate.getClassByName(KIE_PMML_EVALUATE_METHOD_TEMPLATE)
                            .orElseThrow(() -> new RuntimeException(MAIN_CLASS_NOT_FOUND));
            MethodDeclaration methodTemplate = evaluateTemplateClass.getMethodsByName("evaluateCategorical").get(0);
            final BlockStmt body =
                    methodTemplate.getBody().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_BODY_TEMPLATE, methodTemplate.getName())));
            IfStmt ifStmt = new IfStmt();
            for (int i = 0; i < categoricalPredictors.size(); i++) {
                CategoricalPredictor categoricalPredictor = categoricalPredictors.get(i);
                Expression lhe;
                if (categoricalPredictor.getValue() instanceof String) {
                    lhe = new StringLiteralExpr((String) categoricalPredictor.getValue());
                } else {
                    lhe = new NameExpr(categoricalPredictor.getValue().toString());
                }
                NodeList<Expression> expressions = NodeList.nodeList(lhe, new NameExpr("input"));
                MethodCallExpr conditionExpr = new MethodCallExpr(new NameExpr("Objects"), "equals", expressions);
                if (i == 0) {
                    ifStmt.setCondition(conditionExpr);
                    ifStmt.setThenStmt(new ReturnStmt(new DoubleLiteralExpr(String.valueOf(categoricalPredictor.getCoefficient()))));
                    body.addStatement(ifStmt);
                } else {
                    IfStmt elseIf = new IfStmt();
                    elseIf.setCondition(conditionExpr);
                    elseIf.setThenStmt(new ReturnStmt(new DoubleLiteralExpr(String.valueOf(categoricalPredictor.getCoefficient()))));
                    ifStmt.setElseStmt(elseIf);
                    ifStmt = elseIf;
                }
            }
            ifStmt.setElseStmt(new ReturnStmt(new DoubleLiteralExpr("0.0")));
            return addMethod(methodTemplate, tableTemplate, "evaluateCategoricalPredictor" + predictorArity);
        } catch (Exception e) {
            throw new KiePMMLInternalException("Failed to add CategoricalPredictors", e);
        }
    }

    private  KiePMMLRegressionTableRegressionFactory();

}