List of usage examples for java.util Collections emptySet
@SuppressWarnings("unchecked") public static final <T> Set<T> emptySet()
From source file:Main.java
/** * Convert a String to a unmodifiable set of characters. * @param str The string to convert//from w w w .j a v a 2 s . c o m * @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
private static Set<String> getQueryParameterNames(Uri uri) { if (uri.isOpaque()) { throw new UnsupportedOperationException("This isn't a hierarchical URI."); }/*from w w w . ja va 2s . c om*/ String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); } Set<String> names = new LinkedHashSet<String>(); int start = 0; do { int next = query.indexOf('&', start); int end = (next == -1) ? query.length() : next; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } String name = query.substring(start, separator); names.add(Uri.decode(name)); // Move start to end of name. start = end + 1; } while (start < query.length()); return Collections.unmodifiableSet(names); }
From source file:Main.java
/** * Returns a collection with the common elements in c1 and c2 * @param <T>//from w w w . ja v a 2 s. c om * @param c1 * @param c2 * @return */ public static <T> Collection<T> intersect(Collection<T> c1, Collection<T> c2) { if (c1.isEmpty() || c2.isEmpty()) { return Collections.emptySet(); } if (!(c2 instanceof Set) && (c1 instanceof Set || c1.size() > c2.size())) { //swap Collection<T> tmp = c1; c1 = c2; c2 = tmp; } Collection<T> result = new HashSet<T>(); for (T obj : c1) { if (c2.contains(obj)) { result.add(obj); } } return result; }
From source file:Main.java
public static Set<String> getQueryParameterNames(Uri uri) { if (uri.isOpaque()) { throw new UnsupportedOperationException("This isn't a hierarchical URI."); }/* ww w . ja v a 2s. c om*/ String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); } Set<String> names = new LinkedHashSet<String>(); int start = 0; do { int next = query.indexOf('&', start); int end = next == -1 ? query.length() : next; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; } String name = query.substring(start, separator); names.add(Uri.decode(name)); // Move start to end of name. start = end + 1; } while (start < query.length()); return Collections.unmodifiableSet(names); }
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
/** * Creates an unmodifiable set filled with the given values. * //ww w. j a v a 2 s . co m * @param <T> * the set's element type. * @param values * the values. * @return a newly created set containing the given values. */ @SafeVarargs public static <T> Set<T> createUnmodifiableSet(final T... values) { switch (values.length) { case 0: return Collections.emptySet(); case 1: return Collections.singleton(values[0]); default: return Collections.unmodifiableSet(createHashSet(values)); } }
From source file:Main.java
/** * Build a set of bean from the provided iterable * @param source any kind of iterable// w w w . j av a 2 s . c om * @return a {@link Serializable} {@link Set} containing the same element set */ public static <Bean> Set<Bean> asSet(Iterable<Bean> source) { if (source instanceof Set && source instanceof Serializable) { return (Set<Bean>) source; } else if (source == null) { return Collections.emptySet(); } else { Set<Bean> returned = new HashSet<Bean>(); for (Bean b : source) { returned.add(b); } return returned; } }
From source file:Main.java
public static <T> Set<T> unmodifiableSet(Set<? extends T> list) { if ((list == null) || (list.isEmpty())) { return Collections.emptySet(); }//from ww w . j a va 2s . c om return Collections.unmodifiableSet(list); }
From source file:Main.java
/** * This is a convenience method that essentially checks for a null set and returns Collections.emptySet in that * case. If the set is non-null, then this is an identity function. * // w w w. j a v a 2s . c o m * @param <T> * @param set * @return */ public static <T> Set<T> getSetValue(Set<T> set) { if (set == null) { return Collections.emptySet(); } return set; }
From source file:Main.java
public static <T> Set<T> newSet(T... values) { if (values == null) { return Collections.emptySet(); }/* w w w . j a v a2 s .c om*/ return new HashSet<T>(Arrays.asList(values)); }