code: private static <T> void shrinkSet(final Set<T> set, int newSize) {
      if (!(set instanceof LinkedHashSet))
        throw new IllegalStateException("Cannot shrink a set which is not of type LinkedHashSet");
      if (newSize > set.size())
        throw new IllegalStateException("Cannot shrink a set of size " + set.size() + " to new size " + newSize);
      Iterator<T> entryIterator = set.iterator();
      int count = 0;
      while (count < newSize) {
        entryIterator.next();
        count++;
      }
      while (entryIterator.hasNext()) {
        entryIterator.next();
        entryIterator.remove();
      }
    }
docs: Shrinks a given set to a given size
  @param set     the set to be shrunk
  @param newSize the new size, the set shall be shrunk to