@Test void generate() { String generate = numericAlgorithmGenerator.generate( targetAttribute, asList(sourceAttribute), targetEntityType, sourceEntityType); assertEquals("$('sourceHeight').unit('cm').toUnit('m').value();", generate); String generateAverageValue = numericAlgorithmGenerator.generate( targetAttribute, asList(sourceAttribute, sourceAttribute1), targetEntityType, sourceEntityType); String expected = "var counter = 0;\nvar SUM=newValue(0);\nif(!$('sourceHeight').isNull().value()){\n\tSUM.plus($('sourceHeight').unit('cm').toUnit('m').value());\n\tcounter++;\n}\nif(!$('sourceHeight1').isNull().value()){\n\tSUM.plus($('sourceHeight1').unit('cm').toUnit('m').value());\n\tcounter++;\n}\nif(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"; assertEquals(expected, generateAverageValue); }
public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { StringBuilder algorithm = new StringBuilder(); if (sourceAttributes.size() == 1) { algorithm.append(generateUnitConversionAlgorithm(targetAttribute, sourceAttributes.get(0))); } else if (sourceAttributes.size() > 1) { algorithm.append("var counter = 0;\nvar SUM=newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generate = generate( targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType); algorithm .append("if(!$('") .append(sourceAttribute.getName()) .append("').isNull().value()){\n\t") .append("SUM.plus(") .append( generate.endsWith(";") ? generate.substring(0, generate.length() - 1) : generate) .append(");\n\tcounter++;\n}\n"); } algorithm.append( "if(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"); } return algorithm.toString(); }
NumericAlgorithmGenerator implements AlgorithmGenerator { public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { StringBuilder algorithm = new StringBuilder(); if (sourceAttributes.size() == 1) { algorithm.append(generateUnitConversionAlgorithm(targetAttribute, sourceAttributes.get(0))); } else if (sourceAttributes.size() > 1) { algorithm.append("var counter = 0;\nvar SUM=newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generate = generate( targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType); algorithm .append("if(!$('") .append(sourceAttribute.getName()) .append("').isNull().value()){\n\t") .append("SUM.plus(") .append( generate.endsWith(";") ? generate.substring(0, generate.length() - 1) : generate) .append(");\n\tcounter++;\n}\n"); } algorithm.append( "if(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"); } return algorithm.toString(); } }
NumericAlgorithmGenerator implements AlgorithmGenerator { public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { StringBuilder algorithm = new StringBuilder(); if (sourceAttributes.size() == 1) { algorithm.append(generateUnitConversionAlgorithm(targetAttribute, sourceAttributes.get(0))); } else if (sourceAttributes.size() > 1) { algorithm.append("var counter = 0;\nvar SUM=newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generate = generate( targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType); algorithm .append("if(!$('") .append(sourceAttribute.getName()) .append("').isNull().value()){\n\t") .append("SUM.plus(") .append( generate.endsWith(";") ? generate.substring(0, generate.length() - 1) : generate) .append(");\n\tcounter++;\n}\n"); } algorithm.append( "if(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"); } return algorithm.toString(); } NumericAlgorithmGenerator(UnitResolver unitResolver); }
NumericAlgorithmGenerator implements AlgorithmGenerator { public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { StringBuilder algorithm = new StringBuilder(); if (sourceAttributes.size() == 1) { algorithm.append(generateUnitConversionAlgorithm(targetAttribute, sourceAttributes.get(0))); } else if (sourceAttributes.size() > 1) { algorithm.append("var counter = 0;\nvar SUM=newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generate = generate( targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType); algorithm .append("if(!$('") .append(sourceAttribute.getName()) .append("').isNull().value()){\n\t") .append("SUM.plus(") .append( generate.endsWith(";") ? generate.substring(0, generate.length() - 1) : generate) .append(");\n\tcounter++;\n}\n"); } algorithm.append( "if(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"); } return algorithm.toString(); } NumericAlgorithmGenerator(UnitResolver unitResolver); String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes); }
NumericAlgorithmGenerator implements AlgorithmGenerator { public String generate( Attribute targetAttribute, List<Attribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) { StringBuilder algorithm = new StringBuilder(); if (sourceAttributes.size() == 1) { algorithm.append(generateUnitConversionAlgorithm(targetAttribute, sourceAttributes.get(0))); } else if (sourceAttributes.size() > 1) { algorithm.append("var counter = 0;\nvar SUM=newValue(0);\n"); for (Attribute sourceAttribute : sourceAttributes) { String generate = generate( targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType); algorithm .append("if(!$('") .append(sourceAttribute.getName()) .append("').isNull().value()){\n\t") .append("SUM.plus(") .append( generate.endsWith(";") ? generate.substring(0, generate.length() - 1) : generate) .append(");\n\tcounter++;\n}\n"); } algorithm.append( "if(counter !== 0){\n\tSUM.div(counter);\n\tSUM.value();\n}else{\n\tnull;\n}"); } return algorithm.toString(); } NumericAlgorithmGenerator(UnitResolver unitResolver); String generate(
      Attribute targetAttribute,
      List<Attribute> sourceAttributes,
      EntityType targetEntityType,
      EntityType sourceEntityType); boolean isSuitable(Attribute targetAttribute, List<Attribute> sourceAttributes);  }