class PredictionRuleMappersGenerator {

    public static String getPredictionRuleMappersSource(final String packageName, final List<String> generatedRuleMappers) {
        CompilationUnit clazz =
                StaticJavaParser.parse(PredictionRuleMappersGenerator.class.getResourceAsStream(TEMPLATE_JAVA)).clone();
        if (!packageName.isEmpty()) {
            clazz.setPackageDeclaration(packageName);
        }
        ClassOrInterfaceDeclaration typeDeclaration = (ClassOrInterfaceDeclaration) clazz.getTypes().get(0);
        FieldDeclaration ruleNameField =
                typeDeclaration.getFieldByName("predictionRuleMappers").orElseThrow(() -> new RuntimeException("The template " + TEMPLATE_JAVA + " has been modified."));
        final List<Expression> nodeList = generatedRuleMappers.stream()
                .map(generatedRuleMapper -> {
                    ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr();
                    objectCreationExpr.setType(generatedRuleMapper);
                    return objectCreationExpr;
                })
                .collect(Collectors.toList());
        NodeList<Expression> expressions = NodeList.nodeList(nodeList);
        MethodCallExpr methodCallExpr = new MethodCallExpr(new NameExpr("Arrays"), "asList", expressions);
        ruleNameField.getVariables().get(0).setInitializer(methodCallExpr);
        return clazz.toString();
    }

    private  PredictionRuleMappersGenerator();

}