Example usage for com.google.common.collect ImmutableSet.Builder addAll

List of usage examples for com.google.common.collect ImmutableSet.Builder addAll

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet.Builder addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:ai.grakn.graql.internal.pattern.Patterns.java

public static VarPatternAdmin mergeVars(Collection<VarPatternAdmin> vars) {
    VarPatternAdmin first = vars.iterator().next();
    Var name = first.getVarName();/*from w w w  . j a v  a 2 s. c  o  m*/
    ImmutableSet.Builder<VarProperty> properties = ImmutableSet.builder();

    for (VarPatternAdmin var : vars) {
        if (var.getVarName().isUserDefinedName()) {
            name = var.getVarName();
        }

        properties.addAll(var.getProperties().iterator());
    }

    return new VarPatternImpl(name, properties.build());
}

From source file:dagger2.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.
 *//*  w ww . j av a 2 s  .  com*/
static ImmutableSet<TypeElement> getTransitiveModules(Types types, Elements elements,
        Iterable<TypeElement> seedModules) {
    TypeMirror objectType = elements.getTypeElement(Object.class.getCanonicalName()).asType();
    Queue<TypeElement> moduleQueue = Queues.newArrayDeque(seedModules);
    Set<TypeElement> moduleElements = Sets.newLinkedHashSet();
    for (TypeElement moduleElement = moduleQueue.poll(); moduleElement != null; moduleElement = moduleQueue
            .poll()) {
        Optional<AnnotationMirror> moduleMirror = getAnnotationMirror(moduleElement, Module.class)
                .or(getAnnotationMirror(moduleElement, ProducerModule.class));
        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:dagger.internal.codegen.writer.Snippet.java

public static Snippet format(String format, Object... args) {
    ImmutableSet.Builder<TypeName> types = ImmutableSet.builder();
    for (Object arg : args) {
        if (arg instanceof Snippet) {
            types.addAll(((Snippet) arg).types());
        }/*from   ww  w.ja v a2 s .  c  o m*/
        if (arg instanceof TypeName) {
            types.add((TypeName) arg);
        }
        if (arg instanceof HasTypeName) {
            types.add(((HasTypeName) arg).name());
        }
    }
    return new BasicSnippet(format, types.build(), ImmutableList.copyOf(args));
}

From source file:org.gradle.process.internal.daemon.AbstractWorkerDaemonExecutor.java

private static void addVisibilityFor(Class<?> visibleClass, ImmutableSet.Builder<File> classpathBuilder,
        ImmutableSet.Builder<String> sharedPackagesBuilder) {
    if (visibleClass.getClassLoader() != null) {
        classpathBuilder.addAll(ClasspathUtil.getClasspath(visibleClass.getClassLoader()).getAsFiles());
    }/*from   www . j  a v a2  s . c o m*/

    if (visibleClass.getPackage() == null || "".equals(visibleClass.getPackage().getName())) {
        sharedPackagesBuilder.add(FilteringClassLoader.DEFAULT_PACKAGE);
    } else {
        sharedPackagesBuilder.add(visibleClass.getPackage().getName());
    }
}

From source file:com.facebook.buck.cxx.AbstractNativeLinkableInput.java

/**
 * Combine, in order, several {@link NativeLinkableInput} objects into a single one.
 *//*ww w.j a  va 2  s  .  c o m*/
public static NativeLinkableInput concat(Iterable<NativeLinkableInput> items) {
    ImmutableList.Builder<Arg> args = ImmutableList.builder();
    ImmutableSet.Builder<FrameworkPath> frameworks = ImmutableSet.builder();
    ImmutableSet.Builder<FrameworkPath> libraries = ImmutableSet.builder();

    for (NativeLinkableInput item : items) {
        args.addAll(item.getArgs());
        frameworks.addAll(item.getFrameworks());
        libraries.addAll(item.getLibraries());
    }

    return NativeLinkableInput.of(args.build(), frameworks.build(), libraries.build());
}

From source file:dagger2.internal.codegen.Binding.java

static Optional<String> bindingPackageFor(Iterable<? extends Binding> bindings) {
    ImmutableSet.Builder<String> bindingPackagesBuilder = ImmutableSet.builder();
    for (Binding binding : bindings) {
        bindingPackagesBuilder.addAll(binding.bindingPackage().asSet());
    }/*from  w w w.j a  v a 2 s.  co  m*/
    ImmutableSet<String> bindingPackages = bindingPackagesBuilder.build();
    switch (bindingPackages.size()) {
    case 0:
        return Optional.absent();
    case 1:
        return Optional.of(bindingPackages.iterator().next());
    default:
        throw new IllegalArgumentException();
    }
}

From source file:com.facebook.presto.sql.planner.optimizations.WindowNodeUtil.java

public static Set<VariableReferenceExpression> extractWindowFunctionUniqueVariables(
        WindowNode.Function function, TypeProvider types) {
    ImmutableSet.Builder<VariableReferenceExpression> builder = ImmutableSet.builder();
    for (RowExpression argument : function.getFunctionCall().getArguments()) {
        if (isExpression(argument)) {
            builder.addAll(SymbolsExtractor.extractAllVariable(castToExpression(argument), types));
        } else {//from www.  j av  a2 s .  c o m
            builder.addAll(SymbolsExtractor.extractAll(argument));
        }
    }
    return builder.build();
}

From source file:org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl.java

private static Set<String> createAllShardNames(Iterable<ModuleConfig> moduleConfigs) {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (ModuleConfig moduleConfig : moduleConfigs) {
        builder.addAll(moduleConfig.getShardNames());
    }//from   w  w w.j  av  a  2s .  c  o  m

    return builder.build();
}

From source file:com.spectralogic.ds3autogen.utils.ConverterUtil.java

/**
 * Gets a set of type names used within a list of Ds3Types
 *//*from   www.j  ava2s. c  o m*/
protected static ImmutableSet<String> getUsedTypesFromAllTypes(final ImmutableMap<String, Ds3Type> typeMap,
        final ImmutableSet<String> usedTypes) {
    if (isEmpty(usedTypes) || isEmpty(typeMap)) {
        return ImmutableSet.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    builder.addAll(usedTypes);
    for (final String type : usedTypes) {
        final Ds3Type ds3Type = typeMap.get(type);
        if (ds3Type != null) {
            builder.addAll(getUsedTypesFromType(ds3Type));
        } else {
            //Log but do not throw an exception because there are cases where a type
            //doesn't need to be generated. Especially true during testing.
            LOG.error("Could not find used type in Type Map: " + type);
        }
    }
    final ImmutableSet<String> newUsedTypes = builder.build();
    if (newUsedTypes.size() > usedTypes.size()) {
        return getUsedTypesFromAllTypes(typeMap, newUsedTypes);
    }
    return newUsedTypes;
}

From source file:edu.mit.streamjit.util.ReflectionUtils.java

/**
 * Returns an immutable set of all fields in the given class or its
 * superclasses and superinterfaces, with any access modifier, static or
 * nonstatic.//from  ww w.j  a  va 2  s.  c  om
 * @param klass the class to get fields of
 * @return an immutable set of all fields in the class, including inherited
 * and static fields
 */
public static ImmutableSet<Field> getAllFields(Class<?> klass) {
    checkNotNull(klass);
    ImmutableSet.Builder<Field> builder = ImmutableSet.builder();
    while (klass != null) {
        builder.addAll(Arrays.asList(klass.getDeclaredFields()));
        for (Class<?> i : klass.getInterfaces())
            builder.addAll(Arrays.asList(i.getDeclaredFields()));
        klass = klass.getSuperclass();
    }
    return builder.build();
}