class LimitedSet {

  public static final <T> Set<T> create(
      final int initialCapacity, final int maxSize, final Mode mode) {
    final boolean useAccessOrder = mode.equals(Mode.DROP_LEAST_RECENTLY_ACCESSED);
    return Collections.synchronizedSet(
        Collections.newSetFromMap(
            new LinkedHashMap<T, Boolean>(initialCapacity, 0.75f, useAccessOrder) {
              @Override
              protected boolean removeEldestEntry(final Map.Entry<T, Boolean> eldest) {
                return size() > maxSize;
              }
            }));
  }

  private  LimitedSet();

}