### Question:
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(); static final Set<T> create(
      final int initialCapacity, final int maxSize, final Mode mode);  }### Answer:
@Test public void create_evictOldest() { final Set<Integer> set = LimitedSet.create(1, 2, Mode.DROP_OLDEST_ELEMENT); set.add(1); assertThat(set.size()).isEqualTo(1); set.add(2); assertThat(set.size()).isEqualTo(2); set.add(1); set.add(3); assertThat(set.size()).isEqualTo(2); assertThat(set.contains(3)).isTrue(); assertThat(set.contains(2)).isTrue(); }
@Test public void create_evictLeastRecentlyAccessed() { final Set<Integer> set = LimitedSet.create(1, 2, Mode.DROP_LEAST_RECENTLY_ACCESSED); set.add(1); assertThat(set.size()).isEqualTo(1); set.add(2); assertThat(set.size()).isEqualTo(2); set.add(1); set.add(3); assertThat(set.size()).isEqualTo(2); assertThat(set.contains(3)).isTrue(); assertThat(set.contains(1)).isTrue(); }