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 <T> List<T> toList(Iterable<T> iterable) { if (null == iterable) return Collections.emptyList(); List<T> retList = new LinkedList<>(); for (T item : iterable) { retList.add(item);//from w w w . ja v a 2 s . com } return retList; }
From source file:Main.java
/** * Sub the list without exception//w w w .jav a2 s . c o m */ public static <T> List<T> safeSubList(List<T> list, int start, int end) { if (start >= list.size()) { return Collections.emptyList(); } return list.subList(start, Math.min(end, list.size())); }
From source file:Main.java
public static <K, V> List<V> getValueList(Map<K, List<V>> map, K key) { List<V> valueList = map.get(key); if (valueList == null) { return Collections.emptyList(); }/* www . j a v a2 s. c om*/ return valueList; }
From source file:Main.java
public static <E> List<E> copyNullSafeList(Collection<? extends E> list) { if (list.isEmpty()) { return Collections.emptyList(); }/*from w ww . j a v a 2 s . co m*/ return Collections.unmodifiableList(copyNullSafeMutableList(list)); }
From source file:Main.java
public static final <T> List<List<T>> devide(List<T> origin, int size) { if (origin == null || origin.isEmpty() || size <= 0) { return Collections.emptyList(); }/*w w w .ja va 2s . c om*/ final int block = origin.size() / size + (origin.size() % size > 0 ? 1 : 0); List<List<T>> devidedList = new ArrayList<List<T>>(block); for (int i = 0; i < block; i++) { final int start = i * size; final int end = Math.min(start + size, origin.size()); devidedList.add(new ArrayList<T>(origin.subList(start, end))); } return devidedList; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <V, T extends Collection<V>> Collection<V> orEmpty(T collection) { return (collection == null ? (Collection<V>) Collections.emptyList() : collection); }
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 www .j a va2 s . c o m*/ return Collections.singletonList(obj); } }
From source file:Main.java
public static <T> List<T> safeSubList(List<T> list, int fromIndex, int toIndex) { int size = list.size(); if (fromIndex >= size || toIndex <= 0 || fromIndex >= toIndex) { return Collections.emptyList(); }/* ww w . j a va 2s . c o m*/ fromIndex = Math.max(0, fromIndex); toIndex = Math.min(size, toIndex); return list.subList(fromIndex, toIndex); }
From source file:Main.java
public static <T, C extends Collection<T>> List<T> merge(Collection<C> splits) { if (splits == null || splits.isEmpty()) { return Collections.emptyList(); }//from w w w .j a va2 s . co m List<T> list = new ArrayList<>(); for (Collection<T> split : splits) { list.addAll(split); } return list; }
From source file:Main.java
public static <E> List<E> concatList(List<E>... array) { if (array == null || array.length < 1) { return Collections.emptyList(); }/*from w w w .j ava 2 s . c o m*/ List<E> newList = new ArrayList<E>(); for (List<E> e : array) { if (isNotEmpty(e)) { newList.addAll(e); } } return newList; }