Example usage for java.util HashSet retainAll

List of usage examples for java.util HashSet retainAll

Introduction

In this page you can find the example usage for java.util HashSet retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this set that are contained in the specified collection (optional operation).

Usage

From source file:ProducerAndConsumerTool.java

public static void main(String[] args) {

    ConsumerTool consumerTool = new ConsumerTool();
    String[] unknown = CommandLineSupport.setOptions(consumerTool, args);
    HashSet<String> set1 = new HashSet<String>(Arrays.asList(unknown));

    ProducerTool producerTool = new ProducerTool();
    unknown = CommandLineSupport.setOptions(producerTool, args);
    HashSet<String> set2 = new HashSet<String>(Arrays.asList(unknown));

    set1.retainAll(set2);
    if (set1.size() > 0) {
        System.out.println("Unknown options: " + set1);
        System.exit(-1);/*w  w  w .  ja  v a2s . c  o  m*/
    }

    consumerTool.run();
    producerTool.run();

}

From source file:ProducerAndConsumerTool.java

public static void main(String[] args) {

    ConsumerTool consumerTool = new ConsumerTool();
    String[] unknown = CommandLineSupport.setOptions(consumerTool, args);
    HashSet<String> set1 = new HashSet<String>(Arrays.asList(unknown));

    HashSet<String> set4 = new HashSet<String>(5);

    ProducerTool producerTool = new ProducerTool();
    unknown = CommandLineSupport.setOptions(producerTool, args);
    HashSet<String> set2 = new HashSet<String>(Arrays.asList(unknown));

    set1.retainAll(set2);
    if (set1.size() > 0) {
        System.out.println("Unknown options: " + set1);
        System.exit(-1);/*from  w  w w  .  j  a  v a 2s. c  o m*/
    }

    /* consumerTool.run(); */

    producerTool.run();

}

From source file:Main.java

public static <T> List<T> conjunctCollections(final Collection<T> list1, final Collection<T> list2) {
    final HashSet<T> s1 = new HashSet<T>(list1);
    s1.retainAll(list2);
    return new ArrayList<T>(s1);
}

From source file:Main.java

/**
 * Returns the intersection of two sets without modifying the original sets.<p>
 * /*from  w ww . jav a  2s.c o m*/
 * @param <A> the type of objects contained in the sets
 * 
 * @param first the first set
 * @param second the second set
 * 
 * @return the intersection of both sets
 */
public static <A> Set<A> intersection(Set<A> first, Set<A> second) {

    HashSet<A> result = new HashSet<A>(first);
    result.retainAll(second);
    return result;
}

From source file:uk.org.todome.Util.java

public static <E> HashSet<E> intersection(HashSet<E> x, HashSet<E> y) {
    HashSet<E> t = new HashSet<E>(x);
    t.retainAll(y);
    return t;/* w ww.ja  v  a2  s . co  m*/
}

From source file:Main.java

/**
 * Return a set containing the intersection of all provided collections. We
 * use a {@link HashSet}, i.e. the elements should support hashing.
 * //from w  w w.j  a v  a 2  s.c om
 * We use two separate arguments to ensure on the interface level that at
 * least one collection is provided. This is transparent for the caller.
 */
public static <T> HashSet<T> intersectionSet(Collection<T> collection1,
        @SuppressWarnings("unchecked") Collection<T>... furtherCollections) {
    HashSet<T> result = new HashSet<T>(collection1);
    for (Collection<T> collection : furtherCollections) {
        if (collection instanceof Set) {
            result.retainAll(collection);
        } else {
            // if the collection is not already a set, it will be
            // significantly faster to first build a set, to speed up the
            // containment query in the following call.
            result.retainAll(new HashSet<T>(collection));
        }
    }
    return result;
}

From source file:edu.illinois.cs.cogcomp.question_typer.QuestionTyperFeatureExtractorsUtils.java

public static List<String> getWordGroupFeatures(TextAnnotation s) {
    List<Constituent> lemma = s.getView(ViewNames.LEMMA).getConstituents();
    Set<String> lemmaLabels = new HashSet<>();
    for (Constituent c : lemma)
        lemmaLabels.add(c.getLabel());/*from  w ww .  j a v a 2 s  .com*/

    List<String> overlapLabels = new ArrayList<>();
    for (Object label : list.keySet()) {
        HashSet set = (HashSet) list.get(label);
        HashSet lemmaLabelsClone = new HashSet(lemmaLabels);
        lemmaLabelsClone.retainAll(set);
        if (lemmaLabelsClone.size() > 0)
            overlapLabels.add((String) label);
    }
    return overlapLabels;
}

From source file:coq.DebugUnivInconst.java

/**
 * //from  w  w w.  j  a  v a2  s.c o  m
 * @param s1
 * @param s2
 * @return 
 */
static boolean nonDisjoint(HashSet<String> highlight, Set<String> scc) {
    if (highlight.isEmpty())
        return true;

    HashSet<String> highCopy = new HashSet<String>(highlight);
    highCopy.retainAll(scc);
    return (highCopy.size() > 0);
}

From source file:org.jamocha.dn.memory.javaimpl.MemoryHandlerMain.java

public static org.jamocha.dn.memory.MemoryHandlerMainAndCounterColumnMatcher newMemoryHandlerMain(
        final PathNodeFilterSet filterSet, final Map<Edge, Set<Path>> edgesAndPaths) {
    final ArrayList<Template> template = new ArrayList<>();
    final ArrayList<FactAddress> addresses = new ArrayList<>();
    final HashMap<FactAddress, FactAddress> newAddressesCache = new HashMap<>();
    if (!edgesAndPaths.isEmpty()) {
        final Edge[] incomingEdges = edgesAndPaths.entrySet().iterator().next().getKey().getTargetNode()
                .getIncomingEdges();// w ww  .  j a  v a 2  s .c o  m
        for (final Edge edge : incomingEdges) {
            final MemoryHandlerMain memoryHandlerMain = (MemoryHandlerMain) edge.getSourceNode().getMemory();
            for (final Template t : memoryHandlerMain.getTemplate()) {
                template.add(t);
            }
            final HashMap<FactAddress, FactAddress> addressMap = new HashMap<>();
            for (final FactAddress oldFactAddress : memoryHandlerMain.addresses) {
                final FactAddress newFactAddress = new FactAddress(addresses.size());
                addressMap.put(oldFactAddress, newFactAddress);
                newAddressesCache.put(oldFactAddress, newFactAddress);
                addresses.add(newFactAddress);
            }
            edge.setAddressMap(addressMap);
        }
    }
    final Template[] templArray = toArray(template, Template[]::new);
    final FactAddress[] addrArray = toArray(addresses, FactAddress[]::new);

    final PathFilterToCounterColumn pathFilterToCounterColumn = new PathFilterToCounterColumn();

    if (filterSet.getPositiveExistentialPaths().isEmpty()
            && filterSet.getNegativeExistentialPaths().isEmpty()) {
        return new MemoryHandlerMainAndCounterColumnMatcher(new MemoryHandlerMain(templArray,
                Counter.newCounter(filterSet, pathFilterToCounterColumn), addrArray),
                pathFilterToCounterColumn);
    }
    final boolean[] existential = new boolean[templArray.length];
    // gather existential paths
    final HashSet<Path> existentialPaths = new HashSet<>();
    existentialPaths.addAll(filterSet.getPositiveExistentialPaths());
    existentialPaths.addAll(filterSet.getNegativeExistentialPaths());

    int index = 0;
    for (final PathFilter pathFilter : filterSet.getFilters()) {
        final HashSet<Path> paths = PathCollector.newHashSet().collect(pathFilter).getPaths();
        paths.retainAll(existentialPaths);
        if (0 == paths.size())
            continue;
        for (final Path path : paths) {
            existential[newAddressesCache.get(path.getFactAddressInCurrentlyLowestNode()).index] = true;
        }
        pathFilterToCounterColumn.putFilterElementToCounterColumn(pathFilter, new CounterColumn(index++));
    }
    return new MemoryHandlerMainAndCounterColumnMatcher(
            new MemoryHandlerMainWithExistentials(templArray,
                    Counter.newCounter(filterSet, pathFilterToCounterColumn), addrArray, existential),
            pathFilterToCounterColumn);
}

From source file:edu.cens.loci.classes.LociWifiFingerprint.java

public static boolean hasCommonBeacons(LociWifiFingerprint sig1, LociWifiFingerprint sig2) {

    HashSet<String> bssid1 = sig1.getBssids();
    HashSet<String> bssid2 = sig2.getBssids();

    HashSet<String> intersection = new HashSet<String>(bssid1);
    intersection.retainAll(bssid2);

    if (intersection.isEmpty())
        return false;
    else/*from  ww  w.ja v  a 2 s .  co m*/
        return true;
}