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:com.threecrickets.sincerity.util.IoUtil.java

/**
 * Recursively gathers all files with filenames ending with a postfix.
 * //from w w w . j a v  a 2  s  .  c om
 * @param file
 *        The file or directory
 * @param postfix
 *        The required postfix
 * @param files
 *        The collection to which we will add files
 */
public static void listRecursiveEndsWith(File file, String postfix, Collection<File> files) {
    if (file.isDirectory())
        for (File child : file.listFiles())
            listRecursiveEndsWith(child, postfix, files);
    else if (file.getName().endsWith(postfix))
        if (!files.contains(file))
            files.add(file);
}

From source file:Main.java

public static <T, K> T copyTree(T node, Function<T, K> keyMapper, Function<T, Collection<T>> childMapper,
        Function<T, T> cloneMapper, Collection<K> toCopy) {
    if (toCopy == null)
        return null;

    T copy = null;/*from w  w w  . j  a  v a  2  s .  co  m*/

    Collection<T> children = childMapper.apply(node);
    if (children != null && children.size() > 0) {
        for (T child : children) {
            T childCopy = copyTree(child, keyMapper, childMapper, cloneMapper, toCopy);
            if (childCopy != null) {
                if (copy == null)
                    copy = cloneMapper.apply(node);
                childMapper.apply(copy).add(childCopy);
            }
        }
    }

    if (copy == null && toCopy.contains(keyMapper.apply(node)))
        copy = cloneMapper.apply(node);

    return copy;
}

From source file:com.cburch.logisim.gui.main.SelectionAttributes.java

private static boolean haveSameElements(Collection<Component> a, Collection<Component> b) {
    if (a == null) {
        return b == null ? true : b.size() == 0;
    } else if (b == null) {
        return a.size() == 0;
    } else if (a.size() != b.size()) {
        return false;
    } else {//  w ww. ja  va 2s  . c  om
        for (Component item : a) {
            if (!b.contains(item))
                return false;
        }
        return true;
    }
}

From source file:net.sourceforge.fenixedu.domain.organizationalStructure.ExternalContract.java

public static List<ExternalContract> readByIDs(Collection<String> accountabilityIDs) {
    List<ExternalContract> externalPersons = new ArrayList<ExternalContract>();
    if (accountabilityIDs == null || accountabilityIDs.isEmpty()) {
        return externalPersons;
    }//from  w  w  w . j  a v a2s.  c  o  m
    for (Accountability accountability : Bennu.getInstance().getAccountabilitysSet()) {
        if (accountability instanceof ExternalContract) {
            ExternalContract externalPerson = (ExternalContract) accountability;
            if (accountabilityIDs.contains(externalPerson.getExternalId())) {
                externalPersons.add(externalPerson);
            }
        }
    }
    return externalPersons;
}

From source file:Main.java

/**
 * Method checks if the given collections contain the same content. Please
 * note that the method only check if each item of one collection is
 * contained at least one times in the other collection. Method does not
 * check if the number of containments of each element are equal. For
 * example this means that { A , B , B } and { A , A , B } are contained
 * equal content.//from   w w  w  .  j  a v a 2 s . c  o  m
 * 
 * @param collectionA
 *            the first collection
 * @param collectionB
 *            the other collection
 * @return <code>true</code> if the content are equal, <code>false</code>
 *         otherwise.
 */
public static boolean isContentEqual(final Collection<?> collectionA, final Collection<?> collectionB) {
    /*
     * check if at least one parameter are null
     */
    if (collectionA == null || collectionB == null) {
        throw new IllegalArgumentException("parameters can not be null.");
    }

    /*
     * check if both collection have the same size
     */
    if (collectionA.size() != collectionB.size()) {
        return false;
    }

    /*
     * check if each item of collection A contained in collection B
     */
    for (Object obj : collectionA) {
        if (!collectionB.contains(obj)) {
            return false;
        }
    }

    /*
     * check if each item of collection B contained in collection A
     */
    for (Object obj : collectionB) {
        if (!collectionA.contains(obj)) {
            return false;
        }
    }

    return true;
}

From source file:Main.java

/**
 * Assesses all the possible containment relations between collections A and B with one call.<br>
 * Returns an int with bits set, according to a "Venn Diagram" view of A vs B.<br>
 * NOT_A_SUPERSET_B: a - b != {}<br>
 * NOT_A_DISJOINT_B: a * b != {}  // * is intersects<br>
 * NOT_A_SUBSET_B: b - a != {}<br>
 * Thus the bits can be used to get the following relations:<br>
 * for A_SUPERSET_B, use (x & CollectionUtilities.NOT_A_SUPERSET_B) == 0<br>
 * for A_SUBSET_B, use (x & CollectionUtilities.NOT_A_SUBSET_B) == 0<br>
 * for A_EQUALS_B, use (x & CollectionUtilities.NOT_A_EQUALS_B) == 0<br>
 * for A_DISJOINT_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) == 0<br>
 * for A_OVERLAPS_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) != 0<br>
 *///  w w  w .j a va  2s  .c o  m
public static int getContainmentRelation(Collection a, Collection b) {
    if (a.size() == 0) {
        return (b.size() == 0) ? ALL_EMPTY : NOT_A_SUPERSET_B;
    } else if (b.size() == 0) {
        return NOT_A_SUBSET_B;
    }
    int result = 0;
    // WARNING: one might think that the following can be short-circuited, by looking at
    // the sizes of a and b. However, this would fail in general, where a different comparator is being
    // used in the two collections. Unfortunately, there is no failsafe way to test for that.
    for (Iterator it = a.iterator(); result != 6 && it.hasNext();) {
        result |= (b.contains(it.next())) ? NOT_A_DISJOINT_B : NOT_A_SUBSET_B;
    }
    for (Iterator it = b.iterator(); (result & 3) != 3 && it.hasNext();) {
        result |= (a.contains(it.next())) ? NOT_A_DISJOINT_B : NOT_A_SUPERSET_B;
    }
    return result;
}

From source file:eu.ggnet.dwoss.report.assist.ReportUtil.java

/**
 * Returns all Lines of the Report which represent Positions of CreditMemos and Annulation Invoices but the associated Invoices have been reported before.
 * This consists of:/*from  w  ww .  j  a v a2 s  .  c  om*/
 * <ul>
 * <li>Position of Type UNIT in DocumentType CREDIT_MEMO/ANNULATIION_INVOICE and a Referencing Invoice is not in same report.</li>
 * <li>Position of Type UNIT_ANNEX in DocumentType CREDIT_MEMO/ANNULATIION_INVOICE and a Referencing Invoice is not in same report and no UNIT also in this
 * report</li>
 * </ul>
 * <p>
 * It's not allowed to have a null value in the collection.
 * <p>
 * @param lines
 * @return all Lines of the Report which represent Positions of CreditMemos and Annulation Invoices but the associated Invoices have been reported before.
 */
public static NavigableSet<ReportLine> filterRepayed(Collection<ReportLine> lines) {
    NavigableSet<ReportLine> result = new TreeSet<>();
    for (ReportLine line : lines) {
        if (line.isFullRepayment()) {
            ReportLine invoiceRef = line.getSingleReference(DocumentType.INVOICE);
            if (invoiceRef == null)
                /*  No Invoice exists, probably before 2014 */ result.add(line);
            else if (!lines.contains(invoiceRef))
                result.add(line);
        }
        if (line.isPartialRepayment() && !line.isFullRepayedIn(lines)) {
            ReportLine invoiceRef = line.getSingleReference(INVOICE);
            if (invoiceRef == null)
                /*  No Invoice exists, probably before 2014 */ result.add(line);
            else if (!lines.contains(invoiceRef))
                result.add(line);
        }
    }
    return result;
}

From source file:javadepchecker.Main.java

private static boolean depNeeded(String pkg, Collection<String> deps) throws IOException {
    Collection<String> jars = getPackageJars(pkg);
    // We have a virtual with VM provider here
    if (jars.size() == 0)
        return true;
    for (String jarName : jars) {
        JarFile jar = new JarFile(jarName);
        for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
            String name = e.nextElement().getName();
            if (deps.contains(name)) {
                return true;
            }//from  w  ww. ja  va 2s .co  m
        }
    }
    return false;
}

From source file:edu.ksu.cis.indus.tools.slicer.SlicerToolHelper.java

/**
 * Optimizes the slice calculated by the given tool for space. This method should be called after residualization.
 * /*from  ww  w. j  a v  a2 s .c  om*/
 * @param tool in which the slice should be optimized.
 * @param classesToRetain is the collection of FQN of classes that need to be retained in the slice.
 * @return the unspecified classes that were retained.
 * @pre tool != null and classesToRetain != null
 * @post result != null
 */
public static Collection<SootClass> optimizeForSpaceAfterResidualization(final SlicerTool<?> tool,
        final Collection<String> classesToRetain) {
    final Collection<SootClass> _classesToErase = new HashSet<SootClass>();
    final Collection<SootClass> _classes = tool.getSystem().getClasses();
    final Iterator<SootClass> _i = _classes.iterator();
    final int _iEnd = _classes.size();

    for (int _iIndex = 0; _iIndex < _iEnd; _iIndex++) {
        final SootClass _sc = _i.next();

        if (_sc.getMethods().size() == 0 && _sc.getFields().size() == 0
                && !classesToRetain.contains(_sc.getName())) {
            _classesToErase.add(_sc);
        }
    }

    final Collection<SootClass> _c = Util.eraseClassesFrom(_classesToErase, tool.getSystem());
    _classesToErase.removeAll(_c);
    return _c;
}

From source file:com.vaadin.sass.testcases.scss.W3ConformanceTests.java

protected static Collection<URI> scrapeIndexForTests(String url, String regexp, int maxTests,
        Collection<URI> excludeUrls) throws Exception {

    URI baseUrl = new URI(url);
    Document doc = Jsoup.connect(url).timeout(10000).get();
    Elements elems = doc.select(String.format("a[href~=%s]", regexp));
    LinkedHashSet<URI> tests = new LinkedHashSet<URI>();
    for (Element e : elems) {
        URI testUrl = new URI(e.attr("href"));
        if (!testUrl.isAbsolute()) {
            testUrl = baseUrl.resolve(testUrl);
        }/* ww  w .  j  a va 2 s .  co  m*/
        if (tests.size() < maxTests) {
            if (!excludeUrls.contains(testUrl)) {
                tests.add(testUrl);
            }
        } else {
            break;
        }
    }

    return tests;
}