@Test void testGenerateWeightedMap() { String expected = "$('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()"; String actual = categoryAlgorithmGenerator.generateWeightedMap(sourceAttribute); assertEquals(expected, actual); }
public String generateWeightedMap(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); for (Category sourceCategory : convertToCategory(attribute)) { AmountWrapper amountWrapper = sourceCategory.getAmountWrapper(); if (amountWrapper != null) { if (stringBuilder.length() == 0) { stringBuilder.append("$('").append(attribute.getName()).append("').map({"); } Amount<?> amount = amountWrapper.getAmount(); if (amount == null) { throw new IllegalArgumentException("Amount wrapper amount can't be null"); } double estimatedValue = amount.getEstimatedValue(); stringBuilder .append("\"") .append(sourceCategory.getCode()) .append("\":") .append(DECIMAL_FORMAT.format(estimatedValue)) .append(","); } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value()"); } return stringBuilder.toString(); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String generateWeightedMap(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); for (Category sourceCategory : convertToCategory(attribute)) { AmountWrapper amountWrapper = sourceCategory.getAmountWrapper(); if (amountWrapper != null) { if (stringBuilder.length() == 0) { stringBuilder.append("$('").append(attribute.getName()).append("').map({"); } Amount<?> amount = amountWrapper.getAmount(); if (amount == null) { throw new IllegalArgumentException("Amount wrapper amount can't be null"); } double estimatedValue = amount.getEstimatedValue(); stringBuilder .append("\"") .append(sourceCategory.getCode()) .append("\":") .append(DECIMAL_FORMAT.format(estimatedValue)) .append(","); } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value()"); } return stringBuilder.toString(); } }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String generateWeightedMap(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); for (Category sourceCategory : convertToCategory(attribute)) { AmountWrapper amountWrapper = sourceCategory.getAmountWrapper(); if (amountWrapper != null) { if (stringBuilder.length() == 0) { stringBuilder.append("$('").append(attribute.getName()).append("').map({"); } Amount<?> amount = amountWrapper.getAmount(); if (amount == null) { throw new IllegalArgumentException("Amount wrapper amount can't be null"); } double estimatedValue = amount.getEstimatedValue(); stringBuilder .append("\"") .append(sourceCategory.getCode()) .append("\":") .append(DECIMAL_FORMAT.format(estimatedValue)) .append(","); } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value()"); } return stringBuilder.toString(); } OneToManyCategoryAlgorithmGenerator(DataService dataService); }
OneToManyCategoryAlgorithmGenerator extends AbstractCategoryAlgorithmGenerator { public String generateWeightedMap(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); for (Category sourceCategory : convertToCategory(attribute)) { AmountWrapper amountWrapper = sourceCategory.getAmountWrapper(); if (amountWrapper != null) { if (stringBuilder.length() == 0) { stringBuilder.append("$('").append(attribute.getName()).append("').map({"); } Amount<?> amount = amountWrapper.getAmount(); if (amount == null) { throw new IllegalArgumentException("Amount wrapper amount can't be null"); } double estimatedValue = amount.getEstimatedValue(); stringBuilder .append("\"") .append(sourceCategory.getCode()) .append("\":") .append(DECIMAL_FORMAT.format(estimatedValue)) .append(","); } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value()"); } 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 { public String generateWeightedMap(Attribute attribute) { StringBuilder stringBuilder = new StringBuilder(); for (Category sourceCategory : convertToCategory(attribute)) { AmountWrapper amountWrapper = sourceCategory.getAmountWrapper(); if (amountWrapper != null) { if (stringBuilder.length() == 0) { stringBuilder.append("$('").append(attribute.getName()).append("').map({"); } Amount<?> amount = amountWrapper.getAmount(); if (amount == null) { throw new IllegalArgumentException("Amount wrapper amount can't be null"); } double estimatedValue = amount.getEstimatedValue(); stringBuilder .append("\"") .append(sourceCategory.getCode()) .append("\":") .append(DECIMAL_FORMAT.format(estimatedValue)) .append(","); } } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); stringBuilder.append("}, null, null).value()"); } 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);  }