use of org.kie.pmml.api.enums.CLOSURE in project drools by kiegroup.
the class KiePMMLIntervalFactory method getIntervalVariableDeclaration.
static BlockStmt getIntervalVariableDeclaration(final String variableName, final Interval interval) {
final MethodDeclaration methodDeclaration = INTERVAL_TEMPLATE.getMethodsByName(GETKIEPMMLINTERVAL).get(0).clone();
final BlockStmt toReturn = methodDeclaration.getBody().orElseThrow(() -> new KiePMMLException(String.format(MISSING_BODY_TEMPLATE, methodDeclaration)));
final VariableDeclarator variableDeclarator = getVariableDeclarator(toReturn, INTERVAL).orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_IN_BODY, INTERVAL, toReturn)));
variableDeclarator.setName(variableName);
final ObjectCreationExpr objectCreationExpr = variableDeclarator.getInitializer().orElseThrow(() -> new KiePMMLException(String.format(MISSING_VARIABLE_INITIALIZER_TEMPLATE, INTERVAL, toReturn))).asObjectCreationExpr();
final Expression leftMarginExpr = getExpressionForObject(interval.getLeftMargin());
final Expression rightMarginExpr = getExpressionForObject(interval.getRightMargin());
final CLOSURE closure = CLOSURE.byName(interval.getClosure().value());
final NameExpr closureExpr = new NameExpr(CLOSURE.class.getName() + "." + closure.name());
objectCreationExpr.getArguments().set(0, leftMarginExpr);
objectCreationExpr.getArguments().set(1, rightMarginExpr);
objectCreationExpr.getArguments().set(2, closureExpr);
return toReturn;
}
Aggregations