List of usage examples for com.google.common.collect Sets intersection
public static <E> SetView<E> intersection(final Set<E> set1, final Set<?> set2)
From source file:org.caleydo.view.relationshipexplorer.ui.collection.idprovider.ElementIDProviders.java
/** * Gets a Provider that returns the intersection of all elements given by the specified providers. Note that this * intersection is cached once and will not be recalculated when calling {@link IElementIDProvider#getElementIDs()}. * * @param providers/*from w w w .j ava 2 s. c o m*/ * @return */ public static IElementIDProvider intersectionOf(IElementIDProvider... providers) { Set<Object> elementIDs = new HashSet<>(); for (int i = 0; i < providers.length; i++) { IElementIDProvider provider = providers[i]; if (i == 0) { elementIDs = provider.getElementIDs(); } else { elementIDs = Sets.intersection(elementIDs, provider.getElementIDs()); } } return new SimpleElementIDProvider(elementIDs); }
From source file:org.apache.james.jmap.utils.KeywordsCombiner.java
public Set<Keyword> intersect(Set<Keyword> set1, Set<Keyword> set2, List<Keyword> forKeywords) { return Sets.intersection(set1, set2).stream().filter(forKeywords::contains) .collect(Guavate.toImmutableSet()); }
From source file:tech.beshu.ror.acl.blocks.rules.impl.GroupsProviderAuthorizationAsyncRule.java
@Override protected CompletableFuture<Boolean> authorize(LoggedUser user) { if (!usersMatcher.match(user.getId())) { return CompletableFuture.completedFuture(false); }//from w ww. j a v a 2s . co m return client.fetchGroupsFor(user) // No wildcard matching for configured groups, but users can be declared as wildcards. .thenApply(fetchedGroupsForUser -> { // Exit early if resolved groups have nothing to do with the ones configured in this rule Sets.SetView<String> intersection = Sets.intersection(settings.getGroups(), Sets.newHashSet(fetchedGroupsForUser)); if (intersection.isEmpty()) { return false; } System.out.println("user: " + user.getId() + " has groups: " + fetchedGroupsForUser + ", intersected: " + intersection); // Exit early if the request has a current group that does not belong to this rule, or is not resolved for user if (user.getCurrentGroup().isPresent()) { String currGroup = user.getCurrentGroup().get(); System.out.println("found current group: " + currGroup); if (!intersection.contains(currGroup)) { System.out .println("current group in header does not match any available groups in rule " + currGroup); return false; } } // Set current group as the first of the list, if was absent (this will surface on the response header) else { String curGroup = intersection.immutableCopy().iterator().next(); System.out.println("setting current group: " + curGroup); user.setCurrentGroup(curGroup); } // Exploring all the __old_ACL for available groups for this user, known what their resolved groups are, and what the __old_ACL has to offer for the user Set<String> matchingUserPatterns = new MatcherWithWildcards( settings.getUserGroupsProviderSettings().getUser2availGroups().keySet()) .matchingMatchers(Sets.newHashSet(user.getId())); Set<String> availGroupsForUser = Sets.newHashSet(); for (String up : matchingUserPatterns) { availGroupsForUser .addAll(settings.getUserGroupsProviderSettings().getUser2availGroups().get(up)); } availGroupsForUser = Sets.intersection(availGroupsForUser, fetchedGroupsForUser); System.out.println( "adding available groups for user " + user.getId() + ": " + availGroupsForUser); user.addAvailableGroups(availGroupsForUser); return true; }); }
From source file:net.conquiris.schema.SchemaImpl.java
private Schema extendWithMap(Map<String, SchemaItem> items) { if (items.isEmpty()) { return this; }/*from w ww . j ava 2 s.com*/ if (isEmpty()) { return new SchemaImpl(items); } Set<String> intersect = Sets.intersection(map.keySet(), items.keySet()); checkArgument(intersect.isEmpty(), "Extending with existing keys %s", intersect); return putItems(items); }
From source file:com.cloudera.gertrude.space.LayerImpl.java
@Override public void assign(final ExperimentState state, List<DiversionCriterion> diversionCriteria, Map<String, FlagValueCalculator<Object>> overrides, Set<Integer> newExperimentIds) { if (!Sets.intersection(segmentIds, state.getExperimentIds()).isEmpty()) { // Diversion has already happened in this layer. return;/*from w ww. j a va2s .c o m*/ } for (DiversionCriterion criteria : diversionCriteria) { int bucket = -1; if (criteria.isRandom()) { bucket = random.nextInt(criteria.getNumBuckets()); } else { Optional<String> identifier = state.getDiversionIdentifier(criteria.getId()); if (identifier.isPresent()) { bucket = computeBucket(identifier.get(), criteria.getNumBuckets()); } } if (bucket != -1) { Set<Segment> selected = findSegments(segmentsByDiversionBuckets.get(criteria.getId()), bucket, state.getRequestTimeMsec()); if (!selected.isEmpty()) { Set<Segment> valid = Sets.filter(selected, new Predicate<Segment>() { @Override public boolean apply(Segment segment) { return segment.isValidFor(state); } }); if (valid.isEmpty()) { // There were experiments for this bucket, but this request did not match any of them. // Mark the request with the appropriate bias identifier. newExperimentIds .add(criteria.isRandom() ? info.getRandomBiasedId() : info.getFixedBiasedId()); } else if (valid.size() == 1) { // Divert the request into this segment Iterables.getOnlyElement(valid).handle(state, diversionCriteria, overrides, newExperimentIds); } else { // Bad news throw new IllegalStateException( String.format("Multiple valid segments assigned to bucket %d in layer %d: %s", bucket, info.getLayerId(), valid.toString())); } return; } } } // Only reach this point if there were no matching experiments in this layer for the current request. newExperimentIds.add(info.getUnbiasedId()); }
From source file:org.sosy_lab.cpachecker.cpa.smg.graphs.CLangSMGConsistencyVerifier.java
/** * Verifies that heap and stack object sets are disjunct * * @param pLogger Logger to log the message * @param pSmg SMG to check/*from w ww . j a v a 2s. co m*/ * @return True if {@link pSmg} is consistent w.r.t. this criteria. False otherwise. */ static private boolean verifyDisjunctHeapAndStack(LogManager pLogger, CLangSMG pSmg) { Deque<CLangStackFrame> stack_frames = pSmg.getStackFrames(); Set<SMGObject> stack = new HashSet<>(); for (CLangStackFrame frame : stack_frames) { stack.addAll(frame.getAllObjects()); } Set<SMGObject> heap = pSmg.getHeapObjects(); boolean toReturn = Collections.disjoint(stack, heap); if (!toReturn) { pLogger.log(Level.SEVERE, "CLangSMG inconsistent, heap and stack objects are not disjoint: " + Sets.intersection(stack, heap)); } return toReturn; }
From source file:grakn.core.graql.reasoner.atom.AtomicBase.java
/** * @param type the class of {@link Predicate} to return * @param <T> the type of {@link Predicate} to return * @return stream of predicates relevant to this atomic *//*w w w.j a v a2 s .c o m*/ public <T extends Predicate> Stream<T> getPredicates(Class<T> type) { return getParentQuery().getAtoms(type) .filter(atom -> !Sets.intersection(this.getVarNames(), atom.getVarNames()).isEmpty()); }
From source file:org.dllearner.reasoning.OWLPunningDetector.java
/** * Checks whether the ontology contains punning, i.e. entities declared as both, class and individual. * @param ontology the OWL ontology/*from www .j a v a2s . c om*/ * @return TRUE if there is at least one entity that is both, class and individual, otherwise FALSE */ public static boolean hasPunning(OWLOntology ontology) { Set<OWLClass> classes = ontology.getClassesInSignature(Imports.INCLUDED); Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(Imports.INCLUDED); Set<IRI> classIRIs = new HashSet<>(classes.size()); for (OWLClass cls : classes) { classIRIs.add(cls.getIRI()); } Set<IRI> individualIRIs = new HashSet<>(classes.size()); for (OWLNamedIndividual ind : individuals) { individualIRIs.add(ind.getIRI()); } return Sets.intersection(classIRIs, individualIRIs).size() > 0; }
From source file:net.sourceforge.fenixedu.domain.accessControl.TeacherResponsibleOfExecutionCourseGroup.java
@Override public boolean isMember(User user) { if (user == null) { return false; }/*w w w.j av a 2s .c o m*/ if (!Sets.intersection(user.getPerson().getProfessorshipsSet(), new HashSet<>(executionCourse.responsibleFors())).isEmpty()) { return true; } return false; }
From source file:org.sosy_lab.cpachecker.cpa.smgfork.graphs.CLangSMGConsistencyVerifier.java
/** * Verifies that heap and stack object sets are disjunct * * @param pLogger Logger to log the message * @param pSmg SMG to check/*from w w w. ja v a 2 s . c o m*/ * @return True if {@link pSmg} is consistent w.r.t. this criteria. False otherwise. */ static private boolean verifyDisjunctHeapAndStack(LogManager pLogger, CLangSMG pSmg) { ArrayDeque<CLangStackFrame> stack_frames = pSmg.getStackFrames(); Set<SMGObject> stack = new HashSet<>(); for (CLangStackFrame frame : stack_frames) { stack.addAll(frame.getAllObjects()); } Set<SMGObject> heap = pSmg.getHeapObjects(); boolean toReturn = Collections.disjoint(stack, heap); if (!toReturn) { pLogger.log(Level.SEVERE, "CLangSMG inconsistent, heap and stack objects are not disjoint: " + Sets.intersection(stack, heap)); } return toReturn; }