NumberService extends AbstractService { public void putAttributeValues(String column) { Number max = null; Number min = null; Number secondMax = null; Number secondMin = null; for (Attribute attr : dataset.getAttributesByColumn(column)) { if (attr.isAlive()) { Number value = (Number) attr.getValue(); if (value == null) { continue; } if (max == null || min == null || secondMin == null || secondMax == null) { max = value; min = value; secondMax = value; secondMin = value; } else { if (value.doubleValue() > max.doubleValue()) { secondMax = max; max = value; if (secondMax.equals(min)) { secondMin = max; } } else if (value.doubleValue() < min.doubleValue()) { secondMin = min; min = value; if (secondMin.equals(max)) { secondMax = min; } } if (value.doubleValue() < max.doubleValue() && secondMax.doubleValue() < value.doubleValue()) { secondMax = value; } if (value.doubleValue() > min.doubleValue() && secondMin.doubleValue() > value.doubleValue()) { secondMin = value; } } } } largestValueMap.put(column, max); smallestValueMap.put(column, min); secondLargestValueMap.put(column, secondMax); secondSmallestValueMap.put(column, secondMin); } NumberService(DataSet dataset); void putAttributeValues(String column); boolean isLargestValue(Object var, String column); boolean isSmallestValue(Object var, String column); boolean isSecondLargestValue(Object var, String column); boolean isSecondSmallestValue(Object var, String column); @Override void init();  }
@Test public void testPutAttributeValues() { List<Column> columnList = generateColumnList(); DataSet dataSet = new DataSet(columnList); dataSet.initData(generateInputData()); NumberService ns = new NumberService(dataSet); ns.putAttributeValues("id1"); ns.putAttributeValues("id2"); ns.putAttributeValues("id3"); ns.putAttributeValues("id4"); Assert.assertEquals("longestValueMap size should be 4", 4, ns.largestValueMap.size()); Assert.assertEquals("secondLongestValueMap size should be 4", 4, ns.smallestValueMap.size()); Assert.assertEquals("secondShortestValueMap size should be 4", 4, ns.secondLargestValueMap.size()); Assert.assertEquals("shortestValueMap size should be 4", 4, ns.secondSmallestValueMap.size()); Assert.assertEquals("The result of firstName column should be 6", 6, ns.largestValueMap.get("id1")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.largestValueMap.get("id2")); Assert.assertEquals("The result of firstName column should be 6", 6, ns.largestValueMap.get("id3")); Assert.assertEquals("The result of firstName column should be 4", 4, ns.largestValueMap.get("id4")); Assert.assertEquals("The result of firstName column should be 5", 5, ns.secondLargestValueMap.get("id1")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.secondLargestValueMap.get("id2")); Assert.assertEquals("The result of firstName column should be 5", 5, ns.secondLargestValueMap.get("id3")); Assert.assertEquals("The result of firstName column should be 3", 3, ns.secondLargestValueMap.get("id4")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.smallestValueMap.get("id1")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.smallestValueMap.get("id2")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.smallestValueMap.get("id3")); Assert.assertEquals("The result of firstName column should be 3", 3, ns.smallestValueMap.get("id4")); Assert.assertEquals("The result of firstName column should be 2", 2, ns.secondSmallestValueMap.get("id1")); Assert.assertEquals("The result of firstName column should be 1", 1, ns.secondSmallestValueMap.get("id2")); Assert.assertEquals("The result of firstName column should be 2", 2, ns.secondSmallestValueMap.get("id3")); Assert.assertEquals("The result of firstName column should be 4", 4, ns.secondSmallestValueMap.get("id4")); ns.init(); }