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:edu.isi.karma.modeling.research.PatternContainment.java

public boolean containedIn(Set<String> mappedNodes, Set<String> mappedLinks) {

    HashMap<String, List<Link>> mainLinks = new HashMap<String, List<Link>>();
    HashMap<String, List<Link>> newLinks = new HashMap<String, List<Link>>();

    for (Link e : mainGraph.edgeSet()) {
        String target = (e.getTarget() instanceof InternalNode) ? e.getTarget().getLabel().getUri() : "";
        String key = e.getSource().getLabel().getUri() + target + e.getLabel().getUri();
        List<Link> links = mainLinks.get(key);
        if (links == null) {
            links = new ArrayList<Link>();
            mainLinks.put(key, links);//from w  w  w. j  a  va  2 s  . c om
        }
        links.add(e);
    }

    for (Link e : newGraph.edgeSet()) {
        String target = (e.getTarget() instanceof InternalNode) ? e.getTarget().getLabel().getUri() : "";
        String key = e.getSource().getLabel().getUri() + target + e.getLabel().getUri();
        List<Link> links = newLinks.get(key);
        if (links == null) {
            links = new ArrayList<Link>();
            newLinks.put(key, links);
        }
        links.add(e);
    }

    Set<String> sharedLinks = Sets.intersection(mainLinks.keySet(), newLinks.keySet());
    for (String key : sharedLinks) {
        if (mainLinks.get(key).size() != newLinks.get(key).size())
            return false;
    }

    if (sharedLinks.size() == newLinks.keySet().size()) {
        for (String key : sharedLinks) {
            List<Link> links = mainLinks.get(key);
            for (Link l : links) {
                mappedNodes.add(l.getSource().getId());
                mappedNodes.add(l.getTarget().getId());
                mappedLinks.add(l.getId());
            }
        }
        return true;
    }

    return false;

}

From source file:com.google.errorprone.bugpatterns.threadsafety.AbstractLockMethodChecker.java

@Override
public Description matchMethod(MethodTree tree, final VisitorState state) {

    ImmutableList<String> lockExpressions = getLockExpressions(tree);
    if (lockExpressions.isEmpty()) {
        return Description.NO_MATCH;
    }//w  w  w .j  av a  2s . c  o  m

    Optional<ImmutableSet<GuardedByExpression>> expected = parseLockExpressions(lockExpressions, tree, state);
    if (!expected.isPresent()) {
        return buildDescription(tree).setMessage("Could not resolve lock expression.").build();
    }

    Set<GuardedByExpression> unwanted = getUnwanted(tree, state);
    SetView<GuardedByExpression> mishandled = Sets.intersection(expected.get(), unwanted);
    if (!mishandled.isEmpty()) {
        String message = buildMessage(formatLockString(mishandled));
        return buildDescription(tree).setMessage(message).build();
    }

    Set<GuardedByExpression> actual = getActual(tree, state);
    SetView<GuardedByExpression> unhandled = Sets.difference(expected.get(), actual);
    if (!unhandled.isEmpty()) {
        String message = buildMessage(formatLockString(unhandled));
        return buildDescription(tree).setMessage(message).build();
    }

    return Description.NO_MATCH;
}

From source file:com.cloudera.gertrude.space.ExperimentInfo.java

Map<String, ? extends FlagValueCalculator<Object>> getOverrides(Set<Integer> newExperimentIds) {
    Set<Integer> interactions = Sets.intersection(newExperimentIds, launchOverrides.keySet());
    if (interactions.isEmpty()) {
        return baseOverrides;
    } else {//from w w w  . jav a 2 s  .  co  m
        Map<String, FlagValueCalculatorImpl<Object>> ret = Maps.newHashMap(baseOverrides);
        for (Integer launchLayerExperimentId : interactions) {
            ret.putAll(launchOverrides.get(launchLayerExperimentId));
        }
        return ret;
    }
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.ConceptOverlappingCountAnswerScorer.java

public Map<String, Double> score(JCas jcas, Answer answer) {
    Set<CandidateAnswerOccurrence> caos = TypeUtil.getCandidateAnswerVariants(answer).stream()
            .map(TypeUtil::getCandidateAnswerOccurrences).flatMap(Collection::stream).collect(toSet());
    double[] qconceptOverlappingRatios = caos.stream().map(TypeUtil::annotationOffset).map(offset2concepts::get)
            .mapToDouble(concepts -> Scorer.safeDividedBy(Sets.intersection(concepts, qconcepts).size(),
                    concepts.size()))/*from   ww w.  j a v  a 2 s  . c o m*/
            .toArray();
    return Scorer.generateSummaryFeatures(qconceptOverlappingRatios, "concept-overlap", "avg", "pos-ratio",
            "any-one");
}

From source file:org.caleydo.view.relationshipexplorer.ui.collection.AEntityCollection.java

@Override
public void setHighlightItems(Set<Object> elementIDs) {
    this.highlightElementIDs = new HashSet<>(Sets.intersection(elementIDs, allElementIDs));
}

From source file:org.caleydo.view.histogram.v2.BarDistributionElement.java

@Override
protected void render(GLGraphics g, float w, float h) {
    final float factor = (vertical ? h : w) / data.size();
    float x = 0;//ww w. j av  a2  s  .c  o m
    final List<DistributionEntry> entries = data.getEntries();
    final int size = entries.size();
    for (int i = 0; i < size; ++i) {
        DistributionEntry bucket = entries.get(i);
        float v = bucket.getValue() * factor;
        g.color(toHighlight(bucket.getColor(), i));
        g.pushName(bucketPickingIds.get(i));
        if (vertical)
            g.fillRect(0, x, w, v);
        else
            g.fillRect(x, 0, v, h);
        g.popName();
        x += v;
    }
    if (!g.isPickingPass()) {
        if (RenderStyle.COLOR_BORDER != null) {
            g.color(RenderStyle.COLOR_BORDER);
            x = 0;
            for (int i = 0; i < size; ++i) {
                DistributionEntry bucket = entries.get(i);
                float v = bucket.getValue() * factor;
                if (vertical)
                    g.drawRect(0, x, w, v);
                else
                    g.drawRect(x, 0, v, h);
                x += v;
            }
        }
        g.lineWidth(2);
        for (SelectionType selectionType : SELECTIONTYPES) {
            Set<Integer> elements = data.getElements(selectionType);
            if (elements.isEmpty())
                continue;
            g.color(toHighlightColor(selectionType));
            x = 0;
            for (int i = 0; i < size; ++i) {
                DistributionEntry bucket = entries.get(i);
                float v = Sets.intersection(elements, bucket.getIDs()).size() * factor;
                if (vertical)
                    g.fillRect(0, x, w, v);
                else
                    g.fillRect(x, 0, v, h);
                v = bucket.getValue() * factor;
                x += v;
            }
        }
    }
}

From source file:eu.lp0.cursus.xml.data.entity.DataXMLSeries.java

public DataXMLSeries(Series series, SortedSet<Event> events, SortedSet<Race> races, Set<Pilot> pilots) {
    super(series);

    name = series.getName();//from  w  ww  .  j  a  v  a  2  s  .  c  om
    description = series.getDescription();

    Set<Class> classes_ = new HashSet<Class>();
    for (Pilot pilot : pilots) {
        classes_.addAll(pilot.getClasses());
    }

    classes = new ArrayList<DataXMLClass>(classes_.size());
    for (Class class_ : classes_) {
        classes.add(new DataXMLClass(class_));
    }
    Collections.sort(classes);

    this.pilots = new ArrayList<DataXMLPilot>(pilots.size());
    for (Pilot pilot : pilots) {
        this.pilots.add(new DataXMLPilot(pilot));
    }
    Collections.sort(this.pilots);

    this.events = new ArrayList<DataXMLEvent>(events.size());
    for (Event event : events) {
        this.events.add(
                new DataXMLEvent(event, Sets.intersection(new TreeSet<Race>(event.getRaces()), races), pilots));
    }
}

From source file:ai.grakn.graql.internal.reasoner.query.QueryAnswerStream.java

private static Answer joinOperator(Answer m1, Answer m2) {
    boolean isCompatible = true;
    Set<Var> joinVars = Sets.intersection(m1.keySet(), m2.keySet());
    Iterator<Var> it = joinVars.iterator();
    while (it.hasNext() && isCompatible) {
        Var var = it.next();
        isCompatible = m1.get(var).equals(m2.get(var));
    }/*from  ww  w  . j av a  2  s.  c om*/
    return isCompatible ? m1.merge(m2) : new QueryAnswer();
}

From source file:edu.isi.karma.reserach.alignment.PatternContainment.java

public boolean containedIn(Set<String> mappedNodes, Set<String> mappedLinks) {

    HashMap<String, List<LabeledLink>> mainLinks = new HashMap<String, List<LabeledLink>>();
    HashMap<String, List<LabeledLink>> newLinks = new HashMap<String, List<LabeledLink>>();

    for (LabeledLink e : mainGraph.edgeSet()) {
        String target = (e.getTarget() instanceof InternalNode) ? e.getTarget().getLabel().getUri() : "";
        String key = e.getSource().getLabel().getUri() + target + e.getLabel().getUri();
        List<LabeledLink> links = mainLinks.get(key);
        if (links == null) {
            links = new ArrayList<LabeledLink>();
            mainLinks.put(key, links);/*from   w ww  .j  av a2  s.co m*/
        }
        links.add(e);
    }

    for (LabeledLink e : newGraph.edgeSet()) {
        String target = (e.getTarget() instanceof InternalNode) ? e.getTarget().getLabel().getUri() : "";
        String key = e.getSource().getLabel().getUri() + target + e.getLabel().getUri();
        List<LabeledLink> links = newLinks.get(key);
        if (links == null) {
            links = new ArrayList<LabeledLink>();
            newLinks.put(key, links);
        }
        links.add(e);
    }

    Set<String> sharedLinks = Sets.intersection(mainLinks.keySet(), newLinks.keySet());
    for (String key : sharedLinks) {
        if (mainLinks.get(key).size() != newLinks.get(key).size())
            return false;
    }

    if (sharedLinks.size() == newLinks.keySet().size()) {
        for (String key : sharedLinks) {
            List<LabeledLink> links = mainLinks.get(key);
            for (LabeledLink l : links) {
                mappedNodes.add(l.getSource().getId());
                mappedNodes.add(l.getTarget().getId());
                mappedLinks.add(l.getId());
            }
        }
        return true;
    }

    return false;

}

From source file:org.magnum.mcc.building.guessers.LocationGuesserImpl.java

@Override
public void narrowLocationsByType(LocationType t) {
    rootType_ = floorplan_.typeByName(t.getName());
    Set<FloorplanLocation> newpossible = floorplan_.getLocationsOfType(t);
    possibleLocations_ = Sets.intersection(new HashSet<FloorplanLocation>(possibleLocations_), newpossible);
}