List of usage examples for java.util Collection size
int size();
From source file:Main.java
public static <T> T checkAndReturnOnlyElement(Collection<T> collection) { if (collection == null || collection.size() == 0) { return null; } else if (collection.size() != 1) { throw new IllegalStateException("collection size is " + collection.size()); }/*w w w .j a v a 2s .co m*/ return collection.iterator().next(); }
From source file:Main.java
@SuppressWarnings("rawtypes") public static boolean allIn(Collection source, Collection target) { if (target == null || target.size() == 0) { return false; }/*from w w w. ja va2s . c om*/ for (Iterator it = source.iterator(); it.hasNext();) { Object object = it.next(); if (!target.contains(object)) { return false; } } return true; }
From source file:Main.java
/** * Retorna true se a colleciton for null ou vazia. */// ww w . j a va 2 s.co m public static <T> boolean isEmpty(final Collection<T> collection) { return collection == null || collection.size() == 0; }
From source file:Main.java
public static boolean isNonEmpty(Collection c) { return (c != null && c.size() > 0); }
From source file:Main.java
public static long[] toLongArray(Collection<? extends Number> c) { long arr[] = new long[c.size()]; int i = 0;// w w w . ja v a 2s. c om for (Number item : c) { arr[i++] = item.longValue(); } return arr; }
From source file:Main.java
/** * Returns the size of the specified collection or 0 on null. * @param <T>//from www . j a v a 2s. c o m * @param collection * @return */ public static <T> int size(Collection<T> collection) { return collection == null ? 0 : collection.size(); }
From source file:Main.java
public static byte[] toByteArray(Collection<? extends Number> c) { byte arr[] = new byte[c.size()]; int i = 0;// w ww .j a v a 2 s. c o m for (Number item : c) { arr[i++] = item.byteValue(); } return arr; }
From source file:Main.java
public static boolean isEmpty(Collection<?> collection) { if (collection == null || collection.size() == 0) { return true; }/*from w w w.ja v a 2 s .co m*/ return false; }
From source file:Main.java
/** * @param array/*from w w w . ja v a 2s . c om*/ * @return */ public static <T> boolean isEmpty(Collection<T> array) { if (array == null || array.size() == 0) { return true; } return false; }
From source file:Main.java
public static <T> boolean isEmpty(Collection<T> collection) { return null == collection || collection.size() <= 0; }