List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:org.apache.flex.compiler.internal.css.semantics.CSSSemanticAnalyzer.java
/** * Find all the class definitions in the given collection. * /*from w w w.j a v a 2s . com*/ * @param definitions A collection of definitions. * @return A set of class definitions. */ public static ImmutableSet<IClassDefinition> getClassDefinitionSet(final Collection<IDefinition> definitions) { final ImmutableSet.Builder<IClassDefinition> builder = new ImmutableSet.Builder<IClassDefinition>(); for (final IDefinition def : definitions) { if (def instanceof IClassDefinition) builder.add((IClassDefinition) def); } final ImmutableSet<IClassDefinition> classDefinitions = builder.build(); return classDefinitions; }
From source file:org.opendaylight.controller.cluster.datastore.node.NodeToNormalizedNodeBuilder.java
/** * Create an AugmentationIdentifier based on the AugmentationSchema * * @param augmentation//ww w . j av a 2 s .c o m * @return */ public static AugmentationIdentifier augmentationIdentifierFrom(final AugmentationSchema augmentation) { ImmutableSet.Builder<QName> potentialChildren = ImmutableSet.builder(); for (DataSchemaNode child : augmentation.getChildNodes()) { potentialChildren.add(child.getQName()); } return new AugmentationIdentifier(potentialChildren.build()); }
From source file:com.facebook.buck.cxx.toolchain.CxxBuckConfig.java
/** * Constructs set of flavors given in a .buckconfig file, as is specified by section names of the * form cxx#{flavor name}.//from w w w. j a v a 2 s .c o m */ public static ImmutableSet<Flavor> getCxxFlavors(BuckConfig config) { ImmutableSet.Builder<Flavor> builder = ImmutableSet.builder(); ImmutableSet<String> sections = config.getSections(); for (String section : sections) { if (section.startsWith(FLAVORED_CXX_SECTION_PREFIX)) { builder.add(InternalFlavor.of(section.substring(FLAVORED_CXX_SECTION_PREFIX.length()))); } } return builder.build(); }
From source file:com.facebook.presto.server.protocol.Query.java
private static Set<String> globalUniqueNodes(StageInfo stageInfo) { if (stageInfo == null) { return ImmutableSet.of(); }// w ww .ja v a2 s . c om ImmutableSet.Builder<String> nodes = ImmutableSet.builder(); for (TaskInfo task : stageInfo.getTasks()) { // todo add nodeId to TaskInfo URI uri = task.getTaskStatus().getSelf(); nodes.add(uri.getHost() + ":" + uri.getPort()); } for (StageInfo subStage : stageInfo.getSubStages()) { nodes.addAll(globalUniqueNodes(subStage)); } return nodes.build(); }
From source file:com.android.tools.idea.editors.theme.ColorUtils.java
/** * @param styleAttributeName the name of a style attribute we want to check for contrast issues * Returns the set of {@link ItemResourceValue} that have to be checked in the current theme for contrast against a particular attribute. *///from w ww. j a v a 2s . c o m @NotNull public static ImmutableSet<ItemResourceValue> getContrastItems(@NotNull ThemeEditorContext context, @NotNull String styleAttributeName) { Set<String> contrastColorSet = CONTRAST_MAP.get(styleAttributeName); if (contrastColorSet == null) { return ImmutableSet.of(); } ImmutableSet.Builder<ItemResourceValue> contrastItemsBuilder = ImmutableSet.builder(); ConfiguredThemeEditorStyle currentTheme = context.getCurrentTheme(); assert currentTheme != null; for (String contrastColor : contrastColorSet) { ItemResourceValue contrastItem = ThemeEditorUtils.resolveItemFromParents(currentTheme, contrastColor, false); if (contrastItem == null) { contrastItem = ThemeEditorUtils.resolveItemFromParents(currentTheme, contrastColor, true); } if (contrastItem != null) { contrastItemsBuilder.add(contrastItem); } } return contrastItemsBuilder.build(); }
From source file:edu.mit.streamjit.util.bytecode.DeadCodeElimination.java
/** * Finds all the non-phi values that might be the result of the given * PhiInst. This will look through intermediate PhiInsts in the hope that * they all can only select one value./*from w w w . j a v a2 s . c o m*/ * @param inst the phi instruction to find sources of * @return a list of the non-phi values that might be the result */ private static ImmutableSet<Value> phiSources(PhiInst inst) { Queue<PhiInst> worklist = new ArrayDeque<>(); Set<PhiInst> visited = Collections.newSetFromMap(new IdentityHashMap<PhiInst, Boolean>()); ImmutableSet.Builder<Value> builder = ImmutableSet.builder(); worklist.add(inst); visited.add(inst); while (!worklist.isEmpty()) { PhiInst pi = worklist.remove(); for (Value v : pi.incomingValues()) if (v instanceof PhiInst && !visited.contains((PhiInst) v)) { visited.add((PhiInst) v); worklist.add((PhiInst) v); } else if (!(v instanceof PhiInst)) builder.add(v); } return builder.build(); }
From source file:com.facebook.buck.cli.ExopackageInstaller.java
/** * @param output Output of "ls" command. * @param requiredHashes Hashes of dex files required for this apk. * @param foundHashesBuilder Builder to receive hashes that we need and were found. * @param toDeleteBuilder Builder to receive files that we need to delete. *//* ww w .j a va 2s . com*/ @VisibleForTesting static void scanSecondaryDexDir(String output, ImmutableSet<String> requiredHashes, ImmutableSet.Builder<String> foundHashesBuilder, ImmutableSet.Builder<String> toDeleteBuilder) { Pattern dexFilePattern = Pattern.compile("secondary-([0-9a-f]+)\\.[\\w.-]*"); for (String line : Splitter.on("\r\n").split(output)) { if (line.equals("metadata.txt") || line.startsWith(AgentUtil.TEMP_PREFIX)) { toDeleteBuilder.add(line); continue; } Matcher m = dexFilePattern.matcher(line); if (m.matches()) { if (requiredHashes.contains(m.group(1))) { foundHashesBuilder.add(m.group(1)); } else { toDeleteBuilder.add(line); } } } }
From source file:com.facebook.presto.cassandra.CassandraSplitManager.java
private static Set<List<Object>> getPartitionKeysSet(CassandraTable table, TupleDomain<ColumnHandle> tupleDomain) { ImmutableList.Builder<Set<Object>> partitionColumnValues = ImmutableList.builder(); for (CassandraColumnHandle columnHandle : table.getPartitionKeyColumns()) { Domain domain = tupleDomain.getDomains().get().get(columnHandle); // if there is no constraint on a partition key, return an empty set if (domain == null) { return ImmutableSet.of(); }/*from w w w. j a v a2s. com*/ // todo does cassandra allow null partition keys? if (domain.isNullAllowed()) { return ImmutableSet.of(); } Set<Object> values = domain.getValues().getValuesProcessor().transform(ranges -> { ImmutableSet.Builder<Object> columnValues = ImmutableSet.builder(); for (Range range : ranges.getOrderedRanges()) { // if the range is not a single value, we can not perform partition pruning if (!range.isSingleValue()) { return ImmutableSet.of(); } Object value = range.getSingleValue(); CassandraType valueType = columnHandle.getCassandraType(); columnValues.add(valueType.validatePartitionKey(value)); } return columnValues.build(); }, discreteValues -> { if (discreteValues.isWhiteList()) { return ImmutableSet.copyOf(discreteValues.getValues()); } return ImmutableSet.of(); }, allOrNone -> ImmutableSet.of()); partitionColumnValues.add(values); } return Sets.cartesianProduct(partitionColumnValues.build()); }
From source file:com.facebook.buck.android.UnsortedAndroidResourceDeps.java
/** * Returns transitive android resource deps which are _not_ sorted topologically, only to be used * when the order of the resource rules does not matter, for instance, when graph enhancing * UberRDotJava, DummyRDotJava, AaptPackageResources where we only need the deps to correctly * order the execution of those buildables. *///from ww w .ja v a 2s . c o m public static UnsortedAndroidResourceDeps createFrom(Collection<BuildRule> rules, final Optional<Callback> callback) { final ImmutableSet.Builder<HasAndroidResourceDeps> androidResources = ImmutableSet.builder(); // This visitor finds all AndroidResourceRules that are reachable from the specified rules via // rules with types in the TRAVERSABLE_TYPES collection. AbstractBreadthFirstTraversal<BuildRule> visitor = new AbstractBreadthFirstTraversal<BuildRule>(rules) { @Override public ImmutableSet<BuildRule> visit(BuildRule rule) { HasAndroidResourceDeps androidResourceRule = null; if (rule instanceof HasAndroidResourceDeps) { androidResourceRule = (HasAndroidResourceDeps) rule; } if (androidResourceRule != null && androidResourceRule.getRes() != null) { androidResources.add(androidResourceRule); } // Only certain types of rules should be considered as part of this traversal. ImmutableSet<BuildRule> depsToVisit = BuildRuleDependencyVisitors.maybeVisitAllDeps(rule, TRAVERSABLE_TYPES.contains(rule.getClass())); if (callback.isPresent()) { callback.get().onRuleVisited(rule, depsToVisit); } return depsToVisit; } }; visitor.start(); return new UnsortedAndroidResourceDeps(androidResources.build()); }
From source file:com.facebook.buck.java.DefaultJavaPackageFinder.java
/** * @param pathPatterns elements that start with a slash must be prefix patterns; all other * elements indicate individual directory names (and therefore cannot contain slashes). *//*from w ww . j ava 2 s .com*/ public static DefaultJavaPackageFinder createDefaultJavaPackageFinder(Iterable<String> pathPatterns) { ImmutableSortedSet.Builder<String> pathsFromRoot = ImmutableSortedSet.reverseOrder(); ImmutableSet.Builder<String> pathElements = ImmutableSet.builder(); for (String pattern : pathPatterns) { if (pattern.charAt(0) == '/') { // Strip the leading slash. pattern = pattern.substring(1); // Ensure there is a trailing slash, unless it is an empty string. if (!pattern.isEmpty() && !pattern.endsWith("/")) { pattern = pattern + "/"; } pathsFromRoot.add(pattern); } else { if (pattern.contains("/")) { throw new HumanReadableException( "Path pattern that does not start with a slash cannot contain a slash: %s", pattern); } pathElements.add(pattern); } } return new DefaultJavaPackageFinder(pathsFromRoot.build(), pathElements.build()); }