class KiePMMLRegressionTableRegressionFactory {

    static MethodDeclaration addPredictorTerm(final PredictorTerm predictorTerm,
                                              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("evaluatePredictor").get(0);
            final BlockStmt body =
                    methodTemplate.getBody().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_BODY_TEMPLATE, methodTemplate.getName())));
            VariableDeclarator variableDeclarator = getVariableDeclarator(body, "fieldRefs")
                    .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_VARIABLE_IN_BODY,
                                                                                  "fieldRefs", body)));
            final List<Expression> nodeList = predictorTerm.getFieldRefs().stream()
                    .map(fieldRef -> new StringLiteralExpr(fieldRef.getField().getValue()))
                    .collect(Collectors.toList());
            NodeList<Expression> expressions = NodeList.nodeList(nodeList);
            MethodCallExpr methodCallExpr = new MethodCallExpr(new NameExpr("Arrays"), "asList", expressions);
            variableDeclarator.setInitializer(methodCallExpr);
            variableDeclarator = getVariableDeclarator(body, COEFFICIENT)
                    .orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_VARIABLE_IN_BODY,
                                                                                  COEFFICIENT, body)));
            variableDeclarator.setInitializer(String.valueOf(predictorTerm.getCoefficient().doubleValue()));
            return addMethod(methodTemplate, tableTemplate, "evaluatePredictorTerm" + predictorArity);
        } catch (Exception e) {
            throw new KiePMMLInternalException(String.format("Failed to add PredictorTerm %s", predictorTerm), e);
        }
    }

    private  KiePMMLRegressionTableRegressionFactory();

}