List of usage examples for java.util Collections emptyList
@SuppressWarnings("unchecked") public static final <T> List<T> emptyList()
From source file:Main.java
private static List<String> split(String input, String delimiter) { if (input == null || input.isEmpty()) { return Collections.emptyList(); }//from ww w . j a v a2 s . c om return new ArrayList<String>(Arrays.asList(input.split(delimiter))); }
From source file:Main.java
/** * convert to List<T> from Enumeration<T> * //from w w w.j a v a2s.co m * @param enumeration * @return */ public static <T> List<T> convert(Enumeration<T> enumeration) { if (enumeration == null) { return Collections.emptyList(); } ArrayList<T> result = new ArrayList<T>(); while (enumeration.hasMoreElements()) { result.add(enumeration.nextElement()); } return result; }
From source file:Main.java
public static <V> List<V> uniteCollectionArray(Collection<V[]> values) { if (isEmpty(values)) { return Collections.emptyList(); }//from w ww . j a v a2 s. c o m List<V> copy = new ArrayList<V>(); for (V[] collections : values) { copy.addAll(Arrays.asList(collections)); } return copy; }
From source file:Main.java
/** * /* www . j av a 2 s .com*/ * @param c1 * @param s1 * @return c1 - s1 * */ public static <T> List<T> minius(Collection<T> c1, Collection<T> s1) { if (c1 == null) { return Collections.emptyList(); } if (s1 == null || s1.size() == 0) { return new ArrayList<T>(c1); } List<T> list = new ArrayList<T>(); for (T t : c1) { if (!s1.contains(t)) { list.add(t); } } return list; }
From source file:Main.java
public static <T> List<T> immutableList(T... list) { if (list == null) return Collections.emptyList(); return immutableList(Arrays.asList(list)); }
From source file:Main.java
public static <T> List<T> toImmutableList(List<T> list) { switch (list.size()) { case 0:// w ww . jav a 2 s . com return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: return Collections.unmodifiableList(list); } }
From source file:Main.java
/** * Returns an non null value based on the giving {@link List} * * @param list/* w w w . ja v a2 s . co m*/ * value to evaluate * @return the original value or an empty {@link List} * @since 4.2 */ public static <T> List<T> nonNullList(@Nullable final List<T> list) { return list == null ? Collections.emptyList() : list; }
From source file:Main.java
public static <T> List<T> innerJoin(List<List<T>> list, BiFunction<T, T, T> function) { if (list == null || function == null) { throw new NullPointerException("list or function must not be null"); }/*from www . j a v a 2 s.c o m*/ if (list.isEmpty()) { return Collections.emptyList(); } if (list.size() == 1) { return list.get(0); } List<List<T>> result = innerJoin(list.get(0), list.get(1), function); if (list.size() == 2) { return merge(result); } else { for (int i = 2; i < list.size(); i++) { List<T> l1 = list.get(i); List<List<T>> temp = new ArrayList<>(); result.stream().forEach(l -> temp.addAll(innerJoin(l, l1, function))); result = temp; } return merge(result); } }
From source file:Main.java
/** * Returns an non null value based on the giving {@link Collection} * * @param collection/*from w w w.j a v a2 s . c o m*/ * value to evaluate * @return the original value or an empty {@link Collection} * @since 4.2 */ public static <T> Collection<T> nonNullCollection(@Nullable final Collection<T> collection) { return collection == null ? Collections.emptyList() : collection; }
From source file:Main.java
public static <T> List<T> toImmutableList(final Collection<T> c) { if (c.isEmpty()) { return Collections.emptyList(); } else {/*from ww w. jav a2s . c o m*/ return Collections.unmodifiableList(new ArrayList<T>(c)); } }