List of usage examples for java.util Collections unmodifiableSet
public static <T> Set<T> unmodifiableSet(Set<? extends T> s)
From source file:Main.java
public static <E> Set<E> intersection(final Set<E> set1, final Set<E> set2) { Set<E> set = new HashSet<>(set1); set.retainAll(set2);/*from w ww. j a v a 2 s . c o m*/ return Collections.unmodifiableSet(set); }
From source file:Main.java
public static <T> Set<T> copyToLinkedHashSet(Collection<? extends T> src) { if (src.isEmpty()) { return Collections.emptySet(); }/*www . j av a 2 s . c o m*/ return Collections.unmodifiableSet(new LinkedHashSet<T>(src)); }
From source file:Main.java
public static <T> Set<T> immutableSet(Collection<? extends T> set) { return Collections.unmodifiableSet(set instanceof Set ? (Set<? extends T>) set : new HashSet<T>(set)); }
From source file:Main.java
/** Shortcut for creating a Set collection. Used for the list of required and unbound parameters. */ public static <T2> Set<T2> unmodifiableSet(T2... items) { return Collections.unmodifiableSet(new HashSet<T2>(Arrays.asList(items))); }
From source file:Main.java
@SafeVarargs public static <V> Set<V> unmodifiableSet(Set<V> s, V... elements) { return Collections.unmodifiableSet(toSet(s, elements)); }
From source file:Main.java
public static <T> Set<T> asUnmodifiableSet(T[] a_array) /* */ {/*from w ww . java2 s.co m*/ /* 318 */if (a_array == null) /* */ { /* 320 */return null; /* */} /* */ /* 324 */List list = Arrays.asList(a_array); /* 325 */Set set = new HashSet(list); /* 326 */return Collections.unmodifiableSet(set); /* */}
From source file:Main.java
public static <T> Set<T> immutableSet(T... set) { if (set == null) return Collections.emptySet(); return Collections.unmodifiableSet(new HashSet<T>(Arrays.asList(set))); }
From source file:Main.java
public static <T> Set<T> toImmutableSet(Set<T> set) { switch (set.size()) { case 0:/*from w w w . j a v a2s .c om*/ return Collections.emptySet(); case 1: return Collections.singleton(set.iterator().next()); default: return Collections.unmodifiableSet(set); } }
From source file:Main.java
/** * Convert a String to a unmodifiable set of characters. * @param str The string to convert/*from w ww .j av a 2 s . com*/ * @return A set containing the characters in str. A empty set * is returned if str is null. */ public static Set<Character> strToUnmodifiableSet(String str) { if (str == null) return Collections.emptySet(); if (str.length() == 1) return Collections.singleton(str.charAt(0)); return Collections.unmodifiableSet(strToSet(str)); }
From source file:Main.java
public static <T> Set<T> unmodifiableSet(Set<? extends T> list) { if ((list == null) || (list.isEmpty())) { return Collections.emptySet(); }//from w w w .j a v a 2 s. c o m return Collections.unmodifiableSet(list); }