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