### Question:
EvaluatorUtil { static public <K> List<Map<K, Object>> groupRows(K groupKey, List<Map<K, Object>> table){ Map<Object, ListMultimap<K, Object>> groupedRows = Maps.newLinkedHashMap(); for(int i = 0; i < table.size(); i++){ Map<K, ?> row = table.get(i); Object groupValue = row.get(groupKey); ListMultimap<K, Object> groupedRow = groupedRows.get(groupValue); if(groupedRow == null){ groupedRow = ArrayListMultimap.create(); groupedRows.put(groupValue, groupedRow); } Collection<? extends Map.Entry<K, ?>> entries = row.entrySet(); for(Map.Entry<K, ?> entry : entries){ K key = entry.getKey(); Object value = entry.getValue(); groupedRow.put(key, value); } } List<Map<K, Object>> resultTable = Lists.newArrayList(); Collection<Map.Entry<Object, ListMultimap<K, Object>>> entries = groupedRows.entrySet(); for(Map.Entry<Object, ListMultimap<K, Object>> entry : entries){ Map<K, Object> resultRow = Maps.newLinkedHashMap(); resultRow.putAll((entry.getValue()).asMap()); resultRow.put(groupKey, entry.getKey()); resultTable.add(resultRow); } return resultTable; } private  EvaluatorUtil(); static Object decode(Object object); static Map<String, ?> decode(Map<FieldName, ?> map); static FieldValue prepare(Evaluator evaluator, FieldName name, Object value); static List<Map<K, Object>> groupRows(K groupKey, List<Map<K, Object>> table);  }### Answer:
@Test public void groupRows(){ List<Map<FieldName, Object>> table = Lists.newArrayList(); table.add(createRow("1", "Cracker")); table.add(createRow("2", "Cracker")); table.add(createRow("1", "Coke")); table.add(createRow("3", "Cracker")); table.add(createRow("3", "Water")); table.add(createRow("3", "Coke")); table.add(createRow("2", "Water")); table = EvaluatorUtil.groupRows(new FieldName("transaction"), table); checkGroupedRow(table.get(0), "1", Arrays.asList("Cracker", "Coke")); checkGroupedRow(table.get(1), "2", Arrays.asList("Cracker", "Water")); checkGroupedRow(table.get(2), "3", Arrays.asList("Cracker", "Water", "Coke")); }