List of usage examples for java.util Collection isEmpty
boolean isEmpty();
From source file:Main.java
/** * Method to check if the collection is empty or not. * * @param collection the collection/*from w w w . j a va 2 s.c o m*/ * @return true if the collection is null or the collection is empty. */ public static Boolean isEmpty(final Collection collection) { return collection == null || collection.isEmpty(); }
From source file:Main.java
/** * Determine whether the given collection only contains a * single unique object./*from w w w . ja v a 2 s . co m*/ * @param coll the collection to check * @return <code>true</code> if the collection contains a * single reference or multiple references to the same * instance, <code>false</code> else */ public static boolean hasUniqueObject(Collection<?> coll) { if (coll.isEmpty()) { return false; } Object candidate = null; for (Iterator<?> it = coll.iterator(); it.hasNext();) { Object elem = it.next(); if (candidate == null) { candidate = elem; } else if (candidate != elem) { return false; } } return true; }
From source file:Main.java
public static <T> boolean isEmptyOrNull(Collection<T> c) { if (null == c) return true; return c.isEmpty(); }
From source file:Main.java
public static <T> T first(Collection<T> collection) { if (collection == null || collection.isEmpty()) { return null; }/* w w w .ja v a2 s. com*/ return collection.iterator().next(); }
From source file:Main.java
public static boolean isEmpty(Collection<?> collection) { return ((collection == null) || collection.isEmpty()); }
From source file:Main.java
public static <T> Collection<T> isEmpty(Collection<T> collection, String messgae) { if (collection == null || collection.isEmpty()) { //TODO: Araz throw new IllegalArgumentException(messgae); }/*from www. ja v a 2s .co m*/ return collection; }
From source file:Main.java
public static boolean isEmpty(Collection<?> collection) { if (collection == null || collection.isEmpty()) { return true; } else {// www. j ava2 s. co m return false; } }
From source file:Main.java
public static int[] toIntArray(Collection<Integer> list) { if (list == null || list.isEmpty()) { return EMPTY_INT_ARRAY; }//from www.ja va 2 s.c o m int[] result = new int[list.size()]; int i = 0; for (Integer integer : list) { result[i++] = integer; } return result; }
From source file:Main.java
/** * Get comma separated string from collection * // ww w. ja va 2 s . c om * @param strings * @return */ public static String getCommaSeparatedString(Collection<String> strings) { if (strings != null && !strings.isEmpty()) { Iterator<String> it = strings.iterator(); StringBuilder sb = new StringBuilder(it.next()); while (it.hasNext()) { sb.append("," + it.next()); } return sb.toString(); } else { return null; } }
From source file:Main.java
public static final boolean isNotEmpty(Collection<?> c) { return null != c && !c.isEmpty(); }