FrequencyService extends AbstractService { public HashMap<Object, Integer> putAttributeValues(String column, boolean ignoreBlanks) { HashMap<Object, Integer> valueToFreq = new HashMap<>(); frequencyMaps.put(column, valueToFreq); for (Attribute attr : dataset.getAttributesByColumn(column)) { if (attr.isAlive()) { Object value = attr.getValue(); if (value == null || (ignoreBlanks == true && "".equals(value.toString().trim()))) { continue; } if (valueToFreq.get(value) == null) { valueToFreq.put(value, 1); } else { valueToFreq.put(value, valueToFreq.get(value) + 1); } } } int max = 0; int second = 0; for (Entry<Object, Integer> entry : valueToFreq.entrySet()) { int freq = entry.getValue(); if (freq > max) { second = max; max = freq; } else if (freq < max && freq > second) { second = freq; } } maxOccurence.put(column, max); secondMaxOccurence.put(column, second); return valueToFreq; } FrequencyService(DataSet dataset); HashMap<Object, Integer> putAttributeValues(String column, boolean ignoreBlanks); HashSet<Object> getMostCommonValue(String column, boolean ignoreBlanks); HashSet<Object> getSecondMostCommonValue(String column, boolean ignoreBlanks); @Override void init();  }
@Test public void testPutAttributeValues() { List<Column> columnList = generateColumnList(); DataSet dataSet = new DataSet(columnList); dataSet.initData(generateInputData()); FrequencyService fs = new FrequencyService(dataSet); fs.putAttributeValues("firstName", false); fs.putAttributeValues("lastName", false); Assert.assertEquals("frequencyMaps size should be 2", 2, fs.frequencyMaps.size()); Assert.assertEquals("maxOccurence size should be 2", 2, fs.maxOccurence.size()); Assert.assertEquals("secondMaxOccurence size should be 2", 2, fs.secondMaxOccurence.size()); Assert.assertEquals("The result of firstName column should be 6", 6, fs.frequencyMaps.get("firstName").size()); Assert.assertEquals("The result of lastName column should be 3", 3, fs.frequencyMaps.get("lastName").size()); Assert.assertEquals("The maxOccurence of firstName column should be 1", 1, fs.maxOccurence.get("firstName").intValue()); Assert.assertEquals("The maxOccurence of lastName column should be 3", 3, fs.maxOccurence.get("lastName").intValue()); Assert.assertEquals("The secondMaxOccurence of firstName column should be 0", 0, fs.secondMaxOccurence .get("firstName") .intValue()); Assert.assertEquals("The secondMaxOccurence of lastName column should be 2", 2, fs.secondMaxOccurence .get("lastName") .intValue()); fs.init(); }