List of usage examples for java.util Collections emptyList
@SuppressWarnings("unchecked") public static final <T> List<T> emptyList()
From source file:Main.java
/** * Build a list of bean from the provided iterable * @param source any kind of iterable// ww w . j a v a2s . c o m * @return a {@link Serializable} {@link List} containing the same element set */ public static <Bean> List<Bean> asList(Iterable<Bean> source) { if (source instanceof List && source instanceof Serializable) { return (List<Bean>) source; } else if (source == null) { return Collections.emptyList(); } else { List<Bean> returned = new LinkedList<Bean>(); for (Bean b : source) { returned.add(b); } return returned; } }
From source file:Main.java
public static List getList(Object... objs) { if (objs.length == 0) { return Collections.emptyList(); } else if (objs.length == 1) { return Collections.singletonList(objs[0]); } else {//from w w w . j a v a 2s . c o m return new ArrayList(Arrays.asList(objs)); } }
From source file:Main.java
public static List<String> split(String str, String delimiter) { if (str == null || "".equals(str)) { return Collections.emptyList(); }/*from w w w . j a va2 s. c om*/ return Arrays.asList(str.split(delimiter)); }
From source file:Main.java
public static <T> List<T> safe(final List<T> list) { if (list == null) { return Collections.emptyList(); }/* ww w. ja v a 2 s . c o m*/ return list; }
From source file:Main.java
static <E> List<E> getList(List<E> orig, Class<E> elemType) { if (orig == null || orig.isEmpty()) { return Collections.emptyList(); } else if (orig.size() == 1) { return Collections.singletonList(orig.get(0)); } else {/*from ww w. ja v a 2s . co m*/ return Collections.unmodifiableList(Arrays.asList(orig.toArray(createArray(elemType, orig.size())))); } }
From source file:Main.java
public static List<String> stringToList(String str, String delimiter) { if (str == null || "".equals(str)) { return Collections.emptyList(); }//from ww w.java 2s . c o m return Arrays.asList(str.split(delimiter)); }
From source file:Main.java
public static <V> List<V> asList(Enumeration<V> elements) { if (elements == null || !elements.hasMoreElements()) { return Collections.emptyList(); }//from w ww . j a va 2 s .c o m List<V> copy = new ArrayList<V>(); for (; elements.hasMoreElements();) { copy.add(elements.nextElement()); } return copy; }
From source file:Main.java
/** */ public static List<QName> toQName(List<String> removeProps) { if (removeProps == null) { return Collections.emptyList(); }/* ww w . j a v a2 s.com*/ List<QName> result = new ArrayList<QName>(removeProps.size()); for (String entry : removeProps) { result.add(createQNameWithCustomNamespace(entry)); } return result; }
From source file:Main.java
/** Credit Victor from StackOverflow * Combines several collections of elements and create permutations of all of them, taking one element from each * collection, and keeping the same order in resultant lists as the one in original list of collections. * * <ul>Example/*w w w . j a v a 2s.com*/ * <li>Input = { {a,b,c} , {1,2,3,4} }</li> * <li>Output = { {a,1} , {a,2} , {a,3} , {a,4} , {b,1} , {b,2} , {b,3} , {b,4} , {c,1} , {c,2} , {c,3} , {c,4} }</li> * </ul> * * @param collections Original list of collections which elements have to be combined. * @return Resultant collection of lists with all permutations of original list. */ public static <T> Collection<List<T>> permutations(List<Collection<T>> collections) { if (collections == null || collections.isEmpty()) { return Collections.emptyList(); } else { Collection<List<T>> res = Lists.newLinkedList(); permutationsImpl(collections, res, 0, new LinkedList<T>()); return res; } }
From source file:Main.java
/** * Given two collections of elements of type <T>, return a collection with the items which only appear in both lists * /*from ww w . j a v a2s .c o m*/ * @param <T> * Type * @param collection1 * Collection #1 * @param collection2 * Collection #2 * @return Collection with items common to both lists */ public static <T> Collection<T> intersect(Collection<T> collection1, Collection<T> collection2) { if (isEmpty(collection1) || isEmpty(collection2)) { return Collections.emptyList(); } Set<T> intersection = new HashSet<T>(collection1); intersection.retainAll(collection2); return intersection; }