use of com.github.javaparser.ast.expr.CastExpr in project drools by kiegroup.
the class FEELPropertyAccessibleImplementation method toSetPropertySwitchEntry.
private SwitchEntry toSetPropertySwitchEntry(DMNDeclaredField fieldDefinition) {
String accessorName = fieldDefinition.overriddenSetterName().orElse(getAccessorName(fieldDefinition, "set"));
MethodCallExpr setMethod = new MethodCallExpr(new ThisExpr(), accessorName);
setMethod.addArgument(new CastExpr(StaticJavaParser.parseType(fieldDefinition.getObjectType()), new NameExpr("value")));
ExpressionStmt setStatement = new ExpressionStmt();
setStatement.setExpression(setMethod);
NodeList<Expression> labels = nodeList(new StringLiteralExpr(fieldDefinition.getOriginalMapKey()));
NodeList<Statement> statements = nodeList(setStatement, new ReturnStmt());
return new SwitchEntry(labels, SwitchEntry.Type.STATEMENT_GROUP, statements);
}
use of com.github.javaparser.ast.expr.CastExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getNumericPredictorExpression.
/**
* Create a <b>NumericPredictor</b> <code>CastExpr</code>
* @param numericPredictor
* @return
*/
static CastExpr getNumericPredictorExpression(final NumericPredictor numericPredictor) {
boolean withExponent = !Objects.equals(1, numericPredictor.getExponent());
final String lambdaExpressionMethodName = withExponent ? "evaluateNumericWithExponent" : "evaluateNumericWithoutExponent";
final String parameterName = "input";
final MethodCallExpr lambdaMethodCallExpr = new MethodCallExpr();
lambdaMethodCallExpr.setName(lambdaExpressionMethodName);
lambdaMethodCallExpr.setScope(new NameExpr(KiePMMLRegressionTable.class.getSimpleName()));
final NodeList<Expression> arguments = new NodeList<>();
arguments.add(0, new NameExpr(parameterName));
arguments.add(1, getExpressionForObject(numericPredictor.getCoefficient().doubleValue()));
if (withExponent) {
arguments.add(2, getExpressionForObject(numericPredictor.getExponent().doubleValue()));
}
lambdaMethodCallExpr.setArguments(arguments);
final ExpressionStmt lambdaExpressionStmt = new ExpressionStmt(lambdaMethodCallExpr);
final LambdaExpr lambdaExpr = new LambdaExpr();
final Parameter lambdaParameter = new Parameter(new UnknownType(), parameterName);
lambdaExpr.setParameters(NodeList.nodeList(lambdaParameter));
lambdaExpr.setBody(lambdaExpressionStmt);
final String doubleClassName = Double.class.getSimpleName();
final ClassOrInterfaceType serializableFunctionType = getTypedClassOrInterfaceTypeByTypeNames(SerializableFunction.class.getCanonicalName(), Arrays.asList(doubleClassName, doubleClassName));
final CastExpr toReturn = new CastExpr();
toReturn.setType(serializableFunctionType);
toReturn.setExpression(lambdaExpr);
return toReturn;
}
use of com.github.javaparser.ast.expr.CastExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactory method getResultUpdaterSupportedExpression.
/**
* Create a <b>resultUpdater</b> <code>CastExpr</code>
* @param normalizationMethod
* @return
*/
static MethodReferenceExpr getResultUpdaterSupportedExpression(final RegressionModel.NormalizationMethod normalizationMethod) {
final String thisExpressionMethodName = String.format("update%sResult", normalizationMethod.name());
final CastExpr castExpr = new CastExpr();
final String doubleClassName = Double.class.getSimpleName();
final ClassOrInterfaceType consumerType = getTypedClassOrInterfaceTypeByTypeNames(SerializableFunction.class.getCanonicalName(), Arrays.asList(doubleClassName, doubleClassName));
castExpr.setType(consumerType);
castExpr.setExpression(KiePMMLRegressionTable.class.getSimpleName());
final MethodReferenceExpr toReturn = new MethodReferenceExpr();
toReturn.setScope(castExpr);
toReturn.setIdentifier(thisExpressionMethodName);
return toReturn;
}
use of com.github.javaparser.ast.expr.CastExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactoryTest method getNumericPredictorExpressionWithExponent.
@Test
public void getNumericPredictorExpressionWithExponent() throws IOException {
String predictorName = "predictorName";
int exponent = 2;
double coefficient = 1.23;
NumericPredictor numericPredictor = PMMLModelTestUtils.getNumericPredictor(predictorName, exponent, coefficient);
CastExpr retrieved = KiePMMLRegressionTableFactory.getNumericPredictorExpression(numericPredictor);
String text = getFileContent(TEST_01_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, coefficient, exponent));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
use of com.github.javaparser.ast.expr.CastExpr in project drools by kiegroup.
the class KiePMMLRegressionTableFactoryTest method getCategoricalPredictorExpression.
@Test
public void getCategoricalPredictorExpression() throws IOException {
final String categoricalPredictorMapName = "categoricalPredictorMapName";
CastExpr retrieved = KiePMMLRegressionTableFactory.getCategoricalPredictorExpression(categoricalPredictorMapName);
String text = getFileContent(TEST_05_SOURCE);
Expression expected = JavaParserUtils.parseExpression(String.format(text, categoricalPredictorMapName));
assertTrue(JavaParserUtils.equalsNode(expected, retrieved));
}
Aggregations