List of usage examples for com.google.common.collect Sets union
public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2)
From source file:org.apache.cassandra.io.compress.CompressionParameters.java
private static ICompressor createCompressor(Class<?> compressorClass, Map<String, String> compressionOptions) throws ConfigurationException { if (compressorClass == null) { if (!compressionOptions.isEmpty()) throw new ConfigurationException("Unknown compression options (" + compressionOptions.keySet() + ") since no compression class found"); return null; }/* w w w. ja v a 2 s . c o m*/ try { Method method = compressorClass.getMethod("create", Map.class); ICompressor compressor = (ICompressor) method.invoke(null, compressionOptions); // Check for unknown options AbstractSet<String> supportedOpts = Sets.union(compressor.supportedOptions(), GLOBAL_OPTIONS); for (String provided : compressionOptions.keySet()) if (!supportedOpts.contains(provided)) throw new ConfigurationException("Unknown compression options " + provided); return compressor; } catch (NoSuchMethodException e) { throw new ConfigurationException("create method not found", e); } catch (SecurityException e) { throw new ConfigurationException("Access forbiden", e); } catch (IllegalAccessException e) { throw new ConfigurationException("Cannot access method create in " + compressorClass.getName(), e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new ConfigurationException(String.format("%s.create() threw an error: %s", compressorClass.getSimpleName(), cause == null ? e.getClass().getName() + " " + e.getMessage() : cause.getClass().getName() + " " + cause.getMessage()), e); } catch (ExceptionInInitializerError e) { throw new ConfigurationException("Cannot initialize class " + compressorClass.getName()); } }
From source file:org.gradle.api.internal.resolve.VariantsMatcher.java
public Collection<? extends BinarySpec> filterBinaries(VariantsMetaData variantsMetaData, Collection<BinarySpec> binaries) { if (binaries.isEmpty()) { return binaries; }/*from w w w . j av a 2 s .c o m*/ Set<String> resolveDimensions = variantsMetaData.getNonNullVariantAxes(); TreeMultimap<String, VariantValue> selectedVariants = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, SPEC_COMPARATOR); Set<BinarySpec> removedSpecs = Sets.newHashSet(); for (BinarySpec binarySpec : binaries) { if (binarySpecType.isAssignableFrom(binarySpec.getClass())) { VariantsMetaData binaryVariants = DefaultVariantsMetaData.extractFrom(binarySpec, schemaStore); Set<String> commonsDimensions = Sets.intersection(resolveDimensions, binaryVariants.getNonNullVariantAxes()); Set<String> incompatibleDimensionTypes = VariantsMetaDataHelper .determineAxesWithIncompatibleTypes(variantsMetaData, binaryVariants, commonsDimensions); if (incompatibleDimensionTypes.isEmpty()) { for (String dimension : commonsDimensions) { Class<?> dimensionType = variantsMetaData.getVariantAxisType(dimension).getConcreteClass(); boolean isStringType = String.class == dimensionType; Object requestedValue = isStringType ? variantsMetaData.getValueAsString(dimension) : variantsMetaData.getValueAsType( Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension); Object binaryValue = isStringType ? binaryVariants.getValueAsString(dimension) : binaryVariants.getValueAsType( Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension); VariantAxisCompatibility<Object> selector = createSelector(requestedValue); if (selector.isCompatibleWithRequirement(requestedValue, binaryValue)) { VariantValue value = new VariantValue(binaryValue, binarySpec); SortedSet<VariantValue> variantValues = selectedVariants.get(dimension); for (VariantValue variantValue : variantValues) { // all the values are equal, but we store all the binaries that match that value // and incrementally build a list of binaries which are excluded because of a better match if (selector.betterFit(requestedValue, variantValue.value, binaryValue)) { // the new value is a better fit than the old one removedSpecs.add(variantValue.spec); } else if (selector.betterFit(requestedValue, binaryValue, variantValue.value)) { // the old value is a better fit than the new one, let's ignore the new one altogether removedSpecs.add(value.spec); } } selectedVariants.put(dimension, value); } else { removedSpecs.add(binarySpec); } } } } } Set<BinarySpec> union = null; for (String dimension : selectedVariants.keySet()) { Set<BinarySpec> variantValues = ImmutableSet .copyOf(Iterables.transform(selectedVariants.get(dimension), VariantValue.SPEC_FUNCTION)); union = union == null ? variantValues : Sets.union(union, variantValues); } return union == null ? Collections.<BinarySpec>emptySet() : Sets.difference(union, removedSpecs); }
From source file:com.google.enterprise.adaptor.Acl.java
/** * Returns immutable set of denied users and groups; */ public Set<Principal> getDenies() { return Sets.union(denyUsers, denyGroups); }
From source file:blockplus.transport.VirtualClient.java
private IPosition testAI(final Colors color, final Board board, final Options options) { System.out.println();// w w w .jav a2s . co m System.out.println(color); final Iterable<IPosition> ownLights = board.getLights(color); System.out.println(ownLights); final Set<IPosition> setOfOwnLights = Sets.newHashSet(ownLights); final Set<Colors> colors = board.getColors(); colors.remove(color); Set<IPosition> intersections = Sets.newHashSet(); for (final Colors Color : colors) { final Iterable<IPosition> otherLights = board.getLights(Color); final SetView<IPosition> intersection = Sets.intersection(setOfOwnLights, Sets.newHashSet(otherLights)); intersections = Sets.union(intersections, intersection); } IPosition position = null; if (!intersections.isEmpty()) { System.out.println(intersections); int max = 0; for (final IPosition iPosition : intersections) { int n = 0; for (final Colors Color : colors) { if (Sets.newHashSet(board.getLights(Color)).contains(iPosition)) ++n; } if (n > max) { max = n; position = iPosition; } } System.out.println(max); System.out.println(position); } return position; }
From source file:co.mitro.core.servlets.MutateOrganization.java
@Override protected MitroRPC processCommand(MitroRequestContext context) throws IOException, SQLException, MitroServletException { try {/* w ww . ja va 2s.c o m*/ RPC.MutateOrganizationRequest in = gson.fromJson(context.jsonRequest, RPC.MutateOrganizationRequest.class); in.promotedMemberEncryptedKeys = MitroServlet.createMapIfNull(in.promotedMemberEncryptedKeys); in.newMemberGroupKeys = MitroServlet.createMapIfNull(in.newMemberGroupKeys); in.adminsToDemote = MitroServlet.uniquifyCollection(in.adminsToDemote); in.membersToRemove = MitroServlet.uniquifyCollection(in.membersToRemove); @SuppressWarnings("deprecation") AuthenticatedDB userDb = AuthenticatedDB.deprecatedNew(context.manager, context.requestor); DBGroup org = userDb.getOrganizationAsAdmin(in.orgId); Set<String> adminsToDemote = Sets.newHashSet(in.adminsToDemote); Collection<DBAcl> aclsToRemove = new HashSet<>(); Set<Integer> existingAdmins = new HashSet<>(); for (DBAcl acl : org.getAcls()) { DBIdentity u = acl.loadMemberIdentity(context.manager.identityDao); assert (u != null); // toplevel groups should not have group members. if (adminsToDemote.contains(u.getName())) { aclsToRemove.add(acl); adminsToDemote.remove(u.getName()); } else { existingAdmins.add(u.getId()); } } // check for an attempt to promote members who are already admins. Set<Integer> duplicateAdmins = Sets.intersection(existingAdmins, DBIdentity.getUserIdsFromNames(context.manager, in.promotedMemberEncryptedKeys.keySet())); if (!duplicateAdmins.isEmpty()) { throw new MitroServletException( "Operation would create duplicate admins: " + COMMA_JOINER.join(duplicateAdmins)); } if (!adminsToDemote.isEmpty()) { throw new MitroServletException("The following users are not admins and could not be deleted:" + COMMA_JOINER.join(adminsToDemote)); } if (existingAdmins.isEmpty() && in.promotedMemberEncryptedKeys.isEmpty()) { throw new UserVisibleException("You cannot remove all admins from an organization"); } // delete ACLs for the admin user on the group. This maybe should be using common code? context.manager.aclDao.delete(aclsToRemove); Map<Integer, Integer> currentMemberIdsToGroupIds = getMemberIdsAndPrivateGroupIdsForOrg(context.manager, org); // Promoted members (new admins) must be members after all changes Set<String> currentMembers = DBIdentity.getUserNamesFromIds(context.manager, currentMemberIdsToGroupIds.keySet()); Set<String> membersAfterChanges = Sets.difference( Sets.union(currentMembers, in.newMemberGroupKeys.keySet()), new HashSet<>(in.membersToRemove)); Set<String> nonMemberAdmins = Sets.difference(in.promotedMemberEncryptedKeys.keySet(), membersAfterChanges); if (!nonMemberAdmins.isEmpty()) { throw new MitroServletException( "Cannot add admins without them being members: " + COMMA_JOINER.join(nonMemberAdmins)); } // check for duplicate users Set<Integer> duplicateMembers = Sets.intersection(currentMemberIdsToGroupIds.keySet(), DBIdentity.getUserIdsFromNames(context.manager, in.newMemberGroupKeys.keySet())); if (!duplicateMembers.isEmpty()) { throw new MitroServletException( "Operation would create duplicate members: " + COMMA_JOINER.join(duplicateMembers)); } // delete all the private groups. This might orphan secrets, which is the intended result. Set<Integer> memberIdsToRemove = DBIdentity.getUserIdsFromNames(context.manager, in.membersToRemove); if (memberIdsToRemove.size() != in.membersToRemove.size()) { throw new MitroServletException("Invalid members to remove."); } Set<Integer> illegalRemovals = Sets.intersection(existingAdmins, memberIdsToRemove); if (!illegalRemovals.isEmpty()) { throw new MitroServletException( "Cannot remove members who are admins:" + COMMA_JOINER.join(illegalRemovals)); } Set<Integer> nonOrgUsers = Sets.difference(memberIdsToRemove, currentMemberIdsToGroupIds.keySet()); if (!nonOrgUsers.isEmpty()) { throw new MitroServletException("The following users are not members and cannot be removed:" + COMMA_JOINER.join(nonOrgUsers)); } Set<Integer> deleteGroupIds = Sets.newHashSet( Maps.filterKeys(currentMemberIdsToGroupIds, Predicates.in(memberIdsToRemove)).values()); if (!deleteGroupIds.isEmpty()) { context.manager.groupDao.deleteIds(deleteGroupIds); DeleteBuilder<DBAcl, Integer> deleter = context.manager.aclDao.deleteBuilder(); deleter.where().in(DBAcl.GROUP_ID_FIELD_NAME, deleteGroupIds); deleter.delete(); DeleteBuilder<DBGroupSecret, Integer> gsDeleter = context.manager.groupSecretDao.deleteBuilder(); gsDeleter.where().in(DBGroupSecret.GROUP_ID_NAME, deleteGroupIds); gsDeleter.delete(); } // Remove the user from all org-owned group to which he belongs. // Note: if the user has access to an org-owned secret via a non-org-owned group, // he will retain access. Set<Integer> allOrgGroupIds = Sets.newHashSet(); for (DBGroup g : org.getAllOrgGroups(context.manager)) { allOrgGroupIds.add(g.getId()); } if (!memberIdsToRemove.isEmpty()) { if (!allOrgGroupIds.isEmpty()) { // Remove users from organization-owned groups (named or otherwise) DeleteBuilder<DBAcl, Integer> deleter = context.manager.aclDao.deleteBuilder(); deleter.where().in(DBAcl.MEMBER_IDENTITY_FIELD_NAME, memberIdsToRemove).and() .in(DBAcl.GROUP_ID_FIELD_NAME, allOrgGroupIds); deleter.delete(); } // Remove users from any org-owned secrets (e.g. via non-org private or named groups) HashMap<Integer, SecretToPath> orgSecretsToPath = new HashMap<>(); ListMySecretsAndGroupKeys.getSecretInfo(context, AdminAccess.FORCE_ACCESS_VIA_TOPLEVEL_GROUPS, orgSecretsToPath, ImmutableSet.of(org.getId()), null, IncludeAuditLogInfo.NO_AUDIT_LOG_INFO); if (orgSecretsToPath.size() > 0) { // Delete any group secret giving these users access to org secrets // strange side effect: personal teams may be mysteriously removed from org secrets // TODO: Potential bug: removing the last personal team will "orphan" the secret String groupSecretDelete = String.format( "DELETE FROM group_secret WHERE id IN (" + "SELECT group_secret.id FROM group_secret, acl WHERE " + " group_secret.\"serverVisibleSecret_id\" IN (%s) AND " + " group_secret.group_id = acl.group_id AND acl.member_identity IN (%s))", COMMA_JOINER.join(orgSecretsToPath.keySet()), COMMA_JOINER.join(memberIdsToRemove)); context.manager.groupSecretDao.executeRaw(groupSecretDelete); } } List<DBAcl> organizationAcls = CreateOrganization.makeAdminAclsForOrganization(userDb, org, in.promotedMemberEncryptedKeys); // TODO: move to authdb? for (DBAcl acl : organizationAcls) { context.manager.aclDao.create(acl); } // create private groups for each new member CreateOrganization.addMembersToOrganization(userDb, org, in.newMemberGroupKeys, context.manager); context.manager.addAuditLog(DBAudit.ACTION.MUTATE_ORGANIZATION, null, null, org, null, ""); MutateOrganizationResponse out = new RPC.MutateOrganizationResponse(); // TODO: validate the group? return out; } catch (CyclicGroupError e) { throw new MitroServletException(e); } }
From source file:org.caleydo.view.domino.api.model.typed.TypedSet.java
private Set<Integer> unionImpl(TypedSet that) { Set<Integer> r;//from www. jav a2 s. co m if (this.size() < that.size()) { // smaller at the beginning r = Sets.union(that.wrappee, this.wrappee); } else r = Sets.union(this.wrappee, that.wrappee); return r; }
From source file:com.googlecode.blaisemath.style.AttributeSet.java
/** * Return attributes of the given type, whether in this set or the parent set. * @param type attribute type// w w w .j a v a 2s . co m * @return attribute keys */ public Set<String> getAllAttributes(Class type) { Map<String, Object> filtered = Maps.filterValues(attributeMap, Predicates.instanceOf(type)); if (parent.isPresent()) { return Sets.union(filtered.keySet(), parent.get().getAllAttributes(type)); } else { return filtered.keySet(); } }
From source file:org.gradle.jvm.internal.resolve.VariantsMatcher.java
public Collection<? extends BinarySpec> filterBinaries(VariantsMetaData variantsMetaData, Collection<BinarySpec> binaries) { if (binaries.isEmpty()) { return binaries; }/* ww w .j a va 2 s . co m*/ Set<String> resolveDimensions = variantsMetaData.getNonNullVariantAxes(); TreeMultimap<String, VariantValue> selectedVariants = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, SPEC_COMPARATOR); Set<BinarySpec> removedSpecs = Sets.newHashSet(); for (BinarySpec binarySpec : binaries) { if (binarySpecType.isAssignableFrom(binarySpec.getClass())) { VariantsMetaData binaryVariants = DefaultVariantsMetaData.extractFrom(binarySpec, schemaStore.getSchema(((BinarySpecInternal) binarySpec).getPublicType())); Set<String> commonsDimensions = Sets.intersection(resolveDimensions, binaryVariants.getNonNullVariantAxes()); Set<String> incompatibleDimensionTypes = VariantsMetaDataHelper .determineAxesWithIncompatibleTypes(variantsMetaData, binaryVariants, commonsDimensions); if (incompatibleDimensionTypes.isEmpty()) { for (String dimension : commonsDimensions) { Class<?> dimensionType = variantsMetaData.getVariantAxisType(dimension).getConcreteClass(); boolean isStringType = String.class == dimensionType; Object requestedValue = isStringType ? variantsMetaData.getValueAsString(dimension) : variantsMetaData.getValueAsType( Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension); Object binaryValue = isStringType ? binaryVariants.getValueAsString(dimension) : binaryVariants.getValueAsType( Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension); VariantAxisCompatibility<Object> selector = createSelector(requestedValue); if (selector.isCompatibleWithRequirement(requestedValue, binaryValue)) { VariantValue value = new VariantValue(binaryValue, binarySpec); SortedSet<VariantValue> variantValues = selectedVariants.get(dimension); for (VariantValue variantValue : variantValues) { // all the values are equal, but we store all the binaries that match that value // and incrementally build a list of binaries which are excluded because of a better match if (selector.betterFit(requestedValue, variantValue.value, binaryValue)) { // the new value is a better fit than the old one removedSpecs.add(variantValue.spec); } else if (selector.betterFit(requestedValue, binaryValue, variantValue.value)) { // the old value is a better fit than the new one, let's ignore the new one altogether removedSpecs.add(value.spec); } } selectedVariants.put(dimension, value); } else { removedSpecs.add(binarySpec); } } } } } Set<BinarySpec> union = null; for (String dimension : selectedVariants.keySet()) { Set<BinarySpec> variantValues = ImmutableSet .copyOf(Iterables.transform(selectedVariants.get(dimension), VariantValue.SPEC_FUNCTION)); union = union == null ? variantValues : Sets.union(union, variantValues); } return union == null ? Collections.<BinarySpec>emptySet() : Sets.difference(union, removedSpecs); }
From source file:com.github.pms1.tppt.p2.FeatureXmlComparator.java
private void comparePlugins2(Map<String, Multimap<String, Element>> baseline, Map<String, Multimap<String, Element>> current, ElementDeltaReporter elementDeltaReporter, DeltaReporter deltaReporter) {//from ww w . ja va2s .c om for (String id : Sets.union(baseline.keySet(), current.keySet())) { Multimap<String, Element> b = baseline.get(id); if (b == null) b = HashMultimap.create(); else b = HashMultimap.create(b); Multimap<String, Element> c = current.get(id); if (c == null) c = HashMultimap.create(); else c = HashMultimap.create(c); AttributesDeltaReporter r = new AttributesDeltaReporter() { @Override public void removed(String key) { deltaReporter.fileDelta("Plugin {0} attribute {1} removed", id, key); } @Override public void changed(String key, String left, String right) { if (key.equals("version")) { deltaReporter.pluginVersionDelta(id, left, right); } else { deltaReporter.fileDelta("Plugin {0} attribute {1} changed {2} -> {3}", id, key, left, right); } } @Override public void added(String key, String value) { deltaReporter.fileDelta("Plugin {0} attribute {1} / {2} added", id, key, value); } }; Set<String> intersection = new HashSet<>(b.keys()); intersection.retainAll(c.keys()); for (String v : intersection) { Collection<Element> be = b.get(v); Collection<Element> ce = c.get(v); if (be.size() == 1 && ce.size() == 1) { compareAttributes(Iterables.getOnlyElement(be), Iterables.getOnlyElement(ce), r); b.removeAll(v); c.removeAll(v); } } if (b.size() == 1 && c.size() == 1) { compareAttributes(Iterables.getOnlyElement(b.values()), Iterables.getOnlyElement(c.values()), r); } else { for (Element e : b.values()) deltaReporter.fileDelta("Plugin removed: {0}", domRenderer.render(e)); for (Element e : c.values()) deltaReporter.fileDelta("Plugin added: {0}", domRenderer.render(e)); } } }
From source file:org.semanticweb.owlapi.sparql.ui.AutoCompleter.java
private static Set<? extends OWLEntity> getSignatureOfType(EntityType<?> et, OWLOntology o) { Set<OWLEntity> result = new HashSet<>(); if (et == EntityType.CLASS) { OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory(); return Sets.union(o.getClassesInSignature(true), Collections.singleton(df.getOWLThing())); } else if (et == EntityType.OBJECT_PROPERTY) { return o.getObjectPropertiesInSignature(true); } else if (et == EntityType.DATA_PROPERTY) { return o.getDataPropertiesInSignature(true); } else if (et == EntityType.ANNOTATION_PROPERTY) { Set<OWLAnnotationProperty> builtIns = getBuiltInAnnotationProperties(o); return Sets.union(o.getAnnotationPropertiesInSignature(), builtIns); } else if (et == EntityType.NAMED_INDIVIDUAL) { return o.getIndividualsInSignature(); } else {/*from ww w . j a v a 2s. c o m*/ return o.getDatatypesInSignature(); } }