FrequencyService extends AbstractService { public HashSet<Object> getMostCommonValue(String column, boolean ignoreBlanks) { HashMap<Object, Integer> valueToFreq = frequencyMaps.get(column); if (valueToFreq == null) { valueToFreq = putAttributeValues(column, ignoreBlanks); } int max = maxOccurence.get(column); HashSet<Object> mostFrequentValues = new HashSet<Object>(); for (Entry<Object, Integer> entry : valueToFreq.entrySet()) { Object obj = entry.getKey(); int count = entry.getValue(); if (count == max) { mostFrequentValues.add(obj); } } return mostFrequentValues; } 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 testGetMostCommonValue() { 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("the size of most common value on firstName column should be 6", 6, fs.getMostCommonValue("firstName", false).size()); Assert.assertEquals("the size of most common value on lastName column should be 1", 1, fs.getMostCommonValue("lastName", false).size()); Assert.assertEquals("most common value on lastName column should be cook", "cook", fs.getMostCommonValue("lastName", false).toArray()[0].toString()); }