Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:Main.java

/**
 * add a unique value to a collection. If the value already exists, it will
 * return <code>false</code>.
 * //from  w w w .  ja v a2 s. c o m
 * @param collection
 *            the collection.
 * @param value
 *            the value.
 * @return boolean.
 * @since 0.1
 */
public static boolean addUnique(final Collection collection, final Object value) {
    if (collection.contains(value)) {
        return false;
    }
    return collection.add(value);
}

From source file:Main.java

/**
 * Checks whether the given source collection contains any of the items in the find {@link Collection}.
 * //from ww w .  j  a v a 2s  . c o m
 * @param source
 * @param find
 * @return
 */
public static <T> boolean containsAny(Collection<T> source, Collection<T> find) {
    for (T tofind : find) {
        if (source.contains(tofind)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static <T> boolean isNullOrContainsNot(final Collection<?> collection, final T item) {
    return ((collection == null) && (!collection.contains(item)));
}

From source file:Main.java

public static <T> void uniqAdd(Collection<T> collection, T elements) {
    if (collection == null)
        return;//from w  ww .  j a  v a 2s  . c om
    if (!collection.contains(elements))
        collection.add(elements);
}

From source file:Main.java

public static <K> Set<K> intersect(Collection<K> a, Collection<K> b) {
    Set<K> ret = new HashSet<K>();
    for (K v : a) {
        if (b.contains(v))
            ret.add(v);//  w  w  w .j  a v  a  2s.  co m
    }
    return ret;
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static <T> void addAllOfExclude(Container container, Class<T> clazz, List<T> all,
        Collection<? extends Component> exclude) {
    if (exclude.contains(container)) {
        return;//from   w w  w.j  a  v  a2 s  . c o m
    }
    if (container.getClass().equals(clazz)) {
        all.add((T) container);
    }
    int count = container.getComponentCount();
    for (int i = 0; i < count; i++) {
        Component component = container.getComponent(i);
        if (exclude.contains(component)) {
            continue;
        }
        if (component instanceof Container) {
            addAllOfExclude((Container) component, clazz, all, exclude); // Recursive
        } else if (component.getClass().equals(clazz)) {
            all.add((T) component);
        }
    }
}

From source file:edu.wisc.web.util.JstlUtil.java

public static boolean contains(Collection<?> coll, Object o) {
    return coll.contains(o);
}

From source file:Main.java

/**
 * if any item in toCheck is present in collection
 *
 * @param collection//from  ww w . j a v a 2s .  com
 * @param toCheck
 */
public static <T> boolean containsAny(Collection<T> collection, Collection<T> toCheck) {
    for (T c : toCheck) {
        if (collection.contains(c))
            return true;
    }
    return false;

}

From source file:Main.java

public static <T> boolean containsNone(Collection<T> outer, Iterable<T> inner) {
    for (T item : inner) {
        if (outer.contains(item)) {
            return false;
        }//w w  w. jav a2 s . c o m
    }
    return true;
}

From source file:Main.java

public static <T> boolean containsAny(Collection<T> outer, Iterable<T> inner) {
    for (T item : inner) {
        if (outer.contains(item)) {
            return true;
        }/* w  w  w .j  av  a2  s .  c  o m*/
    }
    return false;
}