Collect { @SuppressWarnings("unchecked") public static <T, V> Set<T> unmodifiableSet(Function<V, T> extractor, V... values) { Set<T> newSet = new HashSet<>(); for (V value : values) { if (value != null) { newSet.add(extractor.apply(value)); } } return Collections.unmodifiableSet(newSet); } private  Collect(); static Map<K, V> fixedSizeMap(int maximumNumberOfEntries); @SuppressWarnings("unchecked") static Set<T> unmodifiableSet(Function<V, T> extractor, V... values); static Set<T> unmodifiableSet(Function<V, T> extractor, Collection<V> values); @SuppressWarnings("unchecked") static Set<T> unmodifiableSet(Set<T> values, T... additionalValues); @SuppressWarnings("unchecked") static Set<T> unmodifiableSet(T... values); static Set<T> unmodifiableSet(Collection<T> values); static Set<T> unmodifiableSet(Set<T> values); static Set<T> unmodifiableSet(Iterator<T> values); static List<T> arrayListOf(T[] values); @SuppressWarnings("unchecked") static List<T> arrayListOf(T first, T... additional); static List<T> arrayListOf(Iterable<T> values); static Map<K, V> mapOf(K key, V value); static Map<K, V> hashMapOf(K key, V value); static Map<K, V> hashMapOf(K key1, V value1, K key2, V value2); static Map<K, V> hashMapOf(K key1, V value1, K key2, V value2, K key3, V value3); static Map<K, V> hashMapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); static Map<K, V> hashMapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5); static Map<K, V> hashMapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5, K key6, V value6); static Map<K, V> linkMapOf(K key, V value); static Map<K, V> linkMapOf(K key1, V value1, K key2, V value2); static Map<K, V> linkMapOf(K key1, V value1, K key2, V value2, K key3, V value3); static Map<K, V> linkMapOf(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4); static Properties propertiesOf(String key, String value); static Properties propertiesOf(String key1, String value1, String key2, String value2); static Properties propertiesOf(String key1, String value1, String key2, String value2, String key3, String value3); static Properties propertiesOf(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4); static Properties propertiesOf(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4, String key5,
                                          String value5); static Properties propertiesOf(String key1, String value1, String key2, String value2, String key3, String value3, String key4, String value4, String key5,
                                          String value5, String key6, String value6); static void set(List<T> list, int index, T value, T defaultValue);  }
@Test public void unmodifiableSetForIteratorShouldReturnExpectedElements() { Set<Integer> values = Collect.unmodifiableSet(Arrays.asList(1, 2, 3, 42).iterator()); assertThat(values).containsOnly(1, 2, 3, 42); }
@Test(expected = UnsupportedOperationException.class) public void unmodifiableSetForIteratorShouldRaiseExceptionUponModification() { Set<Integer> values = Collect.unmodifiableSet(Arrays.asList(1, 2, 3, 42).iterator()); values.remove(1); }