List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:Main.java
/** * Return <code>true</code> if the supplied Collection is <code>null</code> * or empty. Otherwise, return <code>false</code>. * /* w ww .j a v a 2 s . c o m*/ * @param collection * the Collection to check * @return whether the given Collection is empty */ public static boolean isEmpty(final Collection<?> collection) { return ((collection == null) || collection.isEmpty()); }
From source file:Main.java
public static <T> boolean containsAny(Collection<T> collection, Collection<T> query) { if (collection == null || collection.isEmpty() || query == null || query.isEmpty()) return false; for (T val : query) { if (collection.contains(val)) return true; }//from w w w .j av a 2s. c o m return false; }
From source file:Main.java
public static <V> V getRandom(Collection<V> collection) { if (collection.isEmpty()) { return null; }// w ww. j a va2s . co m int randIdx = (int) Math.round(Math.random() * (collection.size() - 1)); int count = 0; Iterator<V> iterator = collection.iterator(); while (iterator.hasNext()) { V current = iterator.next(); if (count == randIdx) { return current; } count++; } throw new RuntimeException("Shouldn't happen"); }
From source file:Main.java
public static boolean isEmpty(Collection<?>... colls) { boolean result = false; for (Collection<?> coll : colls) { if (null == coll || coll.isEmpty()) { result = true;//from w w w. j a v a2 s .c o m break; } } return result; }
From source file:Main.java
public static <T> boolean retainAllByValue(Collection<T> c1, Collection<? extends T> c2) { if (c1 == null || c2 == null || c1.isEmpty() || c2.isEmpty()) return false; List<T> itemsToRemove = new ArrayList<T>(); for (T item : c1) { if (!containsByValue(c2, item)) itemsToRemove.add(item);/*from ww w .ja v a 2 s . c o m*/ } c1.removeAll(itemsToRemove); return (!itemsToRemove.isEmpty()); }
From source file:Main.java
public static boolean isEmpty(final Collection<?> c) { return c == null || c.isEmpty(); }
From source file:Main.java
private static <E> boolean fallBackToStandardImplementation(final Collection<E> coll, final int limit) { return limit >= coll.size() || limit < 0 || coll.isEmpty(); }
From source file:Main.java
/** * Checks if is empty./* w ww . j a v a 2 s. c o m*/ * * @param value * the value * @return true, if is empty */ public static boolean isEmpty(Collection<?> value) { if (value == null) return true; return value.isEmpty(); }
From source file:Main.java
public static <T> boolean isEmptyOrNull(Collection<T> collection) { return collection == null || collection.isEmpty(); }
From source file:Main.java
public static <T> List<T> sub(Collection<T> list, int start, int end) { if (list == null || list.isEmpty()) { return null; }/*from w w w . j a v a2s . c o m*/ return sub(new ArrayList<T>(list), start, end); }