Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
 public void collectFingerprints(Map<T, Counter<T>> result, String[] strings) {
   for (String string : strings) {
     for (T fingerprint : get(string)) {
       Counter<T> counter = result.get(fingerprint);
       if (counter == null) {
         counter = new Counter<T>(fingerprint);
         result.put(fingerprint, counter);
       }
       counter.increment();
     }
   }
 }