List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:com.sun.tools.hat.internal.util.Misc.java
public static ImmutableSet<JavaHeapObject> getReferrers(Iterable<JavaHeapObject> instances) { ImmutableSet.Builder<JavaHeapObject> builder = ImmutableSet.builder(); for (JavaHeapObject instance : instances) { builder.addAll(instance.getReferers()); }//from ww w .j a v a 2 s . c o m return builder.build(); }
From source file:org.apache.beam.runners.core.construction.graph.GreedyStageFuser.java
/** * Returns an {@link ExecutableStage} where the initial {@link PTransformNode PTransform} is a * Remote gRPC Port Read, reading elements from the materialized {@link PCollectionNode * PCollection}./* ww w . jav a2s . c o m*/ * * @param initialNodes the initial set of sibling transforms to fuse into this node. All of the * transforms must consume the {@code inputPCollection} on a per-element basis, and must all * be mutually compatible. */ public static ExecutableStage forGrpcPortRead(QueryablePipeline pipeline, PCollectionNode inputPCollection, Set<PTransformNode> initialNodes) { checkArgument(!initialNodes.isEmpty(), "%s must contain at least one %s.", GreedyStageFuser.class.getSimpleName(), PTransformNode.class.getSimpleName()); // Choose the environment from an arbitrary node. The initial nodes may not be empty for this // subgraph to make any sense, there has to be at least one processor node // (otherwise the stage is gRPC Read -> gRPC Write, which doesn't do anything). Environment environment = getStageEnvironment(pipeline, initialNodes); ImmutableSet.Builder<PTransformNode> fusedTransforms = ImmutableSet.builder(); fusedTransforms.addAll(initialNodes); Set<SideInputReference> sideInputs = new LinkedHashSet<>(); Set<UserStateReference> userStates = new LinkedHashSet<>(); Set<TimerReference> timers = new LinkedHashSet<>(); Set<PCollectionNode> fusedCollections = new LinkedHashSet<>(); Set<PCollectionNode> materializedPCollections = new LinkedHashSet<>(); Queue<PCollectionNode> fusionCandidates = new ArrayDeque<>(); for (PTransformNode initialConsumer : initialNodes) { fusionCandidates.addAll(pipeline.getOutputPCollections(initialConsumer)); sideInputs.addAll(pipeline.getSideInputs(initialConsumer)); userStates.addAll(pipeline.getUserStates(initialConsumer)); timers.addAll(pipeline.getTimers(initialConsumer)); } while (!fusionCandidates.isEmpty()) { PCollectionNode candidate = fusionCandidates.poll(); if (fusedCollections.contains(candidate) || materializedPCollections.contains(candidate)) { // This should generally mean we get to a Flatten via multiple paths through the graph and // we've already determined what to do with the output. LOG.debug("Skipping fusion candidate {} because it is {} in this {}", candidate, fusedCollections.contains(candidate) ? "fused" : "materialized", ExecutableStage.class.getSimpleName()); continue; } PCollectionFusibility fusibility = canFuse(pipeline, candidate, environment, fusedCollections); switch (fusibility) { case MATERIALIZE: materializedPCollections.add(candidate); break; case FUSE: // All of the consumers of the candidate PCollection can be fused into this stage. Do so. fusedCollections.add(candidate); fusedTransforms.addAll(pipeline.getPerElementConsumers(candidate)); for (PTransformNode consumer : pipeline.getPerElementConsumers(candidate)) { // The outputs of every transform fused into this stage must be either materialized or // themselves fused away, so add them to the set of candidates. fusionCandidates.addAll(pipeline.getOutputPCollections(consumer)); sideInputs.addAll(pipeline.getSideInputs(consumer)); } break; default: throw new IllegalStateException(String.format("Unknown type of %s %s", PCollectionFusibility.class.getSimpleName(), fusibility)); } } return ImmutableExecutableStage.ofFullComponents(pipeline.getComponents(), environment, inputPCollection, sideInputs, userStates, timers, fusedTransforms.build(), materializedPCollections); }
From source file:com.sun.tools.hat.internal.util.Misc.java
public static ImmutableSet<JavaHeapObject> getReferrers(Iterable<JavaHeapObject> instances, Predicate<JavaHeapObject> filter) { ImmutableSet.Builder<JavaHeapObject> builder = ImmutableSet.builder(); for (JavaHeapObject instance : instances) { builder.addAll(Sets.filter(instance.getReferers(), filter)); }// www . j a v a 2 s . co m return builder.build(); }
From source file:edu.mit.streamjit.util.CollectionUtils.java
/** * Returns the union of the given maps, using the given function to merge * values for the same key. The function is called for all keys with a list * of the values of the maps in the order the maps were given. Maps that do * not contain the key are not represented in the list. The function's * return value is used as the value in the union map. * TODO: the generics don't seem right here; I should be able to use e.g. * a Collection<Comparable> in place of List<Integer> for the middle arg. * Note that the above overload permits that and forwards to this one! * @param <K> the key type of the returned map * @param <V> the value type of the returned map * @param <X> the value type of the input map(s) * @param merger the function used to merge values for the same key * @param maps the maps/*from w w w . j av a 2s . c o m*/ * @return a map containing all the keys in the given maps */ public static <K, V, X> ImmutableMap<K, V> union( Maps.EntryTransformer<? super K, ? super List<X>, ? extends V> merger, List<? extends Map<? extends K, ? extends X>> maps) { ImmutableSet.Builder<K> keys = ImmutableSet.builder(); for (Map<? extends K, ? extends X> m : maps) keys.addAll(m.keySet()); ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); for (K k : keys.build()) { ImmutableList.Builder<X> values = ImmutableList.builder(); for (Map<? extends K, ? extends X> m : maps) if (m.containsKey(k)) values.add(m.get(k)); builder.put(k, merger.transformEntry(k, values.build())); } return builder.build(); }
From source file:com.spectralogic.ds3contractcomparator.print.htmlprinter.generators.row.ModifiedHtmlRowGenerator.java
/** * Creates a union of all values for the specified property in both lists of objects *//*from w w w .ja va 2 s. c o m*/ static <T> ImmutableSet<String> toPropertyUnion(final ImmutableList<T> oldList, final ImmutableList<T> newList, final String property) { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); builder.addAll(getPropertyValues(oldList, property)); builder.addAll(getPropertyValues(newList, property)); return builder.build(); }
From source file:com.google.idea.blaze.base.lang.buildfile.language.semantics.BuiltInNamesProvider.java
/** Returns all built-in global symbols and function names. */ public static ImmutableSet<String> getBuiltInNames(Project project) { ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder().addAll(GLOBALS).addAll(FUNCTIONS); BuildLanguageSpec spec = BuildLanguageSpecProvider.getInstance().getLanguageSpec(project); if (spec != null) { builder = builder.addAll(spec.getKnownRuleNames()); }// www . ja va 2 s . c o m return builder.build(); }
From source file:com.google.errorprone.bugpatterns.StaticImports.java
/** * Looks for a field or method with the given {@code identifier}, in * @code typeSym} or one of it's super-types or super-interfaces, * and that is visible from the {@code start} symbol. *//*w w w. ja va 2 s . co m*/ // TODO(cushon): does javac really not expose this anywhere? // // Resolve.resolveInternal{Method,Field} almost work, but we don't want // to filter on method signature. private static ImmutableSet<Symbol> lookup(Symbol.TypeSymbol typeSym, Symbol.TypeSymbol start, Name identifier, Types types, Symbol.PackageSymbol pkg) { if (typeSym == null) { return ImmutableSet.of(); } ImmutableSet.Builder<Symbol> members = ImmutableSet.builder(); members.addAll(lookup(types.supertype(typeSym.type).tsym, start, identifier, types, pkg)); for (Type i : types.interfaces(typeSym.type)) { members.addAll(lookup(i.tsym, start, identifier, types, pkg)); } OUTER: for (Symbol member : typeSym.members().getSymbolsByName(identifier)) { if (!member.isStatic()) { continue; } switch ((int) (member.flags() & Flags.AccessFlags)) { case Flags.PUBLIC: break; case Flags.PRIVATE: continue OUTER; case 0: case Flags.PROTECTED: if (member.packge() != pkg) { continue OUTER; } default: break; } if (member.isMemberOf(start, types)) { members.add(member); } } return members.build(); }
From source file:com.spotify.heroic.metadata.FindSeries.java
public static Collector<FindSeries, FindSeries> reduce(final OptionalLimit limit) { return results -> { final List<RequestError> errors = new ArrayList<>(); final ImmutableSet.Builder<Series> series = ImmutableSet.builder(); boolean limited = false; for (final FindSeries result : results) { errors.addAll(result.errors); series.addAll(result.series); limited |= result.limited;/*from w w w . ja va 2s .c om*/ } final Set<Series> s = series.build(); return new FindSeries(errors, limit.limitSet(s), limited || limit.isGreater(s.size())); }; }
From source file:com.spotify.heroic.metadata.FindSeriesIds.java
public static Collector<FindSeriesIds, FindSeriesIds> reduce(final OptionalLimit limit) { return results -> { final List<RequestError> errors = new ArrayList<>(); final ImmutableSet.Builder<String> ids = ImmutableSet.builder(); boolean limited = false; for (final FindSeriesIds result : results) { errors.addAll(result.errors); ids.addAll(result.ids); limited |= result.limited;//from ww w . j ava2 s . c o m } final Set<String> s = ids.build(); return new FindSeriesIds(errors, limit.limitSet(s), limited || limit.isGreater(s.size())); }; }
From source file:com.facebook.presto.sql.planner.optimizations.WindowNodeUtil.java
public static Set<Symbol> extractWindowFunctionUnique(WindowNode.Function function) { ImmutableSet.Builder<Symbol> builder = ImmutableSet.builder(); for (RowExpression argument : function.getFunctionCall().getArguments()) { if (isExpression(argument)) { builder.addAll(SymbolsExtractor.extractAll(castToExpression(argument))); } else {//from w w w . j a va2 s . c om builder.addAll(SymbolsExtractor.extractAll(argument).stream() .map(variable -> new Symbol(variable.getName())).collect(toImmutableSet())); } } return builder.build(); }