Example usage for com.google.common.collect Sets intersection

List of usage examples for com.google.common.collect Sets intersection

Introduction

In this page you can find the example usage for com.google.common.collect Sets intersection.

Prototype

public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2) 

Source Link

Document

Returns an unmodifiable view of the intersection of two sets.

Usage

From source file:com.google.javascript.jscomp.lint.CheckNoMutatedEs6Exports.java

private void checkNoMutations() {
    Set<String> mutatedExports = Sets.intersection(mutatedNames.keySet(), exportedLocalNames);

    for (String mutatedExport : mutatedExports) {
        for (Node mutation : mutatedNames.get(mutatedExport)) {
            compiler.report(JSError.make(mutation, MUTATED_EXPORT, mutatedExport));
        }// w ww.  j av  a2 s. c o m
    }

    mutatedNames.clear();
    exportedLocalNames.clear();
}

From source file:com.technophobia.substeps.runner.ExecutionContext.java

public static Map<String, Object> flatten() {

    // return a single Map with the items in the narrowest scope remaining

    ExecutionContext ec = executionContextThreadLocal.get();

    Map newMaster = new HashMap<String, Object>();
    for (Scope scope : Scope.values()) {

        Map<String, Object> scopedMap = ec.scopedData.get(scope);
        if (scopedMap != null) {
            Sets.SetView intersection = Sets.intersection(newMaster.keySet(), scopedMap.keySet());

            if (!intersection.isEmpty()) {
                intersection.stream().forEach(s -> log.warn(
                        "existing key value " + s + " is being overwritten flattening the ExecutionContext"));
            }/*  ww  w . jav a2 s.c  o m*/

            newMaster.putAll(scopedMap);
        }
    }
    return newMaster;
}

From source file:org.dllearner.algorithms.schema.EntityDependencyMatrix.java

public static void getEntityDependencyMatrix(OWLOntology ontology) {
    OWLReasoner reasoner = new StructuralReasonerFactory().createNonBufferingReasoner(ontology);

    // how often are individuals of class A related to individuals of class B
    Set<OWLClass> classes = ontology.getClassesInSignature(Imports.INCLUDED);
    for (OWLClass clsA : classes) {
        for (OWLClass clsB : classes) {
            if (!clsA.equals(clsB)) {
                Set<OWLNamedIndividual> instancesA = reasoner.getInstances(clsA, false).getFlattened();
                Set<OWLNamedIndividual> instancesB = reasoner.getInstances(clsB, false).getFlattened();

                // S_1 = { o_i | A(a_i) and there is an p_i(a_i, o_i) in O }
                Set<OWLIndividual> objectsOfInstancesFromA = new HashSet<>();
                for (OWLNamedIndividual ind : instancesA) {
                    Set<OWLObjectPropertyAssertionAxiom> axioms = ontology
                            .getObjectPropertyAssertionAxioms(ind);
                    for (OWLObjectPropertyAssertionAxiom axiom : axioms) {
                        objectsOfInstancesFromA.add(axiom.getObject());
                    }/*from  w w  w .  j a  v  a2 s . co m*/
                }

                // S_2 = { o_i | B(b_i) and there is an p_i(b_i, o_i) in O }
                Set<OWLIndividual> objectsOfInstancesFromB = new HashSet<>();
                for (OWLNamedIndividual ind : instancesB) {
                    Set<OWLObjectPropertyAssertionAxiom> axioms = ontology
                            .getObjectPropertyAssertionAxioms(ind);
                    for (OWLObjectPropertyAssertionAxiom axiom : axioms) {
                        objectsOfInstancesFromB.add(axiom.getObject());
                    }
                }

                // A -> B
                SetView<OWLIndividual> aToB = Sets.intersection(objectsOfInstancesFromA, instancesB);
                // B -> A
                SetView<OWLIndividual> bToA = Sets.intersection(objectsOfInstancesFromB, instancesA);

            }
        }
    }
}

From source file:org.summer.dsl.xbase.typesystem.override.LazyOverrideCheckResult.java

public boolean hasProblems() {
    if (!isOverridingOrImplementing()) {
        return true;
    }/*from   w  ww  .  j  a  va2 s  . c  o m*/
    EnumSet<OverrideCheckDetails> details = getDetails();
    return !Sets.intersection(problemIfAnyOf, details).isEmpty();
}

From source file:com.streamsets.pipeline.stage.processor.fieldorder.FieldOrderProcessor.java

@Override
protected List<ConfigIssue> init() {
    List<ConfigIssue> issues = super.init();
    fields = ImmutableSet.copyOf(config.fields);
    discardFields = new ImmutableSet.Builder<String>().add("") // Root item is implicitly ignored
            .addAll(config.discardFields).build();

    if (config.missingFieldAction == MissingFieldAction.USE_DEFAULT) {
        defaultField = Field.create(config.dataType.getType(), config.defaultValue);
    }//from  ww w.j a va2s. co m

    // Validate that discard fields and order fields do not contain duplicate field paths
    Set<String> duplicates = Sets.intersection(ImmutableSet.copyOf(config.fields),
            ImmutableSet.copyOf(config.discardFields));
    if (!duplicates.isEmpty()) {
        issues.add(getContext().createConfigIssue("ORDER", "config.fields", Errors.FIELD_ORDER_003,
                StringUtils.join(duplicates, ",")));
    }

    return issues;
}

From source file:org.onosproject.store.resource.impl.GenericDiscreteResources.java

@Override
public boolean containsAny(Set<DiscreteResource> other) {
    return !Sets.intersection(this.values(), other).isEmpty();
}

From source file:org.caleydo.view.relationshipexplorer.ui.column.operation.AMappingUpdateOperation.java

@Override
public void execute(IEntityCollection collection) {
    if (!targetCollections.contains(collection))
        return;//w w w .j  av a  2 s .co  m
    Set<Object> elementIDs = null;
    if (sourceCollection == null || collection != sourceCollection) {
        if (multiItemSelectionOperation == ESetOperation.INTERSECTION) {
            // elementIDs = new HashSet<>();

            for (Object bcID : srcBroadcastIDs) {
                Set<Object> ids = collection.getElementIDsFromForeignIDs(Sets.newHashSet(bcID),
                        broadcastIDType);
                if (elementIDs != null) {
                    elementIDs = new HashSet<>(Sets.intersection(elementIDs, ids));
                } else {
                    elementIDs = ids;
                }

            }
        } else {
            elementIDs = collection.getElementIDsFromForeignIDs(srcBroadcastIDs, broadcastIDType);
        }
        if (elementIDs == null)
            elementIDs = new HashSet<>();
        execute(collection, elementIDs);
    }

}

From source file:org.apache.james.mailetcontainer.impl.matchers.And.java

private Set<MailAddress> computeIntersection(ImmutableList<Set<MailAddress>> individualMatchedResults) {
    if (individualMatchedResults.size() == 0) {
        return ImmutableSet.of();
    }/*from   w w  w  .  j  a v a 2 s  .c o m*/
    if (individualMatchedResults.size() == 1) {
        return individualMatchedResults.get(0);
    }
    return Sets.intersection(individualMatchedResults.get(0),
            computeIntersection(individualMatchedResults.subList(1, individualMatchedResults.size())));
}

From source file:org.eclipse.viatra.query.runtime.matchers.planning.helpers.FunctionalDependencyHelper.java

/***
 * Returns the dependency set over attributes in {@link targetAttributes} that are implied by a given source dependency set.
 * <p> Note: exponential in the size of the target attribute set.
 * <p> Note: minimality of the returned dependency set is currently not guaranteed.
 * @param originalDependencies all dependencies that are known to hold on a wider set of attributes
 * @param targetAttributes the set of attributes we are interested in
 * @since 1.5/* w w  w .j av a  2  s . com*/
 */
public static <A> Map<Set<A>, Set<A>> projectDependencies(Map<Set<A>, Set<A>> originalDependencies,
        Set<A> targetAttributes) {
    // only those attributes are considered as left-hand-side candidates that occur at least once in dependencies
    Set<A> leftCandidates = new HashSet<A>();
    for (Entry<Set<A>, Set<A>> dependency : originalDependencies.entrySet()) {
        if (!isTrivial(dependency.getKey(), dependency.getValue())) // only if non-trivial
            leftCandidates.addAll(Sets.intersection(dependency.getKey(), targetAttributes));
    }

    // Compute an initial list of nontrivial projected dependencies - it does not have to be minimal yet
    Map<Set<A>, Set<A>> initialDependencies = new HashMap<Set<A>, Set<A>>();
    for (Set<A> leftSet : Sets.powerSet(leftCandidates)) {
        Set<A> rightSet = Sets.intersection(closureOf(leftSet, originalDependencies), targetAttributes);
        if (!isTrivial(leftSet, rightSet)) {
            initialDependencies.put(leftSet, rightSet);
        }
    }
    // Don't forget to include constants!
    Set<A> constants = Sets.intersection(closureOf(Collections.<A>emptySet(), originalDependencies),
            targetAttributes);
    if (!constants.isEmpty()) {
        initialDependencies.put(Collections.<A>emptySet(), constants);
    }

    // Omit those dependencies where the LHS has superfluous attributes
    Map<Set<A>, Set<A>> solidDependencies = new HashMap<Set<A>, Set<A>>();
    for (Entry<Set<A>, Set<A>> dependency : initialDependencies.entrySet()) {
        Set<A> leftSet = dependency.getKey();
        Set<A> rightSet = dependency.getValue();
        boolean solid = true;
        for (A skipped : leftSet) { // what if we skip one attribute from the left set?
            Set<A> singleton = Collections.singleton(skipped);
            Set<A> candidate = Sets.difference(leftSet, singleton);
            Set<A> rightCandidate = initialDependencies.get(candidate);
            if (rightCandidate != null) {
                if (Sets.union(rightCandidate, singleton).containsAll(rightSet)) {
                    solid = false;
                    break;
                }
            }
        }
        if (solid) {
            solidDependencies.put(leftSet, rightSet);
        }
    }

    // TODO perform proper minimization, 
    // see e.g. page 45 in http://www.cs.ubc.ca/~hkhosrav/db/slides/03.design%20theory.pdf

    return Collections.unmodifiableMap(solidDependencies);
}

From source file:org.eclipse.xtext.xbase.typesystem.override.LazyOverrideCheckResult.java

@Override
public boolean hasProblems() {
    if (!isOverridingOrImplementing()) {
        return true;
    }/*  w  w  w  .j  a  va 2 s .co  m*/
    EnumSet<OverrideCheckDetails> details = getDetails();
    return !Sets.intersection(problemIfAnyOf, details).isEmpty();
}