List of usage examples for com.google.common.collect ImmutableSet.Builder add
boolean add(E e);
From source file:com.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java
public static ImmutableSet<Path> createPackageLookupPathSet(IjModuleGraph moduleGraph) { ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); for (IjModule module : moduleGraph.getModules()) { for (IjFolder folder : module.getFolders()) { if (!folder.getWantsPackagePrefix()) { continue; }/*from www. ja va 2s . c o m*/ Optional<Path> firstJavaFile = folder.getInputs().stream() .filter(input -> input.getFileName().toString().endsWith(".java")).findFirst(); if (firstJavaFile.isPresent()) { builder.add(firstJavaFile.get()); } } } return builder.build(); }
From source file:com.facebook.buck.apple.WorkspaceAndProjectGenerator.java
private static ImmutableSet<TargetNode<AppleTestDescription.Arg>> getExtraTestTargetNodes(TargetGraph graph, Iterable<BuildTarget> targets) { ImmutableSet.Builder<TargetNode<AppleTestDescription.Arg>> builder = ImmutableSet.builder(); for (TargetNode<?> node : graph.getAll(targets)) { Optional<TargetNode<AppleTestDescription.Arg>> castedNode = node .castArg(AppleTestDescription.Arg.class); if (castedNode.isPresent()) { builder.add(castedNode.get()); } else {/* ww w . j a v a 2 s . com*/ throw new HumanReadableException("Extra test target is not a test: '%s'", node.getBuildTarget()); } } return builder.build(); }
From source file:zipkin.storage.cassandra.Indexer.java
@VisibleForTesting static ImmutableSetMultimap<PartitionKeyToTraceId, Long> entriesThatIncreaseGap( ConcurrentMap<PartitionKeyToTraceId, Pair<Long>> sharedState, ImmutableSetMultimap<PartitionKeyToTraceId, Long> updates) { ImmutableSet.Builder<PartitionKeyToTraceId> toUpdate = ImmutableSet.builder(); // Enter a loop that affects shared state when an update widens the time interval for a key. for (Map.Entry<PartitionKeyToTraceId, Long> input : updates.entries()) { PartitionKeyToTraceId key = input.getKey(); long timestamp = input.getValue(); for (;;) { Pair<Long> oldRange = sharedState.get(key); if (oldRange == null) { // Initial state is where this key has a single timestamp. oldRange = sharedState.putIfAbsent(key, Pair.create(timestamp, timestamp)); // If there was no previous value, we need to update the index if (oldRange == null) { toUpdate.add(key); break; }/*from w ww . j a va 2s. c o m*/ } long first = timestamp < oldRange._1 ? timestamp : oldRange._1; long last = timestamp > oldRange._2 ? timestamp : oldRange._2; Pair<Long> newRange = Pair.create(first, last); if (oldRange.equals(newRange)) { break; // the current timestamp is contained } else if (sharedState.replace(key, oldRange, newRange)) { toUpdate.add(key); // The range was extended break; } } } // When the loop completes, we'll know one of our updates widened the interval of a trace, if // it is the first or last timestamp. By ignoring those between an existing interval, we can // end up with less Cassandra writes. Builder<PartitionKeyToTraceId, Long> result = ImmutableSetMultimap.builder(); for (PartitionKeyToTraceId needsUpdate : toUpdate.build()) { Pair<Long> firstLast = sharedState.get(needsUpdate); if (updates.containsEntry(needsUpdate, firstLast._1)) result.put(needsUpdate, firstLast._1); if (updates.containsEntry(needsUpdate, firstLast._2)) result.put(needsUpdate, firstLast._2); } return result.build(); }
From source file:com.google.devtools.build.lib.analysis.DependencyResolver.java
private static ImmutableSet<AspectDescriptor> requiredAspects(Iterable<Aspect> aspects, AttributeAndOwner attributeAndOwner, final Target target, Rule originalRule) { if (!(target instanceof Rule)) { return ImmutableSet.of(); }/*from ww w .j av a2s . c om*/ if (attributeAndOwner.ownerAspect != null) { // Do not propagate aspects along aspect attributes. return ImmutableSet.of(); } Iterable<Aspect> aspectCandidates = extractAspectCandidates(aspects, attributeAndOwner.attribute, originalRule); RuleClass ruleClass = ((Rule) target).getRuleClassObject(); ImmutableSet.Builder<AspectDescriptor> result = ImmutableSet.builder(); for (Aspect aspectCandidate : aspectCandidates) { if (aspectCandidate.getDefinition().getRequiredProviders() .isSatisfiedBy(ruleClass.getAdvertisedProviders())) { result.add(new AspectDescriptor(aspectCandidate.getAspectClass(), aspectCandidate.getParameters())); } } return result.build(); }
From source file:com.google.javascript.jscomp.deps.ModuleLoader.java
/** * @param modulePaths List of modules. Modules can be relative to the compilation root or absolute * file system paths (or even absolute paths from the compilation root). * @param roots List of module roots which anchor absolute path references. * @return List of normalized modules which always have a leading slash *///from w w w . ja va 2 s.co m private static ImmutableSet<String> resolvePaths(Iterable<String> modulePaths, Iterable<String> roots, PathEscaper escaper) { ImmutableSet.Builder<String> resolved = ImmutableSet.builder(); Set<String> knownPaths = new HashSet<>(); for (String name : modulePaths) { String canonicalizedPath = escaper.escape(name); if (!knownPaths.add(normalize(canonicalizedPath, roots))) { // Having root paths "a" and "b" and source files "a/f.js" and "b/f.js" is ambiguous. throw new IllegalArgumentException("Duplicate module path after resolving: " + name); } if (isAmbiguousIdentifier(canonicalizedPath)) { canonicalizedPath = MODULE_SLASH + canonicalizedPath; } resolved.add(canonicalizedPath); } return resolved.build(); }
From source file:com.publictransitanalytics.scoregenerator.Main.java
private static Set<TransitStop> getDeletedStops(final OperationDescription description, final BiMap<String, TransitStop> stopIdMap) { final List<ComparisonOperation> operations = description.getOperations(); final ImmutableSet.Builder<TransitStop> builder = ImmutableSet.builder(); if (operations != null) { for (final ComparisonOperation operation : operations) { switch (operation.getOperator()) { case DELETE: final Stop stopData = operation.getStop(); if (stopData != null) { builder.add(stopIdMap.get(stopData.getStopId())); }/* w w w . j a v a 2 s . c om*/ } } } return builder.build(); }
From source file:google.registry.model.ModelUtils.java
/** * Returns the set of Class objects of all persisted fields. This includes the parameterized * type(s) of any fields (if any)./*from w ww . j a va 2s . c o m*/ */ static Set<Class<?>> getPersistedFieldTypes(Class<?> clazz) { ImmutableSet.Builder<Class<?>> builder = new ImmutableSet.Builder<>(); for (Field field : getAllFields(clazz).values()) { // Skip fields that aren't persisted to datastore. if (field.isAnnotationPresent(Ignore.class)) { continue; } // If the field's type is the same as the field's class object, then it's a non-parameterized // type, and thus we just add it directly. We also don't bother looking at the parameterized // types of Key objects, since they are just references to other objects and don't actually // embed themselves in the persisted object anyway. Class<?> fieldClazz = field.getType(); Type fieldType = field.getGenericType(); builder.add(fieldClazz); if (fieldType.equals(fieldClazz) || Key.class.equals(clazz)) { continue; } // If the field is a parameterized type, then also add the parameterized field. if (fieldType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) fieldType; for (Type actualType : parameterizedType.getActualTypeArguments()) { if (actualType instanceof Class<?>) { builder.add((Class<?>) actualType); } else { // We intentionally ignore types that are parameterized on non-concrete types. In theory // we could have collections embedded within collections, but Objectify does not allow // that. } } } } return builder.build(); }
From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java
private static ImmutableSet<TargetNode<AppleTestDescription.Arg, ?>> getExtraTestTargetNodes(TargetGraph graph, Iterable<BuildTarget> targets) { ImmutableSet.Builder<TargetNode<AppleTestDescription.Arg, ?>> builder = ImmutableSet.builder(); for (TargetNode<?, ?> node : graph.getAll(targets)) { Optional<TargetNode<AppleTestDescription.Arg, ?>> castedNode = node .castArg(AppleTestDescription.Arg.class); if (castedNode.isPresent()) { builder.add(castedNode.get()); } else {//from www .j ava2 s . co m throw new HumanReadableException("Extra test target is not a test: '%s'", node.getBuildTarget()); } } return builder.build(); }
From source file:org.inferred.freebuilder.processor.Analyser.java
private static ImmutableSet<TypeElement> nullableAnnotationsOn(ExecutableElement getterMethod) { ImmutableSet.Builder<TypeElement> nullableAnnotations = ImmutableSet.builder(); for (AnnotationMirror mirror : getterMethod.getAnnotationMirrors()) { if (mirror.getElementValues().isEmpty()) { TypeElement type = (TypeElement) mirror.getAnnotationType().asElement(); if (type.getSimpleName().contentEquals("Nullable")) { nullableAnnotations.add(type); }//w w w.j a va 2s . c o m } } return nullableAnnotations.build(); }
From source file:com.facebook.buck.android.UberRDotJavaUtil.java
/** * Finds the transitive set of {@code rules}' {@link AndroidResource} dependencies with * non-null {@code res} directories, which can also include any of the {@code rules} themselves. * This set will be returned as an {@link ImmutableList} with the rules topologically sorted. * Rules will be ordered from least dependent to most dependent. *///from w w w . jav a 2 s . c o m public static ImmutableList<HasAndroidResourceDeps> getAndroidResourceDeps(Collection<BuildRule> rules, final boolean includeAssetOnlyRules) { // This visitor finds all AndroidResourceRules that are reachable from the specified rules via // rules with types in the TRAVERSABLE_TYPES collection. It also builds up the dependency graph // that was traversed to find the AndroidResourceRules. final MutableDirectedGraph<BuildRule> mutableGraph = new MutableDirectedGraph<>(); final ImmutableSet.Builder<HasAndroidResourceDeps> androidResources = ImmutableSet.builder(); AbstractDependencyVisitor visitor = new AbstractDependencyVisitor(rules) { @Override public ImmutableSet<BuildRule> visit(BuildRule rule) { HasAndroidResourceDeps androidResourceRule = null; if (rule instanceof HasAndroidResourceDeps) { androidResourceRule = (HasAndroidResourceDeps) rule; } else if (rule.getBuildable() instanceof HasAndroidResourceDeps) { androidResourceRule = (HasAndroidResourceDeps) rule.getBuildable(); } if (androidResourceRule != null && (androidResourceRule.getRes() != null || (includeAssetOnlyRules && androidResourceRule.getAssets() != null))) { androidResources.add(androidResourceRule); } // Only certain types of rules should be considered as part of this traversal. BuildRuleType type = rule.getType(); ImmutableSet<BuildRule> depsToVisit = maybeVisitAllDeps(rule, TRAVERSABLE_TYPES.contains(type)); mutableGraph.addNode(rule); for (BuildRule dep : depsToVisit) { mutableGraph.addEdge(rule, dep); } return depsToVisit; } }; visitor.start(); final Set<HasAndroidResourceDeps> allAndroidResourceRules = androidResources.build(); // Now that we have the transitive set of AndroidResourceRules, we need to return them in // topologically sorted order. This is critical because the order in which -S flags are passed // to aapt is significant and must be consistent. Predicate<BuildRule> inclusionPredicate = new Predicate<BuildRule>() { @Override public boolean apply(BuildRule rule) { return allAndroidResourceRules.contains(rule) || allAndroidResourceRules.contains(rule.getBuildable()); } }; ImmutableList<BuildRule> sortedAndroidResourceRules = TopologicalSort.sort(mutableGraph, inclusionPredicate); // TopologicalSort.sort() returns rules in leaves-first order, which is the opposite of what we // want, so we must reverse the list and cast BuildRules to AndroidResourceRules. return ImmutableList .copyOf(Iterables.transform(sortedAndroidResourceRules.reverse(), CAST_TO_ANDROID_RESOURCE_RULE)); }