Example usage for java.util Collection remove

List of usage examples for java.util Collection remove

Introduction

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

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:Main.java

public static <T> void removeAll(Collection<T> collection, T... array) {
    for (T t : array) {
        collection.remove(t);
    }// w w  w. j av a2 s .c  o m
}

From source file:Main.java

public static <O> boolean replace(Collection<O> c, O item) {
    if (c == null) {
        return false;
    }/* w w w .jav a 2 s  .  c o m*/

    c.remove(item);
    c.add(item);

    return true;
}

From source file:Main.java

/**
 * Removes and returns an arbitrary element from the collection
 *///ww  w  .j  a  v  a  2 s  . c o m
public static Object removeElement(Collection coll) {
    Object ele = getAnElement(coll);
    coll.remove(ele);
    return ele;
}

From source file:Main.java

/**
 * Removes items from collection/* w  ww.ja  v a  2  s.c  om*/
 * @param <T>
 * @param collection
 * @param items 
 */
public static final <T> void remove(Collection<T> collection, T... items) {
    for (T t : items) {
        collection.remove(t);
    }
}

From source file:Main.java

public static <T> boolean remove(Collection<T> col, T value) {
    if (col == null) {
        return false;
    }/*from   ww  w .ja  va  2s.c  o m*/

    return col.remove(value);
}

From source file:Main.java

public static <T> void removeAll(Collection<T> c, T... items) {
    assert c != null;
    assert items != null;

    for (T item : items) {
        c.remove(item);
    }// ww  w  . j a v a2  s  .co  m
}

From source file:Main.java

public static <T> void cleanNulls(Collection<T> c) {
    Iterator<T> it = c.iterator();
    try {/*  w  ww .  jav a2s. c o  m*/
        while (it.hasNext())
            if (it.next() == null)
                c.remove(null);
    } catch (NullPointerException e) {
        // Does not permit nulls, it should be ok
    }
}

From source file:Main.java

/**
 * Removes all objects from the specified list.
 *
 * @param collection list to fill//from  w ww .  j a  va 2  s .  co  m
 * @param objects    objects
 * @param <T>        objects type
 * @return true if list changed as the result of this operation, false otherwise
 */
public static <T> boolean removeAll(final Collection<T> collection, final T... objects) {
    boolean result = false;
    for (final T object : objects) {
        result |= collection.remove(object);
    }
    return result;
}

From source file:org.opendatakit.aggregate.odktables.Util.java

/**
 * V must implement equals./*ww  w . j  a va 2 s .  co m*/
 */
public static <V> void assertCollectionSameElements(Collection<V> expected, Collection<V> actual) {
    Collection<V> expectedCopy = new ArrayList<V>(expected);
    Collection<V> actualCopy = new ArrayList<V>(actual);

    for (V item : actualCopy) {
        assertTrue(expectedCopy.remove(item));
    }
    assertTrue(expectedCopy.isEmpty());
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> Collection<T> substract(Collection<T> oldList, Collection<T> newList,
        java.util.Comparator comparator) {
    Collection<T> result = new ArrayList<T>(oldList);
    for (T oldValue : oldList) {
        for (T newValue : newList) {
            if (comparator.compare(oldValue, newValue) == 0) {
                result.remove(oldValue);
            }/*from w  w  w . j a  v a 2  s  .  c  o  m*/
        }
    }
    return result;
}