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

public static Collection or(Collection collection1, Collection collection2) {
    Vector completeList = new Vector(collection1);

    if (collection2 == null)
        return collection1;
    Iterator i = collection2.iterator();
    // Do the long way tro make sure no dups
    while (i.hasNext()) {
        Object addlItem = i.next();
        if (collection1.contains(addlItem) == false) {
            completeList.addElement(addlItem);
        }/* ww  w.  j ava  2 s  .  c o m*/
    }
    return completeList;
}

From source file:Main.java

public static boolean areEqual(Collection<?> collection1, Collection<?> collection2) {
    if (collection1 == null && collection2 == null)
        return true;
    if (collection1 == null || collection2 == null)
        return false;
    if (collection1.size() != collection2.size())
        return false;
    for (Object member : collection1) {
        if (!collection2.contains(member))
            return false;
    }//  w  w w .ja v a  2s.  com
    return true;
}

From source file:Main.java

public static <T> boolean doCompare(Collection<T> c1, Collection<T> c2) {

    if (c1 == null && c2 == null) {
        return true;
    }/*from  w w  w  . j  av  a 2s.c  o m*/

    if (c1 == null || c2 == null) {
        return false;
    }

    if (c1.size() != c2.size()) {
        return false;
    }

    Iterator<T> it = c1.iterator();
    while (it.hasNext()) {
        if (!c2.contains(it.next())) {
            return false;
        }
    }

    return true;
}

From source file:com.facebook.TestUtils.java

public static void assertAtLeastExpectedPermissions(final Collection<String> expected,
        final Collection<String> actual) {
    if (expected != null) {
        for (String p : expected) {
            Assert.assertTrue(actual.contains(p));
        }//from ww  w  . j ava  2  s.com
    }
}

From source file:Main.java

public static Object findFirstMatch(Collection source, Collection candidates) {
    if (!isEmpty(source) && !isEmpty(candidates)) {
        Iterator it = candidates.iterator();

        Object candidate;/* ww w.ja  v a  2 s .co m*/
        do {
            if (!it.hasNext()) {
                return null;
            }

            candidate = it.next();
        } while (!source.contains(candidate));

        return candidate;
    } else {
        return null;
    }
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Collection in(Collection source, Collection target) {
    if (source == null || source.size() == 0) {
        return null;
    }//from www  .  j  a va  2  s . c  o  m
    if (target == null || target.size() == 0) {
        return null;
    }
    Collection result = new ArrayList();
    for (Iterator it = source.iterator(); it.hasNext();) {
        Object candidate = it.next();
        if (target.contains(candidate)) {
            result.add(candidate);
        }
    }
    return result;
}

From source file:grails.plugin.searchable.internal.SearchableUtils.java

/**
 * Returns the class type of the searchable property
 * @param property//from  w w  w  .  ja v  a 2s .  c om
 * @param searchableGrailsDomainClasses
 * @return
 */
public static Class getSearchablePropertyAssociatedClass(GrailsDomainClassProperty property,
        Collection searchableGrailsDomainClasses) {
    Assert.notNull(property, "property cannot be null");
    Assert.notNull(property.getDomainClass(), "grailsDomainClass cannot be null");
    Class propertyType = property.getType();
    Collection classes = getClasses(searchableGrailsDomainClasses);
    if (classes.contains(propertyType)) {
        return propertyType;
    }
    propertyType = property.getDomainClass().getRelatedClassType(property.getName());
    if (propertyType != null && classes.contains(propertyType)) {
        return propertyType;
    }

    // Handle generic collection types, e.g. Set<MyDomainClass>, for transient properties.
    propertyType = property.getType();

    if (Collection.class.isAssignableFrom(propertyType)) {
        Class elementClass = getElementClass(property);
        if (classes.contains(elementClass))
            return elementClass;
    }
    return null;
}

From source file:Main.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static Collection substract(Collection source, Collection target) {
    if (source == null || source.size() == 0) {
        return null;
    }//from w ww .j a va 2s  . co m
    if (target == null || target.size() == 0) {
        return source;
    }
    Collection result = new ArrayList();
    for (Iterator it = source.iterator(); it.hasNext();) {
        Object candidate = it.next();
        if (!target.contains(candidate)) {
            result.add(candidate);
        }
    }
    return result;
}

From source file:Main.java

/**
 * Returns true if there is any element that is common to both collections.
 *//*  w  w w . ja  v a2 s .c o m*/
public static boolean containsAny(Collection c1, Collection c2) {
    // A better implementation here would be to use sets
    Collection smallCollection;
    Collection largeCollection;
    if (c1.size() < c2.size()) {
        smallCollection = c1;
        largeCollection = c2;
    } else {
        smallCollection = c2;
        largeCollection = c1;
    }
    boolean intersect = false;
    Iterator i = smallCollection.iterator();
    while (i.hasNext()) {
        if (largeCollection.contains(i.next())) {
            intersect = true;
            break;
        }
    }
    return intersect;
}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditingTestsUtils.java

static void checkDirectoryContainsFiles(File directory, File... expectedFiles) {
    Collection existingFiles = FileUtils.listFiles(directory, null, false);
    Assert.assertEquals(existingFiles.size(), expectedFiles.length);
    for (File expectedFile : expectedFiles) {
        Assert.assertTrue(existingFiles.contains(expectedFile));
    }/* w  w w  . j  ava2  s  .  c  om*/
}