List of usage examples for java.util Collections emptySet
@SuppressWarnings("unchecked") public static final <T> Set<T> emptySet()
From source file:Main.java
/** * Returns an unmodifiable set containing the given elements. * * @param ts the elements from which to create a set * @param <T> the type of the element in the set * @return an unmodifiable set containing the given elements or {@code null} in case the given element array is * {@code null}.//from w ww.j a v a 2 s. c om */ public static <T> Set<T> asSet(T... ts) { if (ts == null) { return null; } else if (ts.length == 0) { return Collections.emptySet(); } else { Set<T> set = new HashSet<T>(ts.length); Collections.addAll(set, ts); return Collections.unmodifiableSet(set); } }
From source file:Main.java
public static <T> Set<T> nonNullFrom(Set<T> set) { if (set == null || set.isEmpty()) { return Collections.emptySet(); }/* w w w .ja v a 2 s . co m*/ return Collections.unmodifiableSet(set); }
From source file:Main.java
@SafeVarargs public static <T> Set<T> newSet(T... values) { if (values == null) { return Collections.emptySet(); }// w w w. j a va 2 s . co m return new HashSet<>(Arrays.asList(values)); }
From source file:Main.java
public static Set<String> getQueryParameterNames(Uri uri) { String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); }//from w ww . ja va 2s. c o m 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 Set getSet(Object... objs) { if (objs.length == 0) { return Collections.emptySet(); } else if (objs.length == 1) { return Collections.singleton(objs[0]); } else {//w ww. java 2 s. c o m return new HashSet(Arrays.asList(objs)); } }
From source file:Main.java
public static <E> Set<E> asSet(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptySet(); }/*from ww w . j ava 2s. com*/ if (elements.length == 1) { return Collections.singleton(elements[0]); } LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); Collections.addAll(set, elements); return set; }
From source file:Main.java
/** * Convert a char array to a unmodifiable Set. * * @param array the contents of the new Set * @return a unmodifiable Set containing the elements in the array. *//*w w w . j ava 2 s . com*/ public static Set<Character> arrayToUnmodifiableSet(char... array) { if (array == null) { return Collections.emptySet(); } if (array.length == 1) { return Collections.singleton(array[0]); } return Collections.unmodifiableSet(arrayToSet(array)); }
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 ava 2 s . c om*/ * @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> nullToEmpty(Set<T> set) { return set == null ? Collections.emptySet() : set; }
From source file:Main.java
/** * Converts the specified {@link JSONArray JSON array} to a * {@link List list}./*from ww w . ja v a 2s. c o m*/ * * @param <T> the type of elements maintained by the specified json array * @param jsonArray the specified json array * @return an {@link ArrayList array list} */ @SuppressWarnings("unchecked") public static <T> Set<T> jsonArrayToSet(final JSONArray jsonArray) { if (null == jsonArray) { return Collections.emptySet(); } final Set<T> ret = new HashSet<T>(); for (int i = 0; i < jsonArray.length(); i++) { ret.add((T) jsonArray.opt(i)); } return ret; }