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.fenixedu.cms.domain.CMSTheme.java
public Set<CMSTemplate> getAllTemplates() { return Sets.union(getTemplatesSet(), getExtendedTemplates()); }
From source file:org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory.java
private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException { return NetconfHelloMessage.createServerHello( Sets.union(transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId);/* ww w . j av a2 s.co m*/ }
From source file:org.terasology.engine.module.ModuleSecurityManager.java
private boolean checkAPIPermissionsFor(Permission permission, int moduleDepth, Class[] stack) { Set<Class> allowed = Sets.union(allowedPermissionInstances.get(permission), allowedPermissionsTypes.get(permission.getClass())); Set<String> allowedPackages = Sets.union(Sets.union(allowedPackagePermissionInstances.get(permission), allowedPackagePermissionsTypes.get(permission.getClass())), fullPrivilegePackages); for (int i = moduleDepth - 1; i >= 0; i--) { if (allowed.contains(stack[i]) || allowedPackages.contains(stack[i].getPackage().getName())) { return true; }//from w ww . j av a 2 s. c om } return false; }
From source file:org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory.java
private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException { return NetconfHelloMessage.createServerHello(Sets .union(DefaultCommit.transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId);/*from w w w. java2s . co m*/ }
From source file:com.rackspacecloud.blueflood.types.BluefloodTimerRollup.java
public boolean equals(Object obj) { if (!(obj instanceof BluefloodTimerRollup)) return false; BluefloodTimerRollup other = (BluefloodTimerRollup) obj; if (other.sum != this.sum) return false; if (other.sampleCount != this.sampleCount) return false; if (other.rate != this.rate) return false; if (!other.average.equals(this.average)) return false; if (!other.variance.equals(this.variance)) return false; if (!other.min.equals(this.min)) return false; if (!other.max.equals(this.max)) return false; if (other.count != this.count) return false; Map<String, Percentile> otherPct = other.getPercentiles(); Set<String> allKeys = Sets.union(otherPct.keySet(), this.getPercentiles().keySet()); if (allKeys.size() != this.getPercentiles().size()) return false; for (Map.Entry<String, Percentile> otherEntry : otherPct.entrySet()) if (!otherEntry.getValue().equals(this.getPercentiles().get(otherEntry.getKey()))) return false; return true;// ww w .j a v a 2s . c om }
From source file:org.tensorics.core.tensor.lang.TensorStructurals.java
public static final <V> Tensor<V> mergeContextIntoShape(Tensor<V> tensor) { if (tensor.context().coordinates().isEmpty()) { throw new IllegalArgumentException("an empty context can't be merged into the positions"); }// w w w.j a v a 2 s . co m Builder<V> builder = ImmutableTensor .builder(Sets.union(tensor.shape().dimensionSet(), tensor.context().dimensionSet())); builder.putAll(tensor.context(), tensor); return builder.build(); }
From source file:org.tensorics.core.tensor.operations.InnerTensorOperation.java
@Override public Tensor<V> perform(Tensor<V> left, Tensor<V> right) { checkNotNull(left, "left tensor must not be null!"); checkNotNull(right, "right tensor must not be null!"); List<CoContraDimensionPair> allPairs = CoContraDimensionPairs.coContraPairsOf(left.shape(), right.shape()); List<CoContraDimensionPair> pairsToReduce = CoContraDimensionPairs.chooseOnePerContravariantPart(allPairs); Set<Class<?>> dimensionsNotToBroadcast = CoContraDimensionPairs.allDimensionsIn(pairsToReduce); TensorPair<V> broadcasted = broadcast(left, right, dimensionsNotToBroadcast); Set<Class<?>> leftDimensionsToReduce = CoContraDimensionPairs.leftDimensionsIn(pairsToReduce); Set<Class<?>> rightDimensionsToReduce = CoContraDimensionPairs.rightDimensionsIn(pairsToReduce); Set<Class<?>> remainingLeftDimensions = Sets .difference(broadcasted.left().shape().dimensionSet(), leftDimensionsToReduce).immutableCopy(); Set<Class<?>> remainingRightDimensions = Sets .difference(broadcasted.right().shape().dimensionSet(), rightDimensionsToReduce).immutableCopy(); Set<Class<?>> targetDimensions = Sets.union(remainingLeftDimensions, remainingRightDimensions) .immutableCopy();/*from ww w. j a va2 s .co m*/ Set<Class<?>> remainingCommonDimensions = Sets.intersection(remainingLeftDimensions, remainingRightDimensions); /* * produce a multimap from positions, consisting of all but the unique right dimensions to positions. */ Set<Class<?>> uniqueLeftDimensions = Sets.difference(remainingLeftDimensions, remainingCommonDimensions); Set<Class<?>> uniqueRightDimensions = Sets.difference(remainingRightDimensions, remainingCommonDimensions); Multimap<Position, Position> nonUniqueToRightPositions = Positions .mapByStripping(broadcasted.right().shape().positionSet(), uniqueRightDimensions); DimensionStripper stripper = Positions.stripping(uniqueLeftDimensions); DimensionStripper targetLeftStripper = Positions.stripping(leftDimensionsToReduce); DimensionStripper targetRightStripper = Positions.stripping(rightDimensionsToReduce); ImmutableMultimap.Builder<Position, PositionPair> builder = ImmutableMultimap.builder(); for (Position leftPosition : broadcasted.left().shape().positionSet()) { Position remainingLeftPosition = targetLeftStripper.apply(leftPosition); Position nonUniqueLeftPosition = stripper.apply(leftPosition); Position nonUniqueRightPosition = CoContraDimensionPairs.convertToRight(nonUniqueLeftPosition, pairsToReduce); Collection<Position> rightPositions = nonUniqueToRightPositions.get(nonUniqueRightPosition); for (Position rightPosition : rightPositions) { Position remainingRightPosition = targetRightStripper.apply(rightPosition); Position targetPosition = Positions.combineDimensions(remainingLeftPosition, remainingRightPosition, targetDimensions); builder.put(targetPosition, PositionPair.fromLeftRight(leftPosition, rightPosition)); } } Multimap<Position, PositionPair> targetPositionToPairs = builder.build(); ListMultimap<Position, ValuePair<V>> valuePairs = broadcasted.mapValues(targetPositionToPairs); ListMultimap<Position, V> targetPositionToValueSet = Operations.mapAll(valuePairs, elementOperation); Map<Position, V> result = IterableOperations.reduce(targetPositionToValueSet, reductionOperation); ContextPropagationStrategy cps = optionRegistry.get(ContextPropagationStrategy.class); Position resultingContext = cps.contextForLeftRight(left.context(), right.context()); TensorBuilder<V> finalBuilder = Tensorics.builder(targetDimensions); finalBuilder.putAll(result); finalBuilder.context(resultingContext); return finalBuilder.build(); }
From source file:org.caleydo.view.domino.api.model.typed.TypedSet.java
private static TypedSet union(BitSetSet a, TypedSet b) { if (b.wrappee instanceof BitSetSet) { return new TypedSet(BitSetSet.or(a, (BitSetSet) b.wrappee), b.idType); }/*from www .ja v a2 s.c o m*/ return new TypedSet(ImmutableSet.copyOf(Sets.union(b, a)), b.idType); // as the predicate is: in the second // argument }
From source file:org.gradle.jvm.internal.resolve.JvmLocalLibraryMetaDataAdapter.java
private void createJvmAssemblyLocalComponentMetaData(EnumMap<UsageKind, List<PublishArtifact>> artifacts, JvmAssembly assembly, EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage, boolean toAssembly) { configureUsageMetadata(UsageKind.API, Collections.<DependencySpec>emptyList(), dependenciesPerUsage); configureUsageMetadata(UsageKind.RUNTIME, Collections.<DependencySpec>emptyList(), dependenciesPerUsage); if (toAssembly) { // TODO:Cedric This is an approximation: when a component wants to compile against the assembly of // a library (not the jar), then we should give it the *stubbed classes* instead of the raw classes. However: // - there's no such thing as a "stubbed classes assembly" // - for performance reasons only the classes that belong to the API are stubbed, so we would miss the classes that do not belong to the API // So this makes the UsageKind.API misleading (should this be COMPILE?). addArtifact(UsageKind.API, assembly.getClassDirectories(), artifacts, assembly); addArtifact(UsageKind.RUNTIME,// w ww . j a v a2 s . c o m Sets.union(assembly.getClassDirectories(), assembly.getResourceDirectories()), artifacts, assembly); } }
From source file:ezbake.groups.graph.query.AuthorizationQuery.java
/** * Will get a user's authorizations, filtering by the groups that apps in the filter chain have access to * * @param type type of user to look for//w w w. j a v a 2 s . co m * @param id user id * @param appFilterChain * @return the user's set of group authorizations */ public Set<Long> getAuthorizationSet(BaseVertex.VertexType type, String id, List<String> appFilterChain) throws GroupQueryException { Set<Long> auths = Sets.newHashSet(); // Only get auths if the user exists User user; try { user = graph.getUser(type, id); if (!user.isActive()) { logger.debug("User was inactive, returning empty set"); return auths; // just don't get groups } } catch (InvalidVertexTypeException e) { logger.debug("Invalid request, returning empty set"); return auths; // just don't get groups } catch (UserNotFoundException e) { throw new GroupQueryException("No user found: " + type + ":" + id, GroupQueryError.USER_NOT_FOUND); } // Add the user's own index logger.debug("Adding user's id to the auths: {}", user.getIndex()); auths.add(user.getIndex()); // This can sometimes be null if (appFilterChain == null) { appFilterChain = Collections.emptyList(); } // These are the groups the user has on their own Set<Group> userGroups = getUserGroups(type, id, false); for (Group g : userGroups) { logger.debug("Group -> {} {}", g.getGroupName(), g.getIndex()); } logger.debug("getAuthorizations User: {} has groups: {}", user, userGroups); // These are the groups the apps always include, even if the user doesn't have access Collection<Set<Group>> appsGroups = getUserGroups( userListToMap(BaseVertex.VertexType.APP_USER, appFilterChain), false); Set<Long> appsFilter = Sets.newHashSet(); // This is the intersection of all app auths Set<Long> groupsAppsAlwaysInclude = Sets.newTreeSet(); // This is all the groups the apps include anyways for (Set<Group> appGroup : appsGroups) { Set<Long> indices = Sets.newTreeSet(); for (Group group : appGroup) { indices.add(group.getIndex()); if (group.isRequireOnlyApp()) { groupsAppsAlwaysInclude.add(group.getIndex()); } } appsFilter.retainAll(indices); } if (type == BaseVertex.VertexType.USER) { // Split groups into 2 sets - those that users always have (even if app doesn't) and those that users only have if app has too Set<Long> groupsUserHasRegardless = Sets.newHashSet(auths); Set<Long> groupsDependingOnApp = Sets.newHashSet(); for (Group g : userGroups) { if (g.isRequireOnlyUser()) { logger.debug("User should have group: {} regardless", g); groupsUserHasRegardless.add(g.getIndex()); } else { logger.debug("Will check app access to group: {}", g); groupsDependingOnApp.add(g.getIndex()); } } // Filter the groups that depend on the app if (!groupsDependingOnApp.isEmpty()) { logger.debug("Filtering groups depending on app: {} -> {}", groupsDependingOnApp, appsFilter); groupsDependingOnApp = Sets.intersection(groupsDependingOnApp, appsFilter); logger.debug("Filter result: {}", groupsDependingOnApp); } // Now union the sets to get the users final list auths = Sets.union(groupsUserHasRegardless, groupsDependingOnApp); logger.debug("Auths after taking intersection: {}", auths); } else if (type == BaseVertex.VertexType.APP_USER) { // What to do here? Set<Long> appAuths = Sets.newHashSet(auths); for (Group g : userGroups) { appAuths.add(g.getIndex()); } auths = appAuths; } graph.commitTransaction(); return Sets.union(auths, groupsAppsAlwaysInclude); }