List of usage examples for com.google.common.collect ImmutableSet builder
public static <E> Builder<E> builder()
From source file:com.spotify.heroic.common.FeatureSet.java
@JsonCreator public static FeatureSet create(final Set<String> features) { final ImmutableSet.Builder<Feature> enabled = ImmutableSet.builder(); final ImmutableSet.Builder<Feature> disabled = ImmutableSet.builder(); for (final String feature : features) { if (feature.startsWith("-")) { disabled.add(Feature.create(feature.substring(1))); } else {//from ww w. ja v a 2 s. c o m enabled.add(Feature.create(feature)); } } return new FeatureSet(enabled.build(), disabled.build()); }
From source file:org.apache.shindig.social.opensocial.model.EnumUtil.java
/** * * @param vals array of enums//from w ww . j a v a 2 s . co m * @return a set of the names for a list of Enum values defined by toString */ // TODO: Because we have a Enum interface in this package we have to explicitly state the java.lang.Enum (bad ?) public static Set<String> getEnumStrings(java.lang.Enum<?>... vals) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (java.lang.Enum<?> v : vals) { builder.add(v.toString()); } Set<String> result = builder.build(); Preconditions.checkArgument(result.size() == vals.length, "Enum names are not disjoint set"); return result; }
From source file:com.facebook.buck.features.project.intellij.aggregation.ModuleAggregator.java
@SuppressWarnings("rawtypes") // https://github.com/immutables/immutables/issues/548 requires us to use // TargetNode not TargetNode<?> public static AggregationModule aggregate(AggregationModule rootModule, Collection<AggregationModule> modulesToAggregate) { ImmutableSet.Builder<TargetNode> targets = ImmutableSet.<TargetNode>builder() .addAll(rootModule.getTargets()); modulesToAggregate.forEach(module -> targets.addAll(module.getTargets())); ImmutableSet.Builder<Path> excludesBuilder = ImmutableSet.builder(); modulesToAggregate.forEach(module -> { Path modulePath = rootModule.getModuleBasePath().relativize(module.getModuleBasePath()); module.getExcludes().stream().map(modulePath::resolve).forEach(excludesBuilder::add); });//www . j av a 2 s. c o m return AggregationModule.builder().from(rootModule).addAllTargets(targets.build()) .setExcludes(excludesBuilder.build()).build(); }
From source file:com.spectralogic.ds3autogen.utils.collections.GuavaCollectors.java
/** Collect a stream of elements into an {@link ImmutableSet}. */ public static <T> Collector<T, ImmutableSet.Builder<T>, ImmutableSet<T>> immutableSet() { return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, (l, r) -> l.addAll(r.build()), ImmutableSet.Builder<T>::build, UNORDERED); }
From source file:com.facebook.buck.dalvik.firstorder.FirstOrderHelper.java
public static void addTypesAndDependencies(Iterable<Type> scenarioTypes, Iterable<ClassNode> allClasses, ImmutableSet.Builder<String> classNamesBuilder) { FirstOrderHelper helper = new FirstOrderHelper(scenarioTypes, classNamesBuilder); helper.addDependencies(allClasses);/* w w w.ja v a2 s .com*/ }
From source file:com.google.template.soy.jssrc.dsl.MapLiteral.java
static MapLiteral create(ImmutableList<? extends CodeChunk.WithValue> keys, ImmutableList<? extends CodeChunk.WithValue> values) { Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values."); ImmutableSet.Builder<CodeChunk> initialStatements = ImmutableSet.builder(); for (CodeChunk.WithValue key : keys) { initialStatements.addAll(key.initialStatements()); }/* ww w. ja va2s .com*/ for (CodeChunk.WithValue value : values) { initialStatements.addAll(value.initialStatements()); } return new AutoValue_MapLiteral(initialStatements.build(), keys, values); }
From source file:org.trancecode.collection.TcSets.java
public static <T> ImmutableSet<T> immutableSet(final Iterable<T> set, final T element) { Preconditions.checkNotNull(set);/* ww w. ja v a 2 s . com*/ Preconditions.checkNotNull(element); if (set instanceof Set && ((Set<?>) set).contains(element)) { return ImmutableSet.copyOf(set); } final Builder<T> builder = ImmutableSet.builder(); return builder.addAll(set).add(element).build(); }
From source file:com.google.idea.blaze.base.util.WorkspacePathUtil.java
/** Removes any duplicates or overlapping directories */ public static ImmutableSet<WorkspacePath> calculateMinimalWorkspacePaths( Collection<WorkspacePath> workspacePaths) { ImmutableSet.Builder<WorkspacePath> minimalWorkspacePaths = ImmutableSet.builder(); for (WorkspacePath directory : workspacePaths) { boolean ok = true; for (WorkspacePath otherDirectory : workspacePaths) { if (directory.equals(otherDirectory)) { continue; }//from w ww .ja v a 2 s .co m if (FileUtil.isAncestor(otherDirectory.relativePath(), directory.relativePath(), true)) { ok = false; break; } } if (ok) { minimalWorkspacePaths.add(directory); } } return minimalWorkspacePaths.build(); }
From source file:com.facebook.buck.io.file.FileFinder.java
/** * Combines prefixes, base, and suffixes to create a set of file names. * * @param prefixes set of prefixes. May be empty. * @param base base name. May be empty./*w ww . j a v a 2s . com*/ * @param suffixes set of suffixes. May be empty. * @return a set containing all combinations of prefix, base, and suffix. */ public static ImmutableSet<String> combine(Set<String> prefixes, String base, Set<String> suffixes) { ImmutableSet<String> suffixedSet; if (suffixes.isEmpty()) { suffixedSet = ImmutableSet.of(base); } else { ImmutableSet.Builder<String> suffixedBuilder = ImmutableSet.builder(); for (String suffix : suffixes) { suffixedBuilder.add(base + suffix); } suffixedSet = suffixedBuilder.build(); } if (prefixes.isEmpty()) { return suffixedSet; } else { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (String prefix : prefixes) { for (String suffix : suffixedSet) { builder.add(prefix + suffix); } } return builder.build(); } }
From source file:com.google.template.soy.soyparse.ParseErrors.java
static void reportSoyFileParseException(ErrorReporter reporter, String filePath, ParseException e) { // currentToken is the 'last successfully consumed token', but the error is usually due to the // first unsuccessful token. use that for the source location Token errorToken = e.currentToken;/*from w ww .j a v a 2 s .co m*/ if (errorToken.next != null) { errorToken = errorToken.next; } ImmutableSet.Builder<String> expectedTokenImages = ImmutableSet.builder(); for (int[] expected : e.expectedTokenSequences) { // We only display the first token expectedTokenImages.add(getSoyFileParserTokenDisplayName(expected[0])); } reporter.report(Tokens.createSrcLoc(filePath, errorToken), SoyError.of("{0}"), formatParseExceptionDetails(errorToken.image, expectedTokenImages.build().asList())); }