예제 #1
0
  public Set<String> clearPopularNames(TablePrettyPrinter printer, int maxSize) {
    Set<String> removed = Helper.newHashSet();
    Set<Counter<String>> sorted = Helper.newTreeSet(Counter.<String>getReverseComparator());
    Iterator<Map.Entry<String, Collection<T>>> iter = map.entrySet().iterator();
    for (Map.Entry<String, Collection<T>> entry = iter.next();
        iter.hasNext();
        entry = iter.next()) {
      if (entry.getValue().size() > maxSize) {
        removed.add(entry.getKey());
        sorted.add(new Counter<String>(entry.getKey(), entry.getValue().size()));
        iter.remove();
      }
    }

    printer.beginTable(2);
    printer.addDividerRow();
    printer.addRow("Name", "Count");
    printer.addDividerRow();
    for (Counter<String> counter : sorted) {
      printer.beginRow();
      printer.addCell(counter.getObject());
      printer.addCell(counter.getCount());
    }
    printer.addDividerRow();
    printer.endTable();

    return removed;
  }
예제 #2
0
 public Set<String> getTopResults(String heuristic, int top) {
   Collection<String> results = resultsByHeuristic.get(heuristic);
   Set<String> topResults = Helper.newHashSet();
   for (String result : results) {
     if (top-- <= 0) {
       break;
     }
     topResults.add(result);
   }
   return topResults;
 }
예제 #3
0
 public Query(String name) {
   this.name = name;
   resultsByHeuristic = Helper.newHashMap();
   results = Helper.newHashSet();
 }