Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

In this page you can find the example usage for java.util Collection addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:Main.java

static <V> void addAllIfNotNull(final Collection<V> collection, final Collection<V> values) {
    if (collection != null && values != null) {
        collection.addAll(values);
    }/*from  w  w  w.ja  v  a 2 s. co m*/

}

From source file:Main.java

public static <T> void addIfNotEmpty(Collection<T> c, Collection<T> elements) {
    if (null != c && null != elements && !elements.isEmpty()) {
        c.addAll(elements);
    }/* w  ww  . j a  v  a 2s.c om*/
}

From source file:Main.java

public static <T> Collection<T> flatten(final Collection<? extends Collection<T>> second) {
    final Collection<T> returnList = new ArrayList<>();

    for (final Collection<T> collection : second) {
        returnList.addAll(collection);
    }/*ww  w .j av  a 2s  . c  o m*/

    return returnList;
}

From source file:Main.java

public static <E> void intersection(final Collection<E> a, final Collection<E> b) {
    if (b != null && !b.isEmpty()) {
        if (a.isEmpty()) {
            a.addAll(b);
        } else {// ww  w .  jav a  2 s .  c om
            a.retainAll(b);
        }
    }
}

From source file:Main.java

/**
 * Adds all of the elements in the specified collection to the target collection if
 * a collection is specified.//from   w ww  .  j  a  v a  2  s.  c  om
 * 
 * @param <E>
 * @param target
 * @param c collection containing elements to be added to this collection, may be null
 * @return <tt>true</tt> if this collection changed as a result of the call
 */
public static <E> boolean addAllIfSet(Collection<E> target, Collection<? extends E> c) {
    if (c == null)
        return false;
    return target.addAll(c);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> Collection<T> unique(Collection<T> c, Collection<T> result) {
    if (c == null) {
        return result;
    }/*from ww w.  j a  va2 s  .co  m*/
    Set<T> s = new LinkedHashSet<T>(c);
    result.addAll(s);
    return result;
}

From source file:Main.java

public static <T> Collection<T> merge(Collection<T>... col) {

    //ensure maximum capacity
    Collection<T> result = new ArrayList(col.length);

    for (Collection<T> c : col) {
        if (c != null)
            result.addAll(c);
    }/*  w w w . ja v  a 2  s .co  m*/

    return result;

}

From source file:Main.java

/**
 * /*from  ww w .  j ava 2s .  co  m*/
 * @param collections
 * @return Collection
 */
public static Collection<?> getIntersection(
        final Collection<? extends Collection<? extends Object>> collections) {
    final List<Collection<?>> collectionsList = new ArrayList<Collection<?>>(collections);
    final Collection<Object> intersection = new HashSet<>();

    if (collectionsList.size() != 0) {
        intersection.addAll(collectionsList.get(0));
    }

    for (int i = 1; i < collections.size() && intersection.size() > 0; i++) {
        intersection.retainAll(new HashSet<>(collectionsList.get(i)));
    }

    return intersection;
}

From source file:Main.java

/**
 * Adds the given items to the given collection
 * /*from  w w w.j  av  a  2 s. com*/
 * @param <T>
 *            the type of item in the collection being updated
 * @param newItems
 *            the items being added; can be <code>null</code> for none
 * @param existingItems
 *            the items being added to; must be modifiable
 * @return <code>true</code> if the existing collection was modified
 * @throws UnsupportedOperationException
 *             if there are items to add and the existing collection is not
 *             modifiable
 * @since 1.2.0
 */
public static <T> boolean addAll(final Collection<? extends T> newItems, final Collection<T> existingItems) {
    if ((existingItems != null) && (newItems != null)) {
        return existingItems.addAll(newItems);
    }
    return false;
}

From source file:Main.java

public static <K> void addAll(Collection<K> destination, Collection<? extends K> toBeAdded) {
    if (destination != null && toBeAdded != null) {
        destination.addAll(toBeAdded);
    }/*from  ww  w .j ava  2s.co  m*/
}