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.dllearner.algorithms.properties.MultiPropertyAxiomLearner.java
public void start() { startTime = System.currentTimeMillis(); checkConfigOptions();//from www .j a v a2 s.c o m // check if entity is empty int popularity = reasoner.getPopularity(entity); if (popularity == 0) { logger.warn("Cannot make axiom suggestions for empty " + entity.getEntityType().getName() + " " + entity.toStringID()); return; } results = Maps.newConcurrentMap(); EntityType<?> entityType = entity.getEntityType(); // check for axiom types that are not appropriate for the given entity Set<AxiomType<? extends OWLAxiom>> possibleAxiomTypes = AxiomAlgorithms.getAxiomTypes(entityType); SetView<AxiomType<? extends OWLAxiom>> notAllowed = Sets.difference(axiomTypes, possibleAxiomTypes); if (!notAllowed.isEmpty()) { logger.warn("Not supported axiom types for entity " + entity + " :" + notAllowed); } Set<AxiomType<? extends OWLAxiom>> todo = Sets.intersection(axiomTypes, possibleAxiomTypes); // compute samples for axiom types Set<AxiomTypeCluster> sampleClusters = AxiomAlgorithms.getSameSampleClusters(entityType); ExecutorService tp = Executors.newFixedThreadPool(maxNrOfThreads); for (final AxiomTypeCluster cluster : sampleClusters) { final SetView<AxiomType<? extends OWLAxiom>> sampleAxiomTypes = Sets .intersection(cluster.getAxiomTypes(), todo); if (!sampleAxiomTypes.isEmpty()) { tp.submit(() -> { try { SparqlEndpointKS ks1 = MultiPropertyAxiomLearner.this.ks; // get sample if enabled if (useSampling) { Model sample = generateSample(entity, cluster); // if sampling failed, we skip if (sample == null) { return; } // if the sample is empty, we skip and show warning if (sample.isEmpty()) { logger.warn("Empty sample. Skipped learning."); return; } ks1 = new LocalModelBasedSparqlEndpointKS(sample); } // process each axiom type for (AxiomType<? extends OWLAxiom> axiomType : sampleAxiomTypes) { try { List<EvaluatedAxiom<OWLAxiom>> result = applyAlgorithm(axiomType, ks1); results.put(axiomType, result); } catch (Exception e) { logger.error("An error occurred while generating " + axiomType.getName() + " axioms for " + OWLAPIUtils.getPrintName(entity.getEntityType()) + " " + entity.toStringID(), e); } } } catch (Exception e) { logger.error("Failed to process " + cluster, e); } }); } } try { tp.shutdown(); tp.awaitTermination(1, TimeUnit.HOURS); } catch (InterruptedException e) { e.printStackTrace(); } // // for (AxiomType<? extends OWLAxiom> axiomType : todo) { // try { // applyAlgorithm(entity, axiomType, useSampling ? axiomType2Ks.get(axiomType) : ks); // } catch (Exception e) { // logger.error("Error occurred while generating " + axiomType.getName() + " for entity " + entity, e); // } // } }
From source file:ezbake.security.permissions.PermissionUtils.java
/** * Get permissions for user (based their authorizations) against the data's visibility. * * @param auths Authorizations of the user * @param visibility Visibility of the data * @param validateFormalAuths true to validate formal authorizations, false to skip * @param subsetToCheck The subset of permissions to check (to avoid more bitvector operations than needed) * @return The set of permissions the user has for the data (a subset of the subsetToCheck) *//*from w w w.ja v a2 s . c om*/ public static Set<Permission> getPermissions(Authorizations auths, Visibility visibility, boolean validateFormalAuths, Set<Permission> subsetToCheck) { if (visibility == null) { return ALL_PERMS; // No visibility to check } if (auths == null) { return NO_PERMS; // Has visibility but no auths } if (validateFormalAuths && !validateVisibilityExpression(auths.getFormalAuthorizations(), visibility.getFormalVisibility())) { return NO_PERMS; // Formals auths check failed } final AdvancedMarkings markings = visibility.getAdvancedMarkings(); if (markings == null) { return ALL_PERMS; // No further visibility to check } if (!validateVisibilityExpression(auths.getExternalCommunityAuthorizations(), markings.getExternalCommunityVisibility())) { return NO_PERMS; // External community auths check failed } final PlatformObjectVisibilities pov = markings.getPlatformObjectVisibility(); if (pov == null) { return ALL_PERMS; // No further visibility to check } final Set<Long> authCheck = auths.getPlatformObjectAuthorizations(); final Set<Permission> perms = EnumSet.noneOf(Permission.class); for (final Permission permToCheck : subsetToCheck) { Set<Long> permVisibility = null; switch (permToCheck) { case READ: permVisibility = pov.getPlatformObjectReadVisibility(); break; case WRITE: permVisibility = pov.getPlatformObjectWriteVisibility(); break; case MANAGE_VISIBILITY: permVisibility = pov.getPlatformObjectManageVisibility(); break; case DISCOVER: permVisibility = pov.getPlatformObjectDiscoverVisibility(); break; default: throw new IllegalArgumentException("Unknown Permission enum value" + permToCheck); } // Null/Empty visibility means world-accessible, else check intersection if (permVisibility == null || permVisibility.isEmpty() || authCheck != null && !Sets.intersection(authCheck, permVisibility).isEmpty()) { perms.add(permToCheck); } } return perms; }
From source file:com.urswolfer.intellij.plugin.gerrit.ui.changesbrowser.CommitDiffBuilder.java
private void changedFiles() { Sets.SetView<String> changedFiles = Sets.intersection(baseChanges.keySet(), changes.keySet()); for (String changedFile : changedFiles) { Change baseChange = baseChanges.get(changedFile); ContentRevision baseRevision = baseChange.getAfterRevision(); Change change = changes.get(changedFile); ContentRevision revision = change.getAfterRevision(); if (baseRevision != null || revision != null) { diff.add(new Change(baseRevision, revision)); }// ww w .j a v a 2s . c om } }
From source file:org.eclipse.sw360.portal.tags.DisplayProjectChanges.java
private void renderLinkedProjects(StringBuilder display, User user) { if (ensureSomethingTodoAndNoNullLinkedProjects()) { Set<String> changedProjectIds = Sets.intersection(additions.getLinkedProjects().keySet(), deletions.getLinkedProjects().keySet()); Set<String> linkedProjectsInDb = nullToEmptyMap(actual.getLinkedProjects()).keySet(); //keep only projects that are still in the database changedProjectIds = Sets.intersection(changedProjectIds, linkedProjectsInDb); Set<String> removedProjectIds = Sets.difference(deletions.getLinkedProjects().keySet(), changedProjectIds);//from www . j a v a 2s. c om removedProjectIds = Sets.intersection(removedProjectIds, linkedProjectsInDb); Set<String> addedProjectIds = Sets.difference(additions.getLinkedProjects().keySet(), changedProjectIds); renderProjectLinkList(display, deletions.getLinkedProjects(), removedProjectIds, "Removed Project Links", user); renderProjectLinkList(display, additions.getLinkedProjects(), addedProjectIds, "Added Project Links", user); renderProjectLinkListCompare(display, actual.getLinkedProjects(), deletions.getLinkedProjects(), additions.getLinkedProjects(), changedProjectIds, user); } }
From source file:org.onosproject.net.resource.impl.LabelAllocator.java
/** * Looks for available Ids.//from w w w . j av a 2 s . c o m * * @param links the links where to look for Ids * @param type the encapsulation type * @return the mappings between key and id */ private Map<LinkKey, Identifier<?>> findAvailableIDs(Set<LinkKey> links, EncapsulationType type) { Map<LinkKey, Identifier<?>> ids = Maps.newHashMap(); for (LinkKey link : links) { Set<Identifier<?>> availableIDsatSrc = getAvailableIDs(link.src(), type); Set<Identifier<?>> availableIDsatDst = getAvailableIDs(link.dst(), type); Set<Identifier<?>> common = Sets.intersection(availableIDsatSrc, availableIDsatDst); if (common.isEmpty()) { continue; } Identifier<?> selected = labelSelection.select(common); if (selected == null) { continue; } ids.put(link, selected); } return ids; }
From source file:dynamicrefactoring.domain.metadata.imp.ElementCatalog.java
/** * Devuelve si alguno de los elementos pertenece a mas de una de las * categorias./*from w w w . j a va 2s .c om*/ * * @param allElements * conjunto de elementos * @param categories * conjunto de categorias * @return si alguno de los elementos pertenece a mas de una de las * categorias */ private boolean hasMultiCategoryElements(Set<K> allElements, Set<Category> categories) { for (K element : allElements) { if (Sets.intersection(element.getCategories(), categories).size() > 1) { return true; } } return false; }
From source file:org.caleydo.view.domino.internal.Blocks.java
/** * @param sel * @param b * @return */ private boolean canHaveBands(Block a, Block b) { return !Sets.intersection(a.getIDTypes(), b.getIDTypes()).isEmpty(); }
From source file:com.nearinfinity.honeycomb.mysql.Util.java
/** * Retrieve from a list of indices which ones have been changed. * * @param indices Table indices/*from www . j a va2s . c o m*/ * @param oldRecords Old MySQL row * @param newRecords New MySQL row * @return List of changed indices */ public static ImmutableList<IndexSchema> getChangedIndices(Collection<IndexSchema> indices, Map<String, ByteBuffer> oldRecords, Map<String, ByteBuffer> newRecords) { if (indices.isEmpty()) { return ImmutableList.of(); } MapDifference<String, ByteBuffer> diff = Maps.difference(oldRecords, newRecords); Set<String> changedColumns = Sets.difference(Sets.union(newRecords.keySet(), oldRecords.keySet()), diff.entriesInCommon().keySet()); ImmutableList.Builder<IndexSchema> changedIndices = ImmutableList.builder(); for (IndexSchema index : indices) { Set<String> indexColumns = ImmutableSet.copyOf(index.getColumns()); if (!Sets.intersection(changedColumns, indexColumns).isEmpty()) { changedIndices.add(index); } } return changedIndices.build(); }
From source file:org.sonatype.nexus.security.user.ConfiguredUsersUserManager.java
@Override protected boolean matchesCriteria(final String userId, final String userSource, final Collection<String> usersRoles, final UserSearchCriteria criteria) { // basically the same as the super, but we don't want to check the source if (!Strings2.isBlank(criteria.getUserId()) && !userId.toLowerCase().startsWith(criteria.getUserId().toLowerCase())) { return false; }// w w w . ja v a2 s . co m if (criteria.getOneOfRoleIds() != null && !criteria.getOneOfRoleIds().isEmpty()) { Set<String> userRoles = new HashSet<>(); if (usersRoles != null) { userRoles.addAll(usersRoles); } // check the intersection of the roles if (Sets.intersection(criteria.getOneOfRoleIds(), userRoles).isEmpty()) { return false; } } return true; }
From source file:tech.beshu.ror.acl.blocks.rules.impl.RorKbnAuthSyncRule.java
@Override public RuleExitResult match(__old_RequestContext rc) { Optional<String> token = Optional.of(rc.getHeaders()).map(m -> m.get(settings.getHeaderName())) .flatMap(RorKbnAuthSyncRule::extractToken); if (!token.isPresent()) { logger.debug("Authorization header is missing or does not contain a bearer token"); return NO_MATCH; }// w ww . j a v a 2s . co m try { Jws<Claims> jws = AccessController.doPrivileged((PrivilegedAction<Jws<Claims>>) () -> { JwtParser parser = Jwts.parser(); if (signingKeyForAlgo.isPresent()) { parser.setSigningKey(signingKeyForAlgo.get()); } else { parser.setSigningKey(settings.getKey()); } return parser.parseClaimsJws(token.get()); }); Optional<String> user = settings.getUserClaim().map(claim -> jws.getBody().get(claim, String.class)); if (settings.getUserClaim().isPresent()) if (!user.isPresent()) return NO_MATCH; else rc.setLoggedInUser(new LoggedUser(user.get())); Optional<Set<String>> roles = this.extractRoles(jws); if (settings.getRolesClaim().isPresent() && !roles.isPresent()) return NO_MATCH; if (!settings.getRoles().isEmpty()) { if (!roles.isPresent()) { return NO_MATCH; } else { Set<String> r = roles.get(); if (r.isEmpty() || Sets.intersection(r, settings.getRoles()).isEmpty()) return NO_MATCH; } } String fromClaim = jws.getBody().get(Constants.HEADER_USER_ORIGIN, String.class); if (!Strings.isNullOrEmpty(fromClaim)) { rc.setResponseHeader(Constants.HEADER_USER_ORIGIN, fromClaim); } return MATCH; } catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | SignatureException e) { return NO_MATCH; } }