code: public static<E> Set<E> retainKeys(Counter<E> counter, Collection<E> matchKeys) {
      Set<E> removed = new HashSet<E>();
      for (E key : counter.keySet()) {
        boolean matched = matchKeys.contains(key);
        if (!matched) {
          removed.add(key);
        }
      }
      for (E key : removed) {
        counter.remove(key);
      }
      return removed;
    }
docs: Removes all entries with keys that does not match the given set of keys
  
  @param counter
  The counter.
  @param matchKeys
  Keys to match
  @return The set of discarded entries.