List of usage examples for java.util Collection add
boolean add(E e);
From source file:Main.java
public static void addAllWithoutDuplicates(Collection collection, Collection addTo) { for (Object obj : addTo) { if (!collection.contains(obj)) { collection.add(obj); }/* w ww. ja va 2 s . c o m*/ } }
From source file:Main.java
/** * Returns all objects in list1 that are not in list2 * * @param <T> Type of items in the collection * @param list1 First collection//from www. j a va2s.c o m * @param list2 Second collection * @return The collection difference list1 - list2 */ public static <T> Collection<T> diff(Collection<T> list1, Collection<T> list2) { Collection<T> diff = new ArrayList<T>(); for (T t : list1) { if (!list2.contains(t)) { diff.add(t); } } return diff; }
From source file:Utils.java
public static <T> Collection<T> diff(Collection<T> c1, Collection<T> c2) { if (c1 == null || c1.size() == 0 || c2 == null || c2.size() == 0) { return c1; }/* ww w .j av a2 s. c o m*/ Collection<T> difference = new ArrayList<T>(); for (T item : c1) { if (!c2.contains(item)) { difference.add(item); } } return difference; }
From source file:Main.java
static <V> boolean addIfNotNull(final Collection<V> collection, final V value) { if (value == null) { return false; } else {//from w w w . j ava 2 s.c o m return collection.add(value); } }
From source file:Main.java
/** * Appends an arbitrary number of explicit elements to an existing collection. * Primarily useful when writing testcases. *//*ww w .j a v a2 s . c o m*/ public static <T> void addAll(Collection<T> coll, T... elems) { for (T elem : elems) coll.add(elem); }
From source file:Main.java
private static <T> void permutationsImpl(List<Collection<T>> ori, Collection<List<T>> res, int d, List<T> current) {//from w w w . j ava2 s.co m if (d == ori.size()) { res.add(current); return; } // iterate from current collection and copy 'current' element N times, one for each element Collection<T> currentCollection = ori.get(d); for (T element : currentCollection) { List<T> copy = new LinkedList<T>(); copy.addAll(current); copy.add(element); permutationsImpl(ori, res, d + 1, copy); } }
From source file:Main.java
public static <E> Collection<E> addGreater(Collection<E> collection, E element, Comparator<E> comp) { Collection<E> resultColl = new LinkedList<>(); for (E e : collection) { if (comp.compare(e, element) > 0) resultColl.add(e); }//from w ww . j a va 2s. c om return resultColl; }
From source file:Main.java
public static Collection toCollection(Enumeration _enum, Collection c) { if (c == null) c = new ArrayList(); while (_enum.hasMoreElements()) c.add(_enum.nextElement()); return c;/* www . ja va2 s . c o m*/ }
From source file:Main.java
public static <T> void uniqAdd(Collection<T> collection, T elements) { if (collection == null) return;/* w ww. j av a 2 s.c o m*/ if (!collection.contains(elements)) collection.add(elements); }
From source file:Main.java
public static void addAll(final long[] src, final Collection<Long> dst) { if (src == null) return;//from w w w .j a v a2s . c om for (final long l : src) dst.add(l); }