Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:Main.java

public static <T> boolean intersectionNotEmpty(Set<T> checkCollection, Collection<T> inputCollection) {
    for (T t : inputCollection) {
        if (checkCollection.contains(t)) {
            return true;
        }/* w w w .  ja  v  a  2s.c om*/
    }
    return false;
}

From source file:Main.java

public static Set<String> diffSet(Set<String> set1, Set<String> set2) {
    Set<String> result = new HashSet<String>();
    for (String s : set1) {
        if (!set2.contains(s)) {
            result.add(s);/*from  w  ww  .j av  a  2  s .c o m*/
        }
    }
    return result;
}

From source file:codes.thischwa.c5c.util.StringUtils.java

public static String getUniqueName(Set<String> existingNames, String name) {
    if (!existingNames.contains(name))
        return name;

    int count = 1;
    String ext = FilenameUtils.getExtension(name);
    String baseName = FilenameUtils.getBaseName(name);
    String tmpName;/*from ww  w . jav a2s  . co m*/
    do {
        tmpName = String.format("%s_%d", baseName, count);
        if (!_isNullOrEmpty(ext))
            tmpName = String.format("%s.%s", tmpName, ext);
        count++;
    } while (existingNames.contains(tmpName));
    return tmpName;
}

From source file:Main.java

public static <T> int intersectionSize(Set<T> checkCollection, Collection<T> inputCollection) {
    int count = 0;
    for (T t : inputCollection) {
        if (checkCollection.contains(t)) {
            count++;//from  w w  w . ja  v a 2  s.  co m
        }
    }
    return count;
}

From source file:Main.java

public static long contains(Set set) {
    long start, stop, result = 0;
    for (int i = 0; i < 100; i++) {
        start = System.nanoTime();
        set.contains(set.size() - i);
        stop = System.nanoTime();
        result += stop - start;/*from w w  w  .ja  v  a 2s . c  o  m*/
    }
    return result / 100;
}

From source file:com.u2apple.tool.util.StaticMapFileUtils.java

private static void sortModels(List<VID> vids, Set<String> changedVids) {
    vids.stream().filter((vid) -> (changedVids.contains(vid.getValue()))).forEach((vid) -> {
        sortModels(vid);/*w w  w.j  a  v  a  2  s.  co  m*/
    });
}

From source file:Main.java

/**
 * Returns a new <code>ArrayList</code> containing only those elements
 * in <code>origList</code> that are also present in <code>universe</code>.
 * This method is meant to be a faster alternative to <code>Collection.retainAll</code>
 * for <code>ArrayList</code> since removal operations take O(n) in <code>ArrayList</code>.
 * //ww  w .  jav a 2 s  . c o m
 * @param <E> type of element
 * @param origList original element <code>ArrayList</code>
 * @param universe <code>Set</code> of all valid elements
 * @return new <code>ArrayList</code> containing only those elements
 *         in <code>origList</code> that are also present in <code>universe</code>
 */
public static <E> ArrayList<E> retainAll(ArrayList<E> origList, Set<E> universe) {
    ArrayList<E> newElms = new ArrayList<E>(origList.size());
    for (E elm : origList) {
        if (universe.contains(elm))
            newElms.add(elm);
    }
    return newElms;
}

From source file:Main.java

public static <T> boolean overlaps(Set<T> a, Set<T> b) {
    if (a.size() > b.size()) {
        Set<T> t = a;//from  ww  w  .  j  av  a2  s.  c om
        a = b;
        b = t;
    }
    for (T elem : a) {
        if (b.contains(elem)) {
            return true;
        }
    }
    return false;
}

From source file:Comparing.java

public static <T> boolean haveEqualElements(Collection<T> a, Collection<T> b) {
    if (a.size() != b.size()) {
        return false;
    }// w w  w. java 2s .  c o  m

    Set<T> aSet = new HashSet<T>(a);
    for (T t : b) {
        if (!aSet.contains(t)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Bestimmt die Schnittmenge zweier Mengen.
 * /*from ww w  .ja v  a2s .  c  o m*/
 * @param <T>
 *            der Typ der Mengen.
 * @param set1
 *            die erste Menge.
 * @param set2
 *            die zweite Menge.
 * @return die Schnittmenge.
 */
public static <T> Set<T> intersection(final Set<T> set1, final Set<T> set2) {
    final Set<T> result = new HashSet<T>();

    for (final T e : set1) {
        if (set2.contains(e)) {
            result.add(e);
        }
    }

    return result;
}