List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java
/** * Removes all unused types from the Ds3Type map. Types are considered to be used if * they are used within a Ds3Request, and/or if they are used within another type that * is also used./*from w w w . ja v a2 s .c o m*/ * @param types A Ds3Type map * @param requests A list of Ds3Requests */ public static ImmutableMap<String, Ds3Type> removeUnusedTypes(final ImmutableMap<String, Ds3Type> types, final ImmutableList<Ds3Request> requests) { if (isEmpty(types) || isEmpty(requests)) { return ImmutableMap.of(); } final ImmutableSet.Builder<String> usedTypesBuilder = ImmutableSet.builder(); usedTypesBuilder.addAll(getUsedTypesFromRequests(requests)); usedTypesBuilder.addAll(getUsedTypesFromAllTypes(types, usedTypesBuilder.build())); final ImmutableSet<String> usedTypes = usedTypesBuilder.build(); final ImmutableMap.Builder<String, Ds3Type> builder = ImmutableMap.builder(); for (final Map.Entry<String, Ds3Type> entry : types.entrySet()) { if (usedTypes.contains(entry.getKey())) { builder.put(entry.getKey(), entry.getValue()); } } return builder.build(); }
From source file:com.facebook.buck.js.JsFlavors.java
public static boolean validateFlavors(ImmutableSet<Flavor> flavors, Iterable<FlavorDomain<?>> allowableDomains) { final ImmutableSet.Builder<Flavor> allowableFlavors = ImmutableSet.builder(); for (FlavorDomain<?> domain : allowableDomains) { // verify only one flavor of each domain is present domain.getFlavor(flavors);//from ww w . j a v a 2s. c o m allowableFlavors.addAll(domain.getFlavors()); } return allowableFlavors.build().containsAll(flavors); }
From source file:org.gradle.api.internal.file.CompositeFileCollection.java
private static Set<File> getFiles(List<? extends FileCollectionInternal> sourceCollections) { switch (sourceCollections.size()) { case 0:/*from w w w . j av a 2s.c om*/ return Collections.emptySet(); case 1: return sourceCollections.get(0).getFiles(); default: ImmutableSet.Builder<File> builder = ImmutableSet.builder(); for (FileCollection collection : sourceCollections) { builder.addAll(collection); } return builder.build(); } }
From source file:com.facebook.buck.features.js.JsFlavors.java
public static boolean validateFlavors(ImmutableSet<Flavor> flavors, Iterable<FlavorDomain<?>> allowableDomains) { ImmutableSet.Builder<Flavor> allowableFlavors = ImmutableSet.builder(); for (FlavorDomain<?> domain : allowableDomains) { // verify only one flavor of each domain is present domain.getFlavor(flavors);/*from www . j ava 2 s . c o m*/ allowableFlavors.addAll(domain.getFlavors()); } return allowableFlavors.build().containsAll(flavors); }
From source file:io.ytcode.reflect.Reflect.java
public static ImmutableSet<Class<?>> superTypes(Class<?> c, Predicate<Class<?>> p) { checkNotNull(c);// ww w . jav a2 s.com checkNotNull(p); ImmutableSet.Builder<Class<?>> b = ImmutableSet.builder(); Class<?> c1 = c.getSuperclass(); if (c1 != null) { if (p.apply(c1)) { b.add(c1); } b.addAll(superTypes(c1, p)); } Class<?>[] c2s = c.getInterfaces(); if (c2s != null) { for (Class<?> c2 : c2s) { if (p.apply(c2)) { b.add(c2); } b.addAll(superTypes(c2, p)); } } return b.build(); }
From source file:dagger.internal.codegen.ConfigurationAnnotations.java
/** * Returns the full set of modules transitively {@linkplain Module#includes included} from the * given seed modules. If a module is malformed and a type listed in {@link Module#includes} * is not annotated with {@link Module}, it is ignored. * * @deprecated Use {@link ComponentDescriptor#transitiveModules}. *//*from ww w . j a v a 2s . com*/ @Deprecated static ImmutableSet<TypeElement> getTransitiveModules(Types types, Elements elements, Iterable<TypeElement> seedModules) { TypeMirror objectType = elements.getTypeElement(Object.class.getCanonicalName()).asType(); Queue<TypeElement> moduleQueue = new ArrayDeque<>(); Iterables.addAll(moduleQueue, seedModules); Set<TypeElement> moduleElements = Sets.newLinkedHashSet(); for (TypeElement moduleElement = moduleQueue.poll(); moduleElement != null; moduleElement = moduleQueue .poll()) { Optional<AnnotationMirror> moduleMirror = getModuleAnnotation(moduleElement); if (moduleMirror.isPresent()) { ImmutableSet.Builder<TypeElement> moduleDependenciesBuilder = ImmutableSet.builder(); moduleDependenciesBuilder.addAll(MoreTypes.asTypeElements(getModuleIncludes(moduleMirror.get()))); // (note: we don't recurse on the parent class because we don't want the parent class as a // root that the component depends on, and also because we want the dependencies rooted // against this element, not the parent.) addIncludesFromSuperclasses(types, moduleElement, moduleDependenciesBuilder, objectType); ImmutableSet<TypeElement> moduleDependencies = moduleDependenciesBuilder.build(); moduleElements.add(moduleElement); for (TypeElement dependencyType : moduleDependencies) { if (!moduleElements.contains(dependencyType)) { moduleQueue.add(dependencyType); } } } } return ImmutableSet.copyOf(moduleElements); }
From source file:ca.cutterslade.match.scheduler.Scheduler.java
private static ImmutableSet<Team> padWithByes(ImmutableSet<Tier> tiers, ImmutableSet<Team> realTeams, int teamsPerTier) { ImmutableSet.Builder<Team> b = ImmutableSet.builder(); for (Tier tier : tiers) { ImmutableSet<Team> tierTeams = ImmutableSet.copyOf(tier.getTeams(realTeams)); b.addAll(tierTeams); if (tierTeams.size() > teamsPerTier) throw new AssertionError("More than allowed number of teams"); if (tierTeams.size() < teamsPerTier) for (int i = 0, n = teamsPerTier - tierTeams.size(); i < n; i++) b.add(new Team("B" + i, tier)); }//w w w .ja va 2s . co m return b.build(); }
From source file:com.tngtech.archunit.junit.ReflectionUtils.java
static Set<Class<?>> getAllSuperTypes(Class<?> type) { if (type == null) { return Collections.emptySet(); }// w w w. j av a 2s . c om ImmutableSet.Builder<Class<?>> result = ImmutableSet.<Class<?>>builder().add(type) .addAll(getAllSuperTypes(type.getSuperclass())); for (Class<?> c : type.getInterfaces()) { result.addAll(getAllSuperTypes(c)); } return result.build(); }
From source file:com.tomtom.speedtools.objects.Immutables.java
/** * Returns an immutable set containing elements from elts1, concatenated with elts2. The order of the elements will * be preserved (by means of a {@link LinkedHashSet}. When given collection was already an immutable set, this set * is simply returned.// www . j a v a 2 s . c om * * @param <T> Element type. * @param elts1 Initial elements for the set. * @param elts2 Elements to be concatenated. * @return Immutable set. */ @SafeVarargs @Nonnull public static <T> Set<T> setOf(@Nonnull final Collection<? extends T> elts1, @Nonnull final T... elts2) { assert elts1 != null; assert elts2 != null; if (elts1.isEmpty()) { return setOf(elts2); } if (elts2.length == 0) { return setOf(elts1); } final ImmutableSet.Builder<T> builder = ImmutableSet.builder(); builder.addAll(elts1); builder.add(elts2); return builder.build(); }
From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java
/** * Gets a set of type names used within a list of Ds3Requests. This includes all Spectra defined * parameter types and response types used within the requests. *///from ww w .j a va 2 s. c o m protected static ImmutableSet<String> getUsedTypesFromRequests(final ImmutableList<Ds3Request> requests) { if (isEmpty(requests)) { return ImmutableSet.of(); } final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (final Ds3Request request : requests) { builder.addAll(getUsedTypesFromParams(request.getRequiredQueryParams())); builder.addAll(getUsedTypesFromParams(request.getOptionalQueryParams())); builder.addAll(getUsedTypesFromResponseCodes(request.getDs3ResponseCodes())); } return builder.build(); }