List of usage examples for java.util Collection size
int size();
From source file:Main.java
@SuppressWarnings({ "rawtypes" }) private static Object toByteArray(Collection collection) { byte[] ba = new byte[collection.size()]; int i = 0;/*from ww w .j ava2 s . c om*/ for (Object o : collection) { byte b = ((Byte) o).byteValue(); ba[i++] = b; } return ba; }
From source file:Main.java
@SuppressWarnings({ "rawtypes" }) private static Object toLongArray(Collection collection) { long[] la = new long[collection.size()]; int i = 0;/*w w w. j av a2s .co m*/ for (Object o : collection) { long l = ((Long) o).longValue(); la[i++] = l; } return la; }
From source file:Main.java
@SuppressWarnings({ "rawtypes" }) private static Object toCharacterArray(Collection collection) { char[] ca = new char[collection.size()]; int i = 0;/*from w w w . j av a 2 s .co m*/ for (Object o : collection) { char c = ((Character) o).charValue(); ca[i++] = c; } return ca; }
From source file:Main.java
public static boolean hasAtLeastOneNotNullElement(Collection<?> collection) { if (collection == null) return false; if (collection.isEmpty()) return false; if (collection.contains(null)) return collection.size() > 1; return collection.size() > 0; }
From source file:com.qwazr.utils.ArrayUtils.java
public static String[] toArray(Collection<String> collection) { if (collection == null) return null; String[] array = new String[collection.size()]; int i = 0;/* w w w . ja v a2 s . c om*/ for (String val : collection) array[i++] = val; return array; }
From source file:com.qwazr.utils.ArrayUtils.java
public static String[] toStringArray(Collection<Object> collection) { if (collection == null) return null; String[] array = new String[collection.size()]; int i = 0;/*from w ww .ja v a 2 s . c o m*/ for (Object val : collection) array[i++] = val == null ? null : val.toString(); return array; }
From source file:Main.java
/** * Returns true if there is any element that is common to both collections. *///from www . j a va 2 s .c om public static boolean containsAny(Collection c1, Collection c2) { // A better implementation here would be to use sets Collection smallCollection; Collection largeCollection; if (c1.size() < c2.size()) { smallCollection = c1; largeCollection = c2; } else { smallCollection = c2; largeCollection = c1; } boolean intersect = false; Iterator i = smallCollection.iterator(); while (i.hasNext()) { if (largeCollection.contains(i.next())) { intersect = true; break; } } return intersect; }
From source file:com.enonic.cms.core.content.ContentVersionKey.java
public static List<ContentVersionKey> createList(Collection<ContentVersionEntity> versions) { List<ContentVersionKey> list = new ArrayList<ContentVersionKey>(); if (versions == null || versions.size() == 0) { return list; }/*from ww w . j a v a 2s . co m*/ for (ContentVersionEntity version : versions) { list.add(version.getKey()); } return list; }
From source file:eu.planets_project.tb.impl.serialization.ExperimentRecords.java
/** * /* w w w . ja v a 2 s .co m*/ * @param out * @param ecol */ public static void writeExperimentsToOutputStream(OutputStream out, Collection<Experiment> ecol) { writeExperimentsToOutputStream(out, ecol.toArray(new Experiment[ecol.size()])); }
From source file:Main.java
@SuppressWarnings({ "rawtypes" }) private static Object toShortArray(Collection collection) { short[] sa = new short[collection.size()]; int i = 0;//w ww.ja v a 2 s. c o m for (Object o : collection) { short s = ((Short) o).shortValue(); sa[i++] = s; } return sa; }