@Test public void testAggregateOneColumn() { List<QueryResultRow> rows; Collection<QueryResultRow> aggregatedRows; List<List<String>> paths = new ArrayList<List<String>>(); paths.add(Arrays.asList("a", "stringValue")); rows = new ArrayList<QueryResultRow>(); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a1"))); aggregatedRows = new PoolerRows().group(rows, paths); assertEquals(1, aggregatedRows.size()); assertEquals(2, aggregatedRows.iterator().next().getGroupedRows().size()); rows = new ArrayList<QueryResultRow>(); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a1"))); rows.add(new QueryResultRow("a", new A("a2"))); aggregatedRows = new PoolerRows().group(rows, paths); assertEquals(2, aggregatedRows.size()); }
@BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); }
PoolerRows { @BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); } }
PoolerRows { @BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); }  }
PoolerRows { @BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); }  @BadSmell("This first if is really weird") Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths); }
PoolerRows { @BadSmell("This first if is really weird") public Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths) { if (rows.isEmpty() && paths.size() > 0 && paths.get(0).get(0).equals("fake_aggregation_for_group_all_rows")) { return Arrays.asList(new QueryResultRow("", null)); } Map<String, QueryResultRow> map = new HashMap<String, QueryResultRow>(); for (QueryResultRow row : rows) { String key = toKey(row, paths); QueryResultRow groupedRow = map.get(key); if (groupedRow == null) { groupedRow = row; map.put(key, groupedRow); } groupedRow.addGroupedRow(row); } return map.values(); }  @BadSmell("This first if is really weird") Collection<QueryResultRow> group(List<QueryResultRow> rows, List<List<String>> paths);  }