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:edu.uci.ics.jung.algorithms.scoring.util.ScoringUtils.java

/**
 * Assigns a probability of 1/<code>roots.size()</code> to each of the elements of <code>roots</code>.
 * @param <V> the vertex type/*from   w w  w  .  jav a  2s  .  co  m*/
 * @param roots the vertices to be assigned nonzero prior probabilities
 * @return
 */
public static <V> Transformer<V, Double> getUniformRootPrior(Collection<V> roots) {
    final Collection<V> inner_roots = roots;
    Transformer<V, Double> distribution = new Transformer<V, Double>() {
        public Double transform(V input) {
            if (inner_roots.contains(input))
                return new Double(1.0 / inner_roots.size());
            else
                return 0.0;
        }
    };

    return distribution;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean allIn(Collection source, Collection target) {
    if (target == null || target.size() == 0) {
        return false;
    }//w w  w .j av a  2 s . c  o m

    for (Iterator it = source.iterator(); it.hasNext();) {
        Object object = it.next();
        if (!target.contains(object)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

private final static void extractAddedEntries(final Collection<String> oldCollection,
        final Collection<String> updatedCollection, final Collection<String> addedEntriesCollection) {
    for (final String entry : updatedCollection) {
        if (!oldCollection.contains(entry)) {
            addedEntriesCollection.add(entry);
        }/*www. ja  va2 s . c  o  m*/
    }
}

From source file:com.cloudera.oryx.common.OryxTest.java

private static <T> Collection<T> minus(Collection<? extends T> a, Collection<T> b) {
    return a.stream().filter(t -> !b.contains(t)).collect(Collectors.toList());
}

From source file:Main.java

public static boolean isOverlap(Collection<?> list1, Collection<?> list2) {
    if (list1 == list2) {
        return true;
    }//from w  w w.  j  a  va  2s  .  c o m

    if (list1 == null || list2 == null) {
        return false;
    }

    for (Object element : list1) {
        if (list2.contains(element)) {
            return true;
        }
    }

    return false;
}

From source file:com.xpn.xwiki.doc.merge.MergeUtils.java

/**
 * Merge a {@link Collection}./*from   w w w  . j a va 2s  .  co  m*/
 * 
 * @param <T> the type of the lists elements
 * @param previousList previous version of the collection
 * @param newList new version of the collection
 * @param currentList current version of the collection to modify
 * @param mergeResult the merge report
 */
public static <T> void mergeCollection(Collection<T> previousList, Collection<T> newList,
        Collection<T> currentList, MergeResult mergeResult) {
    for (T previousElement : previousList) {
        if (!newList.contains(previousElement)) {
            currentList.remove(previousElement);
        }
    }

    for (T newElement : newList) {
        if (!previousList.contains(newElement)) {
            currentList.add(newElement);
        }
    }
}

From source file:Main.java

public static <T> List<T> conjunction(Collection<T> c1, Collection<T> c2) {

    if (c1 == null || c2 == null) {

        return null;

    } else {//from  ww w.  j  a  va 2s  . c o  m

        List<T> result = new ArrayList<T>(c1.size());

        for (T o : c1) {

            if (c2.contains(o)) {

                result.add(o);
            }
        }
        return result;
    }
}

From source file:Main.java

/**
 * Return {@code true} if any element in '{@code candidates}' is
 * contained in '{@code source}'; otherwise returns {@code false}.
 * @param source the source Collection/*from  w w w . j ava2 s. com*/
 * @param candidates the candidates to search for
 * @return whether any of the candidates has been found
 */
public static boolean containsAny(Collection<?> source, Collection<?> candidates) {
    if (isEmpty(source) || isEmpty(candidates))
        return false;
    for (Object candidate : candidates) {
        if (source.contains(candidate))
            return true;
    }
    return false;
}

From source file:Main.java

public static boolean isTheSame(Collection a, Collection b) {
    int sizeA = a == null ? 0 : a.size();
    int sizeB = b == null ? 0 : b.size();
    if (sizeA == sizeB && sizeA != 0) {
        int matchCount = 0;
        for (Object obj : a) {
            if (b.contains(obj)) {
                matchCount++;//from ww  w .jav a2 s  . c o m
            }
        }
        return matchCount == b.size();
    } else {
        return sizeA == 0;
    }
}

From source file:edu.uci.ics.jung.algorithms.scoring.util.ScoringUtils.java

/**
 * Returns a Transformer that hub and authority values of 1/<code>roots.size()</code> to each 
 * element of <code>roots</code>.
 * @param <V> the vertex type/*w w w  .j  av a2  s. c o m*/
 * @param roots the vertices to be assigned nonzero scores
 * @return a Transformer that assigns uniform prior hub/authority probabilities to each root
 */
public static <V> Transformer<V, HITS.Scores> getHITSUniformRootPrior(Collection<V> roots) {
    final Collection<V> inner_roots = roots;
    Transformer<V, HITS.Scores> distribution = new Transformer<V, HITS.Scores>() {
        public HITS.Scores transform(V input) {
            if (inner_roots.contains(input))
                return new HITS.Scores(1.0 / inner_roots.size(), 1.0 / inner_roots.size());
            else
                return new HITS.Scores(0.0, 0.0);
        }
    };
    return distribution;
}