List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:Main.java
public static <O> boolean safeAddAll(Collection<O> c, Collection<O> items) { try {//from www . j a v a 2 s.c o m return c.addAll(items); } catch (Throwable ex) { return false; } }
From source file:Main.java
public static <O> boolean safeAddAll(Collection<O> c, Collection<? extends O> items) { try {/* ww w.j a v a2 s .c o m*/ return c.addAll(items); } catch (Throwable ex) { return false; } }
From source file:Main.java
/** * Copies an existing {@link Collection} into a new (non-abstract!) * {@code Collection} class./*from ww w . j a v a 2s .co m*/ * * @param cl Non-abstract {@code Collection} class. * @param old An existing {@code Collection}. * * @return A new instance of {@code cl} that contains all of the elements * from {@code old}. * * @throws RuntimeException if there was trouble creating a new instance * of {@code cl}. * * @see #collect(Class, Object...) */ // not sure about the utility of this one... @SuppressWarnings({ "unchecked", "rawtypes" }) // again, only adding items of type "E" public static <E> Collection<E> recollect(Class<? extends Collection> cl, Collection<E> old) { try { Collection<E> c = cl.getConstructor().newInstance(); c.addAll(old); return c; } catch (Exception e) { throw new RuntimeException("", e); } }
From source file:Main.java
/** * Adds all elements of collection2 to collection1. collection2 may be * <code>null</code>, in which case nothing happens. */// ww w . ja v a2 s. c o m public static <T> void addAllSafe(Collection<T> collection1, Collection<T> collection2) { if (collection2 != null) { collection1.addAll(collection2); } }
From source file:Main.java
public static <T> void addAll(Collection<T> c, T[] array) { if (isEmpty(array)) { return;//from w ww . j av a2 s .com } c.addAll(Arrays.asList(array)); }
From source file:Main.java
public static <T extends Object> void addAll(Collection<T> target, Collection<T> source) { if (target != null && source != null && source.size() > 0) { target.addAll(source); }/*from ww w. j a v a 2 s .com*/ }
From source file:Main.java
public static final <T> void add(Collection<T> collection, T... values) { if (values == null || values.length == 0) { return;// w w w.j a v a 2s .com } collection.addAll(Arrays.asList(values)); }
From source file:Main.java
/** * Adds all elements in the iteration to the given collection. * //from ww w . j a v a2 s .c om * @param <T> classe parametre * @param collectionDest the collection to add to, must not be null * @param collectionSrc collection src * @return boolean check */ public static <T> Boolean copyAll(Collection<? super T> collectionDest, Collection<? extends T> collectionSrc) { return collectionSrc == null ? false : collectionDest.addAll(collectionSrc); }
From source file:org.vader.apm.dao.util.DaoUtils.java
/** * Filter all objects by type./*w w w . ja v a2s . co m*/ * * @param dbObjects objects to filter * @param state DB object state * @param <T> DB object type * @return filtered objects */ public static <T extends ApmDbObject> Collection<T> getDbObjectsByState(Collection<T> dbObjects, DbObjectState state) { final Collection<T> result = Sets.newIdentityHashSet(); result.addAll(Collections2.filter(dbObjects, state)); return result; }
From source file:Main.java
public static <T> Collection<T> setDiff(Collection<T> itemsToStartWith, Collection<T> itemsToSubtract) { Collection<T> retval = new ArrayList<T>(); if (itemsToStartWith == null) return new ArrayList<T>(); retval.addAll(itemsToStartWith); // make copy so you don't mutate original if (itemsToSubtract != null) retval.removeAll(itemsToSubtract); return retval; }