DimensionalTable { public List<DATA> getDataPoints(Map<String, ?> keys) { Preconditions.checkNotNull(keys); Preconditions.checkArgument(dimensionNameToIndex.keySet().containsAll(keys.keySet()), "The given keys contain names which are not valid keys."); List<Integer> indices = Lists.newArrayList(); List<List<Object>> keyColumns = Lists.newArrayList(); Map<Integer, Object> indexToKey = Maps.newHashMap(); for (Map.Entry<String, ?> entry : keys.entrySet()) { String dimensionName = entry.getKey(); Object value = entry.getValue(); Integer index = dimensionNameToIndex.get(dimensionName); indices.add(index); indexToKey.put(index, value); } Collections.sort(indices); List<Object> tempKeys = Lists.newArrayList(); for (Integer index : indices) { tempKeys.add(indexToKey.get(index)); keyColumns.add(dimensionColumns.get(index)); } int numRows = keyColumns.get(0).size(); List<DATA> results = Lists.newArrayList(); for (int rowIndex = 0; rowIndex < numRows; rowIndex++) { boolean allEqual = true; for (int columnIndex = 0; columnIndex < tempKeys.size(); columnIndex++) { Object key = tempKeys.get(columnIndex); Object keyColumn = keyColumns.get(columnIndex).get(rowIndex); if ((key == null && keyColumn != null) || (key != null && keyColumn == null) || (key != null && !keyColumn.equals(key))) { allEqual = false; break; } } if (allEqual) { results.add(dataColumn.get(rowIndex)); } } return results; } private  DimensionalTable();  DimensionalTable(List<String> headerNames); void appendRow(DATA data, Object... keys); void appendRow(DATA data, Map<String, ?> keys); @SuppressWarnings("element-type-mismatch") DATA getDataPoint(List<?> keys); DATA getDataPoint(Map<String, ?> keys); List<DATA> getDataPoints(Map<String, ?> keys); List<DATA> getAllDataPoints(); int size();  }
@Test public void getDataPointsTest() { DimensionalTable<Integer> table = createTestTable(); Set<Integer> expectedDataPoints = Sets.newHashSet(3, 4, 5); Map<String, String> selectionKeys = Maps.newHashMap(); selectionKeys.put("publisher", "twitter"); Set<Integer> dataPoints = Sets.newHashSet(table.getDataPoints(selectionKeys)); Assert.assertEquals(expectedDataPoints, dataPoints); expectedDataPoints = Sets.newHashSet(8, 9); selectionKeys.clear(); selectionKeys.put("advertiser", "microsoft"); dataPoints = Sets.newHashSet(table.getDataPoints(selectionKeys)); Assert.assertEquals(expectedDataPoints, dataPoints); expectedDataPoints = Sets.newHashSet(2, 10); selectionKeys.clear(); selectionKeys.put("location", "NY"); dataPoints = Sets.newHashSet(table.getDataPoints(selectionKeys)); Assert.assertEquals(expectedDataPoints, dataPoints); }