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> pageList(List<T> list, int page, int size) { if (page < 1) { throw new IllegalArgumentException("page should not little than 1,page:" + page); }/* w w w . ja va2s .c o m*/ if (size < 1) { throw new IllegalArgumentException("size should not little than 1,size:" + size); } if (isEmpty(list)) { return Collections.emptyList(); } int totalSize = list.size(); int fromIndex = (page - 1) * size > (totalSize - 1) ? 0 : (page - 1) * size; int endIndex = (fromIndex + size) > (totalSize) ? (totalSize) : (fromIndex + size); return list.subList(fromIndex, endIndex); }
From source file:Main.java
/** * /*from w ww. java2 s.c om*/ * Returns an unmodifiable view of the specified list. This method makes use * of the method unmodifiableList of java.util.Collections and returns an * empty list if the provided list is null. * * @param list * @return * @see java.util.Collections.unmodifiableList */ public static <T> List<T> unmodifiableList(List<? extends T> list) { if (list == null) { return Collections.emptyList(); } else { return Collections.unmodifiableList(list); } }
From source file:Main.java
public static <T> Collection<T> safe(Collection<T> l) { if (l == null) { return Collections.emptyList(); }/*from w w w . j a va 2 s . c o m*/ return l; }
From source file:Main.java
public static <T> List<T> list() { return Collections.emptyList(); }
From source file:Main.java
/** * @return An ArrayList of the elements of array converted to strings, or the empty list if * array is null. Empty strings in the input array are preserved. *///from w ww. j a va2 s . c o m public static List<String> getStringList(JSONArray array) { String[] stringArray = getStringArray(array); if (stringArray == null) { return Collections.emptyList(); } return Arrays.asList(stringArray); }
From source file:Main.java
public static <O> List<O> safeSubList(List<O> l, int offset, int count) { if (l == null) { return null; }//from w ww . j a va2 s .com if (offset >= l.size()) return Collections.emptyList(); if (count == 0) count = l.size(); return l.subList(offset, Math.min(offset + count, l.size())); }
From source file:Main.java
/** * Extracts a list of integer values from the specified attribute. * @param element the element to fetch the integer list from * @param attributeName the name of the attribute containing the integer list * @return a list of integer values from the specified attribute *//*from ww w . j a va 2s .c o m*/ public static List<Integer> getIntegerListAttribute(Element element, String attributeName) { String intListString = element.getAttribute(attributeName); if (intListString == null || intListString.length() == 0) { return Collections.emptyList(); } String[] intStrings = intListString.split(" "); //$NON-NLS-1$ List<Integer> intValues = new ArrayList<Integer>(intStrings.length); for (String intString : intStrings) { Integer intValue = Integer.valueOf(intString); intValues.add(intValue); } return intValues; }
From source file:Main.java
/** * Generates permutations from a list of collections. Each permutation contains an element * from each of the collections. /*from www .j a va2s. com*/ * * @param <T> the generic type for object in the collections * @param collections the list of collections * @return the collection of permutations */ public static <T> Collection<List<T>> generatePermutations(List<Collection<T>> collections) { if (collections == null || collections.isEmpty()) { return Collections.emptyList(); } else { Collection<List<T>> res = new LinkedList<List<T>>(); permutationsImpl(collections, res, 0, new LinkedList<T>()); return res; } }
From source file:Main.java
/** * Create a new array list from the specified list of items. It is expected * that all items are of the same type.// w w w . j a va 2s. com * * @param items * The items to add to the list * @return */ public static <T> List<T> createList(T... items) { List<T> result; if (items != null && items.length > 0) { result = new ArrayList<T>(items.length); for (int i = 0; i < items.length; i++) { result.add(items[i]); } } else { result = Collections.emptyList(); } return result; }
From source file:Main.java
/** * This is a convenience method that essentially checks for a null list and returns Collections.emptyList in that * case. If the list is non-null, then this is an identity function. * /*from w w w .j a va2 s . c om*/ * @param <T> * @param list * @return */ public static <T> List<T> getListValue(List<T> list) { if (list == null) { return Collections.emptyList(); } return list; }