@Test public void filterResults() { List<Object> results = Arrays.asList(new Object[] {"alice,|bob,", 3L}, new Object[] {",carol", 2L}, new Object[] {"denis|carol|alice", 1L}, new Object[] {"Carol", 1L}); List<Object> filteredResults = this.filter.filterResults(results); assertEquals(2, filteredResults.size()); assertArrayEquals(new Object[] {"alice", 4L}, (Object[]) filteredResults.get(0)); assertArrayEquals(new Object[] {"carol", 3L}, (Object[]) filteredResults.get(1)); }
@Override public List<Object> filterResults(@SuppressWarnings("rawtypes") List results) { Map<String, Long> filteredResults = new HashMap<>(); for (Object result : results) { Object[] row = (Object[]) result; String value = (String) row[0]; Long count = (Long) row[1]; String[] values = StringUtils.split(value, this.separators); for (String actualValue : values) { if (actualValue.contains(this.filter)) { Long previousCount = filteredResults.getOrDefault(actualValue, 0L); filteredResults.put(actualValue, previousCount + count); } } } List<Entry<String, Long>> actualResults = new ArrayList<>(filteredResults.entrySet()); actualResults.sort(Collections.reverseOrder(Entry.comparingByValue())); if (actualResults.size() > this.limit) { actualResults = actualResults.subList(0, this.limit); } return actualResults.stream().map(entry -> new Object[] {entry.getKey(), entry.getValue()}) .collect(Collectors.toList()); }
SplitValueQueryFilter implements QueryFilter { @Override public List<Object> filterResults(@SuppressWarnings("rawtypes") List results) { Map<String, Long> filteredResults = new HashMap<>(); for (Object result : results) { Object[] row = (Object[]) result; String value = (String) row[0]; Long count = (Long) row[1]; String[] values = StringUtils.split(value, this.separators); for (String actualValue : values) { if (actualValue.contains(this.filter)) { Long previousCount = filteredResults.getOrDefault(actualValue, 0L); filteredResults.put(actualValue, previousCount + count); } } } List<Entry<String, Long>> actualResults = new ArrayList<>(filteredResults.entrySet()); actualResults.sort(Collections.reverseOrder(Entry.comparingByValue())); if (actualResults.size() > this.limit) { actualResults = actualResults.subList(0, this.limit); } return actualResults.stream().map(entry -> new Object[] {entry.getKey(), entry.getValue()}) .collect(Collectors.toList()); } }
SplitValueQueryFilter implements QueryFilter { @Override public List<Object> filterResults(@SuppressWarnings("rawtypes") List results) { Map<String, Long> filteredResults = new HashMap<>(); for (Object result : results) { Object[] row = (Object[]) result; String value = (String) row[0]; Long count = (Long) row[1]; String[] values = StringUtils.split(value, this.separators); for (String actualValue : values) { if (actualValue.contains(this.filter)) { Long previousCount = filteredResults.getOrDefault(actualValue, 0L); filteredResults.put(actualValue, previousCount + count); } } } List<Entry<String, Long>> actualResults = new ArrayList<>(filteredResults.entrySet()); actualResults.sort(Collections.reverseOrder(Entry.comparingByValue())); if (actualResults.size() > this.limit) { actualResults = actualResults.subList(0, this.limit); } return actualResults.stream().map(entry -> new Object[] {entry.getKey(), entry.getValue()}) .collect(Collectors.toList()); } SplitValueQueryFilter(String separators, int limit, String filter); }
SplitValueQueryFilter implements QueryFilter { @Override public List<Object> filterResults(@SuppressWarnings("rawtypes") List results) { Map<String, Long> filteredResults = new HashMap<>(); for (Object result : results) { Object[] row = (Object[]) result; String value = (String) row[0]; Long count = (Long) row[1]; String[] values = StringUtils.split(value, this.separators); for (String actualValue : values) { if (actualValue.contains(this.filter)) { Long previousCount = filteredResults.getOrDefault(actualValue, 0L); filteredResults.put(actualValue, previousCount + count); } } } List<Entry<String, Long>> actualResults = new ArrayList<>(filteredResults.entrySet()); actualResults.sort(Collections.reverseOrder(Entry.comparingByValue())); if (actualResults.size() > this.limit) { actualResults = actualResults.subList(0, this.limit); } return actualResults.stream().map(entry -> new Object[] {entry.getKey(), entry.getValue()}) .collect(Collectors.toList()); } SplitValueQueryFilter(String separators, int limit, String filter); @Override List<Object> filterResults(@SuppressWarnings("rawtypes") List results); @Override String filterStatement(String statement, String language); }
SplitValueQueryFilter implements QueryFilter { @Override public List<Object> filterResults(@SuppressWarnings("rawtypes") List results) { Map<String, Long> filteredResults = new HashMap<>(); for (Object result : results) { Object[] row = (Object[]) result; String value = (String) row[0]; Long count = (Long) row[1]; String[] values = StringUtils.split(value, this.separators); for (String actualValue : values) { if (actualValue.contains(this.filter)) { Long previousCount = filteredResults.getOrDefault(actualValue, 0L); filteredResults.put(actualValue, previousCount + count); } } } List<Entry<String, Long>> actualResults = new ArrayList<>(filteredResults.entrySet()); actualResults.sort(Collections.reverseOrder(Entry.comparingByValue())); if (actualResults.size() > this.limit) { actualResults = actualResults.subList(0, this.limit); } return actualResults.stream().map(entry -> new Object[] {entry.getKey(), entry.getValue()}) .collect(Collectors.toList()); } SplitValueQueryFilter(String separators, int limit, String filter); @Override List<Object> filterResults(@SuppressWarnings("rawtypes") List results); @Override String filterStatement(String statement, String language);  }