List of usage examples for java.util Collections emptyList
@SuppressWarnings("unchecked") public static final <T> List<T> emptyList()
From source file:Main.java
public static List<String> split(String str, char delimiter) { if (TextUtils.isEmpty(str)) { return Collections.emptyList(); }/*from ww w . java 2s.com*/ int substringsCount = 1; for (int i = 0, len = str.length(); i < len; i++) { if (str.charAt(i) == delimiter) { substringsCount++; } } if (substringsCount == 1) { return Collections.singletonList(str); } List<String> split = new ArrayList<String>(substringsCount); int index = str.indexOf(delimiter); int lastIndex = 0; while (index != -1) { split.add(str.substring(lastIndex, index)); lastIndex = index + 1; index = str.indexOf(delimiter, lastIndex); } split.add(str.substring(lastIndex, str.length())); // add the final string after the last delimiter return split; }
From source file:Main.java
/** * //from ww w.j ava 2s . c om * @param elements * @return */ public static <E> List<E> asList(E... elements) { if (elements == null || elements.length == 0) { return Collections.emptyList(); } // Avoid integer overflow when a large array is passed in int capacity = computeListCapacity(elements.length); ArrayList<E> list = new ArrayList<E>(capacity); Collections.addAll(list, elements); return list; }
From source file:Main.java
public static <X, Y> List<Y> mapWithFoldr(List<X> xs, Function<X, Y> mapper) { return foldr(xs, Collections.emptyList(), x -> res -> cons(mapper.apply(x), res)); }
From source file:Main.java
public static <T> Collection<Collection<T>> split(Iterable<T> coll, int size) { if (size < 1) { return Collections.emptyList(); }/*from w w w .j ava 2 s .co m*/ final List<Collection<T>> ret = new ArrayList<>(); final Iterator<T> it = coll.iterator(); Collection<T> box = null; for (int i = 0; it.hasNext(); ++i) { if (i % size == 0) { if (box != null) { ret.add(box); } box = new ArrayList<>(size); } //noinspection ConstantConditions box.add(it.next()); } if (box != null) { ret.add(box); } return ret; }
From source file:Main.java
public static List<?> toList(Object obj) { if (obj instanceof List) { return (List<?>) obj; } else if (obj == null) { return Collections.emptyList(); } else {/*from w w w . ja v a2s . c o m*/ return Arrays.asList(obj); } }
From source file:Main.java
public static <T, Tout> List<Tout> select(Iterable<T> source, Function<T, Tout> action) { if (source == null || !source.iterator().hasNext()) return Collections.emptyList(); List<Tout> result = new ArrayList<Tout>(); for (T item : source) { result.add(action.apply(item));/*from w w w . j a v a 2s .co m*/ } return result; }
From source file:Main.java
/** * Like Collections.unmodifiableList(), but with checks for null values. *///from w ww .jav a 2 s. co m public static <T> List<T> unmodifiableList(List<T> list) { if (list == null) { return Collections.emptyList(); } return Collections.unmodifiableList(list); }
From source file:Main.java
public static <V> List<V> uniteCollections(Collection<? extends Collection<V>> values) { if (isEmpty(values)) { return Collections.emptyList(); }//from ww w .j a va2 s . co m List<V> copy = new ArrayList<V>(); for (Collection<V> collection : values) { copy.addAll(collection); } return copy; }
From source file:Main.java
public static Collection<String> addElementBeforeAndAfter(Collection<?> collection, String toAddBefore, String toAddAfter) {//from www. ja va 2 s . co m if (collection == null || collection.isEmpty()) { return Collections.emptyList(); } List<String> result = new ArrayList<>(collection.size()); for (Object o : collection) { StringBuilder stringBuilder = new StringBuilder( o.toString().length() + toAddBefore.length() + toAddAfter.length()); stringBuilder.append(toAddBefore); stringBuilder.append(o.toString().trim()); stringBuilder.append(toAddAfter); result.add(stringBuilder.toString()); } return result; }
From source file:Main.java
public static List<String> split(String input, String delimiter) { if (input == null || input.isEmpty()) { return Collections.emptyList(); }/*from ww w . j a v a2 s . co m*/ return new ArrayList<String>(Arrays.asList(input.split(delimiter))); }