@Test void testCreateAlgorithmElseBlock() { String actual = "else{\n\tSUM_WEIGHT = new newValue(0);\n\tSUM_WEIGHT.plus($('MESHED_POTATO_1').map({\"1\":0.1,\"2\":0.5,\"3\":1,\"4\":3,\"5\":5.5,\"6\":7,\"7\":17.5,\"8\":31.5,\"9\":42}, null, null).value());\n\tSUM_WEIGHT.plus($('MESHED_POTATO').map({\"1\":0,\"2\":0.2,\"3\":0.6,\"4\":1,\"5\":2.5,\"6\":4.5,\"7\":6.5}, null, null).value());\n\tSUM_WEIGHT.group([0,1,3,6,7]).map({\"-0\":\"4\",\"0-1\":\"4\",\"1-3\":\"3\",\"3-6\":\"2\",\"6-7\":\"1\",\"7+\":\"1\"}, null, null).value();\n}"; String createAlgorithmElseBlock = categoryAlgorithmGenerator.createAlgorithmElseBlock( targetAttribute, Arrays.asList(sourceAttribute1, sourceAttribute, sourceAttribute2)); assertEquals(actual, createAlgorithmElseBlock); }
String createAlgorithmElseBlock(Attribute targetAttribute, List<Attribute> sourceAttributes) { StringBuilder stringBuilder = new StringBuilder(); if (!sourceAttributes.isEmpty()) { stringBuilder.append("else{\n").append("\tSUM_WEIGHT = new newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generateWeightedMap = generateWeightedMap(sourceAttribute); if (StringUtils.isNotEmpty(generateWeightedMap)) { stringBuilder.append("\tSUM_WEIGHT.plus(").append(generateWeightedMap).append(");\n"); } } stringBuilder .append("\tSUM_WEIGHT") .append(groupCategoryValues(targetAttribute)) .append("\n}"); } return stringBuilder.toString(); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { String createAlgorithmElseBlock(Attribute targetAttribute, List<Attribute> sourceAttributes) { StringBuilder stringBuilder = new StringBuilder(); if (!sourceAttributes.isEmpty()) { stringBuilder.append("else{\n").append("\tSUM_WEIGHT = new newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generateWeightedMap = generateWeightedMap(sourceAttribute); if (StringUtils.isNotEmpty(generateWeightedMap)) { stringBuilder.append("\tSUM_WEIGHT.plus(").append(generateWeightedMap).append(");\n"); } } stringBuilder .append("\tSUM_WEIGHT") .append(groupCategoryValues(targetAttribute)) .append("\n}"); } return stringBuilder.toString(); } }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { String createAlgorithmElseBlock(Attribute targetAttribute, List<Attribute> sourceAttributes) { StringBuilder stringBuilder = new StringBuilder(); if (!sourceAttributes.isEmpty()) { stringBuilder.append("else{\n").append("\tSUM_WEIGHT = new newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generateWeightedMap = generateWeightedMap(sourceAttribute); if (StringUtils.isNotEmpty(generateWeightedMap)) { stringBuilder.append("\tSUM_WEIGHT.plus(").append(generateWeightedMap).append(");\n"); } } stringBuilder .append("\tSUM_WEIGHT") .append(groupCategoryValues(targetAttribute)) .append("\n}"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { String createAlgorithmElseBlock(Attribute targetAttribute, List<Attribute> sourceAttributes) { StringBuilder stringBuilder = new StringBuilder(); if (!sourceAttributes.isEmpty()) { stringBuilder.append("else{\n").append("\tSUM_WEIGHT = new newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generateWeightedMap = generateWeightedMap(sourceAttribute); if (StringUtils.isNotEmpty(generateWeightedMap)) { stringBuilder.append("\tSUM_WEIGHT.plus(").append(generateWeightedMap).append(");\n"); } } stringBuilder .append("\tSUM_WEIGHT") .append(groupCategoryValues(targetAttribute)) .append("\n}"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); String generateWeightedMap(Attribute attribute); String groupCategoryValues(Attribute attribute); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { String createAlgorithmElseBlock(Attribute targetAttribute, List<Attribute> sourceAttributes) { StringBuilder stringBuilder = new StringBuilder(); if (!sourceAttributes.isEmpty()) { stringBuilder.append("else{\n").append("\tSUM_WEIGHT = new newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generateWeightedMap = generateWeightedMap(sourceAttribute); if (StringUtils.isNotEmpty(generateWeightedMap)) { stringBuilder.append("\tSUM_WEIGHT.plus(").append(generateWeightedMap).append(");\n"); } } stringBuilder .append("\tSUM_WEIGHT") .append(groupCategoryValues(targetAttribute)) .append("\n}"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); @Override boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); @Override String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); String generateWeightedMap(Attribute attribute); String groupCategoryValues(Attribute attribute);  }