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.dishevelled.venn.model.QuaternaryVennModelImpl.java
/** * Create a new quaternary venn model with the specified sets. * * @param first first set, must not be null * @param second second set, must not be null * @param third third set, must not be null * @param fourth fourth set, must not be null *///from ww w. java 2s . c o m public QuaternaryVennModelImpl(final Set<? extends E> first, final Set<? extends E> second, final Set<? extends E> third, final Set<? extends E> fourth) { if (first == null) { throw new IllegalArgumentException("first must not be null"); } if (second == null) { throw new IllegalArgumentException("second must not be null"); } if (third == null) { throw new IllegalArgumentException("third must not be null"); } if (fourth == null) { throw new IllegalArgumentException("fourth must not be null"); } // todo defensive copy? this.first = new ObservableSetImpl(first); this.second = new ObservableSetImpl(second); this.third = new ObservableSetImpl(third); this.fourth = new ObservableSetImpl(fourth); // alias ObservableSet<E> f = this.first; ObservableSet<E> s = this.second; ObservableSet<E> t = this.third; ObservableSet<E> r = this.fourth; firstOnly = Sets.difference(Sets.difference(Sets.difference(f, s), t), r); // f - s - t - r secondOnly = Sets.difference(Sets.difference(Sets.difference(s, f), t), r); // s - f - t - r thirdOnly = Sets.difference(Sets.difference(Sets.difference(t, f), s), r); // t - f - s - r fourthOnly = Sets.difference(Sets.difference(Sets.difference(r, f), s), t); // r - f - s - t firstSecond = Sets.difference(Sets.difference(Sets.intersection(f, s), t), r); // f n s - t - r firstThird = Sets.difference(Sets.difference(Sets.intersection(f, t), s), r); // f n t - s - r firstFourth = Sets.difference(Sets.difference(Sets.intersection(f, r), s), t); // f n r - s - t secondThird = Sets.difference(Sets.difference(Sets.intersection(s, t), f), r); // s n t - f - r secondFourth = Sets.difference(Sets.difference(Sets.intersection(s, r), f), t); // s n r - f - t thirdFourth = Sets.difference(Sets.difference(Sets.intersection(t, r), f), s); // t n r - f - s firstSecondThird = Sets.difference(Sets.intersection(f, Sets.intersection(s, t)), r); // f n s n t - r firstSecondFourth = Sets.difference(Sets.intersection(f, Sets.intersection(s, r)), t); // f n s n r - t firstThirdFourth = Sets.difference(Sets.intersection(f, Sets.intersection(t, r)), s); // f n t n r - s secondThirdFourth = Sets.difference(Sets.intersection(s, Sets.intersection(t, r)), f); // s n t n r - f intersection = Sets.intersection(f, Sets.intersection(s, Sets.intersection(t, r))); // f n s n t n r union = Sets.union(f, Sets.union(s, Sets.union(t, r))); // f u s u t u r selection = new SelectionView<E>(union, f, s, t, r); exclusives = new HashMap<ImmutableBitSet, Set<E>>(15); exclusives.put(toImmutableBitSet(0), firstOnly); exclusives.put(toImmutableBitSet(1), secondOnly); exclusives.put(toImmutableBitSet(2), thirdOnly); exclusives.put(toImmutableBitSet(3), fourthOnly); exclusives.put(toImmutableBitSet(0, 1), firstSecond); exclusives.put(toImmutableBitSet(0, 2), firstThird); exclusives.put(toImmutableBitSet(0, 3), firstFourth); exclusives.put(toImmutableBitSet(1, 2), secondThird); exclusives.put(toImmutableBitSet(1, 3), secondFourth); exclusives.put(toImmutableBitSet(2, 3), thirdFourth); exclusives.put(toImmutableBitSet(0, 1, 2), firstSecondThird); exclusives.put(toImmutableBitSet(0, 1, 3), firstSecondFourth); exclusives.put(toImmutableBitSet(0, 2, 3), firstThirdFourth); exclusives.put(toImmutableBitSet(1, 2, 3), secondThirdFourth); exclusives.put(toImmutableBitSet(0, 1, 2, 3), intersection); }
From source file:grakn.core.graql.reasoner.plan.QueryCollectionBase.java
/** * @param entryQuery query for which candidates are to be determined * @param plan current plan//from ww w . j ava 2 s.c o m * @return set of candidate queries for this query */ public QuerySet getCandidates(ReasonerQueryImpl entryQuery, QueryList plan) { Equivalence.Wrapper<ReasonerQueryImpl> query = equality().wrap(entryQuery); Set<Equivalence.Wrapper<ReasonerQueryImpl>> availableQueries = this.wrappedStream() .filter(q -> !(plan.contains(q) || q.equals(query))).collect(Collectors.toSet()); Set<Equivalence.Wrapper<ReasonerQueryImpl>> availableImmediateNeighbours = this .getImmediateNeighbours(query).stream().filter(availableQueries::contains) .collect(Collectors.toSet()); Set<Variable> subbedVars = plan.stream().flatMap(q -> q.getVarNames().stream()).collect(Collectors.toSet()); Set<Equivalence.Wrapper<ReasonerQueryImpl>> availableImmediateNeighboursFromSubs = availableQueries.stream() .map(Equivalence.Wrapper::get).filter(Objects::nonNull) .filter(q -> !Sets.intersection(q.getVarNames(), subbedVars).isEmpty()).map(q -> equality().wrap(q)) .collect(Collectors.toSet()); return QuerySet.create(this.isQueryDisconnected(query) ? availableQueries : this.isQueryReachable(query, availableQueries) ? Sets.union(availableImmediateNeighbours, availableImmediateNeighboursFromSubs) : availableQueries); }
From source file:co.mitro.core.servlets.AddPendingGroupServlet.java
/** * Too many inout parameters.// ww w . j a v a 2s . c om * TODO: change this to use a parameter object * @param context in * @param pendingGroupsList in * @param org in * @param existingGroups in/out * @param diffs in/out * @param pendingGroupMap in/out * @return the scope */ public static void calculatePendingGroupDiffs(MitroRequestContext context, Collection<? extends PendingGroup> pendingGroupsList, DBGroup org, Map<String, DBGroup> existingGroups, Map<String, GroupDiff> diffs, Map<String, MemberList> pendingGroupMap, String scope) throws MitroServletException, SQLException { assert scope != null || pendingGroupsList.isEmpty(); for (PendingGroup pg : pendingGroupsList) { AddPendingGroupRequest.MemberList ml = gson.fromJson(pg.memberListJson, AddPendingGroupRequest.MemberList.class); assert (null != ml) : "you cannot have a null MemberList"; for (String user : ml.memberList) { assert Util.isEmailAddress(user) : "invalid email: '" + user + "'"; } pendingGroupMap.put(pg.groupName, ml); } for (DBGroup g : org.getAllOrgGroups(context.manager)) { if (scope != null && scope.equals(g.getScope())) { existingGroups.put(g.getName(), g); } } Set<String> allGroupNames = Sets.union(pendingGroupMap.keySet(), existingGroups.keySet()); for (String groupName : allGroupNames) { diffGroupPair(context, diffs, groupName, existingGroups.get(groupName), pendingGroupMap.get(groupName)); } }
From source file:com.facebook.buck.apple.xcode.WorkspaceAndProjectGenerator.java
public Path generateWorkspaceAndDependentProjects(Map<TargetNode<?>, ProjectGenerator> projectGenerators) throws IOException { LOG.debug("Generating workspace for target %s", workspaceTargetNode); String workspaceName;//from ww w .j a v a 2s . c om Path outputDirectory; if (combinedProject) { workspaceName = "GeneratedProject"; outputDirectory = Paths.get("_gen"); } else { workspaceName = XcodeWorkspaceConfigDescription .getWorkspaceNameFromArg(workspaceTargetNode.getConstructorArg()); outputDirectory = workspaceTargetNode.getBuildTarget().getBasePath(); } WorkspaceGenerator workspaceGenerator = new WorkspaceGenerator(projectFilesystem, workspaceName, outputDirectory); ImmutableSet<TargetNode<?>> orderedTargetNodes; if (workspaceTargetNode.getConstructorArg().srcTarget.isPresent()) { orderedTargetNodes = AppleBuildRules.getSchemeBuildableTargetNodes(projectGraph, projectGraph.get(workspaceTargetNode.getConstructorArg().srcTarget.get().getBuildTarget())); } else { orderedTargetNodes = ImmutableSet.of(); } ImmutableSet<TargetNode<?>> orderedTestTargetNodes; ImmutableSet<TargetNode<?>> orderedTestBundleTargetNodes; { ImmutableSet.Builder<TargetNode<?>> orderedTestTargetNodesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<TargetNode<?>> orderedTestBundleTargetNodesBuilder = ImmutableSet.builder(); getOrderedTestNodes(projectGraph, sourceTargetToTestNodes, orderedTargetNodes, extraTestBundleTargetNodes, orderedTestTargetNodesBuilder, orderedTestBundleTargetNodesBuilder); orderedTestTargetNodes = orderedTestTargetNodesBuilder.build(); orderedTestBundleTargetNodes = orderedTestBundleTargetNodesBuilder.build(); } ImmutableSet<BuildTarget> targetsInRequiredProjects = FluentIterable .from(Sets.union(orderedTargetNodes, orderedTestTargetNodes)).transform(HasBuildTarget.TO_TARGET) .toSet(); ImmutableMap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder = ImmutableMap.builder(); ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder(); if (combinedProject) { ImmutableSet.Builder<BuildTarget> initialTargetsBuilder = ImmutableSet.builder(); for (TargetNode<?> targetNode : projectGraph.getNodes()) { if (targetNode.getType() != XcodeProjectConfigDescription.TYPE) { continue; } XcodeProjectConfigDescription.Arg projectArg = (XcodeProjectConfigDescription.Arg) targetNode .getConstructorArg(); if (Sets.intersection(targetsInRequiredProjects, projectArg.rules).isEmpty()) { continue; } initialTargetsBuilder.addAll(projectArg.rules); } LOG.debug("Generating a combined project"); ProjectGenerator generator = new ProjectGenerator(projectGraph, initialTargetsBuilder.build(), projectFilesystem, executionContext, buildRuleResolver, sourcePathResolver, outputDirectory, "GeneratedProject", projectGeneratorOptions); combinedProjectGenerator = Optional.of(generator); generator.createXcodeProjects(); workspaceGenerator.addFilePath(generator.getProjectPath()); buildTargetToPbxTargetMapBuilder.putAll(generator.getBuildTargetToGeneratedTargetMap()); for (PBXTarget target : generator.getBuildTargetToGeneratedTargetMap().values()) { targetToProjectPathMapBuilder.put(target, generator.getProjectPath()); } } else { for (TargetNode<?> targetNode : projectGraph.getNodes()) { if (targetNode.getType() != XcodeProjectConfigDescription.TYPE) { continue; } XcodeProjectConfigDescription.Arg projectArg = (XcodeProjectConfigDescription.Arg) targetNode .getConstructorArg(); if (Sets.intersection(targetsInRequiredProjects, projectArg.rules).isEmpty()) { continue; } ProjectGenerator generator = projectGenerators.get(targetNode); if (generator == null) { LOG.debug("Generating project for target %s", targetNode); generator = new ProjectGenerator(projectGraph, projectArg.rules, projectFilesystem, executionContext, buildRuleResolver, sourcePathResolver, targetNode.getBuildTarget().getBasePath(), projectArg.projectName, projectGeneratorOptions); generator.createXcodeProjects(); projectGenerators.put(targetNode, generator); } else { LOG.debug("Already generated project for target %s, skipping", targetNode); } workspaceGenerator.addFilePath(generator.getProjectPath()); buildTargetToPbxTargetMapBuilder.putAll(generator.getBuildTargetToGeneratedTargetMap()); for (PBXTarget target : generator.getBuildTargetToGeneratedTargetMap().values()) { targetToProjectPathMapBuilder.put(target, generator.getProjectPath()); } } } Path workspacePath = workspaceGenerator.writeWorkspace(); SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, workspaceTargetNode.getConstructorArg().srcTarget, Iterables.transform(orderedTargetNodes, HasBuildTarget.TO_TARGET), Iterables.transform(orderedTestTargetNodes, HasBuildTarget.TO_TARGET), Iterables.transform(orderedTestBundleTargetNodes, HasBuildTarget.TO_TARGET), workspaceName, outputDirectory.resolve(workspaceName + ".xcworkspace"), XcodeWorkspaceConfigDescription .getActionConfigNamesFromArg(workspaceTargetNode.getConstructorArg()), buildTargetToPbxTargetMapBuilder.build(), targetToProjectPathMapBuilder.build()); schemeGenerator.writeScheme(); return workspacePath; }
From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java
private static ImMap<Name, Set<Type>> mergeBreakValueTypes(ImMap<Name, Set<Type>> left, ImMap<Name, Set<Type>> right) { for (Map.Entry<Name, Set<Type>> entry : right.entrySet()) { left = left.assoc(entry.getKey(), immutableEnumSet( Sets.union(right.getOrElse(entry.getKey(), ImmutableSet.of()), entry.getValue()))); }/*ww w .j a va 2 s. c o m*/ return left; }
From source file:org.apache.guacamole.auth.jdbc.user.ModeledAuthenticatedUser.java
@Override public Set<String> getEffectiveUserGroups() { return Sets.union(user.getEffectiveUserGroups(), super.getEffectiveUserGroups()); }
From source file:org.tensorics.core.tensor.Shapes.java
/** * Constructs a shape that contains all positions resulting from the outer product of the positions of the left * shape with those of the right shape. It is required that the two shapes have no overlap of dimensions (i.e. none * of the dimensions in the left shape are available in the right and vice versa). * // www . j ava2s . co m * @param left the left shape to use for the outer product * @param right the right shape to use for the outer product * @return a shape containing positions constructed from all combinations of the left positions with the right * positions. * @throws NullPointerException if one of the arguments is null * @throws IllegalArgumentException if the two shapes have overlapping dimensions */ public static Shape outerProduct(Shape left, Shape right) { checkArgument(dimensionalIntersection(left, right).isEmpty(), "The two shapes have " + "overlapping dimensions. The outer product is not foreseen to be used in this situation."); Shape.Builder builder = Shape.builder(Sets.union(left.dimensionSet(), right.dimensionSet())); for (Position leftPosition : left.positionSet()) { for (Position rightPosition : right.positionSet()) { builder.add(Positions.union(leftPosition, rightPosition)); } } return builder.build(); }
From source file:org.codice.ddf.admin.security.ldap.ServerGuesser.java
private SortedSet<String> extractAttributes(Collection<ObjectClass> objectClasses, Predicate<ObjectClass> predicate) { return objectClasses.stream().filter(predicate) .flatMap(oc -> Sets.union(oc.getRequiredAttributes(), oc.getOptionalAttributes()).stream()) .map(AttributeType::getNameOrOID).collect(Collectors.toCollection(TreeSet::new)); }
From source file:org.caleydo.view.crossword.api.model.TypedSet.java
private static int or(BitSetSet a, Set<Integer> b) { if (b instanceof BitSetSet) { BitSet clone = (BitSet) a.getBitSet().clone(); clone.or(((BitSetSet) b).getBitSet()); return clone.cardinality(); }//from w w w. j a va 2 s. com return Sets.union(b, a).size(); // as the predicate is: in the second argument }
From source file:com.facebook.presto.sql.planner.iterative.rule.InlineProjections.java
private Sets.SetView<Symbol> extractInliningTargets(ProjectNode parent, ProjectNode child) { // candidates for inlining are // 1. references to simple constants // 2. references to complex expressions that // a. are not inputs to try() expressions // b. appear only once across all expressions // c. are not identity projections // which come from the child, as opposed to an enclosing scope. Set<Symbol> childOutputSet = ImmutableSet.copyOf(child.getOutputSymbols()); Map<Symbol, Long> dependencies = parent.getAssignments().getExpressions().stream() .flatMap(expression -> SymbolsExtractor.extractAll(expression).stream()) .filter(childOutputSet::contains) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); // find references to simple constants Set<Symbol> constants = dependencies.keySet().stream() .filter(input -> child.getAssignments().get(input) instanceof Literal).collect(toSet()); // exclude any complex inputs to TRY expressions. Inlining them would potentially // change the semantics of those expressions Set<Symbol> tryArguments = parent.getAssignments().getExpressions().stream() .flatMap(expression -> extractTryArguments(expression).stream()).collect(toSet()); Set<Symbol> singletons = dependencies.entrySet().stream().filter(entry -> entry.getValue() == 1) // reference appears just once across all expressions in parent project node .filter(entry -> !tryArguments.contains(entry.getKey())) // they are not inputs to TRY. Otherwise, inlining might change semantics .filter(entry -> !child.getAssignments().isIdentity(entry.getKey())) // skip identities, otherwise, this rule will keep firing forever .map(Map.Entry::getKey).collect(toSet()); return Sets.union(singletons, constants); }