@Test public void addMapPopulation() { final BlockStmt body = new BlockStmt(); final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap = new LinkedHashMap<>(); IntStream.range(0, 3).forEach(index -> regressionTablesMap.put("KEY" + index, new KiePMMLTableSourceCategory("SOURCE-" + index, "CATEGORY-" + index))); KiePMMLRegressionTableClassificationFactory.addMapPopulation(body, regressionTablesMap); NodeList<Statement> retrieved = body.getStatements(); assertEquals(regressionTablesMap.size(), retrieved.size()); retrieved.forEach(statement -> { assertTrue(statement instanceof ExpressionStmt); assertTrue(((ExpressionStmt) statement).getExpression() instanceof MethodCallExpr); MethodCallExpr methodCallExpr = (MethodCallExpr) ((ExpressionStmt) statement).getExpression(); assertEquals("categoryTableMap", methodCallExpr.getScope().get().asNameExpr().toString()); assertEquals("put", methodCallExpr.getName().asString()); }); final List<MethodCallExpr> methodCallExprs = retrieved.stream() .map(statement -> (MethodCallExpr) ((ExpressionStmt) statement).getExpression()) .collect(Collectors.toList()); IntStream.range(0, 3).forEach(index -> { String key = "KEY" + index; KiePMMLTableSourceCategory kiePMMLTableSourceCategory = regressionTablesMap.get(key); MethodCallExpr methodCallExpr = methodCallExprs.get(index); StringLiteralExpr stringLiteralExpr = (StringLiteralExpr) methodCallExpr.getArguments().get(0); assertEquals(kiePMMLTableSourceCategory.getCategory(), stringLiteralExpr.getValue()); ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) methodCallExpr.getArguments().get(1); assertEquals(key, objectCreationExpr.getTypeAsString()); }); }
static void addMapPopulation(final BlockStmt body, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap) { regressionTablesMap.forEach((className, tableSourceCategory) -> { ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(className); NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(tableSourceCategory.getCategory()), objectCreationExpr); body.addStatement(new MethodCallExpr(new NameExpr("categoryTableMap"), "put", expressions)); }); }
KiePMMLRegressionTableClassificationFactory { static void addMapPopulation(final BlockStmt body, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap) { regressionTablesMap.forEach((className, tableSourceCategory) -> { ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(className); NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(tableSourceCategory.getCategory()), objectCreationExpr); body.addStatement(new MethodCallExpr(new NameExpr("categoryTableMap"), "put", expressions)); }); } }
KiePMMLRegressionTableClassificationFactory { static void addMapPopulation(final BlockStmt body, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap) { regressionTablesMap.forEach((className, tableSourceCategory) -> { ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(className); NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(tableSourceCategory.getCategory()), objectCreationExpr); body.addStatement(new MethodCallExpr(new NameExpr("categoryTableMap"), "put", expressions)); }); } private  KiePMMLRegressionTableClassificationFactory(); }
KiePMMLRegressionTableClassificationFactory { static void addMapPopulation(final BlockStmt body, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap) { regressionTablesMap.forEach((className, tableSourceCategory) -> { ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(className); NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(tableSourceCategory.getCategory()), objectCreationExpr); body.addStatement(new MethodCallExpr(new NameExpr("categoryTableMap"), "put", expressions)); }); } private  KiePMMLRegressionTableClassificationFactory(); static Map<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); static Map.Entry<String, String> getRegressionTable(final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); }
KiePMMLRegressionTableClassificationFactory { static void addMapPopulation(final BlockStmt body, final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap) { regressionTablesMap.forEach((className, tableSourceCategory) -> { ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr(); objectCreationExpr.setType(className); NodeList<Expression> expressions = NodeList.nodeList(new StringLiteralExpr(tableSourceCategory.getCategory()), objectCreationExpr); body.addStatement(new MethodCallExpr(new NameExpr("categoryTableMap"), "put", expressions)); }); } private  KiePMMLRegressionTableClassificationFactory(); static Map<String, KiePMMLTableSourceCategory> getRegressionTables(final List<RegressionTable> regressionTables, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); static Map.Entry<String, String> getRegressionTable(final LinkedHashMap<String, KiePMMLTableSourceCategory> regressionTablesMap, final RegressionModel.NormalizationMethod normalizationMethod, final OpType opType, final List<KiePMMLOutputField> outputFields, final String targetField, final String packageName); static final String KIE_PMML_REGRESSION_TABLE_CLASSIFICATION_TEMPLATE_JAVA; static final String KIE_PMML_REGRESSION_TABLE_CLASSIFICATION_TEMPLATE; }