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

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

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.gradle.internal.ImmutableActionSet.java

private static <T> ImmutableActionSet<T> plus(ImmutableActionSet<T> one, Action<? super T> two) {
    ImmutableSet.Builder<Action<? super T>> builder = ImmutableSet.builder();
    one.unpackInto(builder);/*from  w ww. java2  s .  c om*/
    builder.add(two);
    ImmutableSet<Action<? super T>> set = builder.build();
    return fromActions(set);
}

From source file:com.google.auto.common.MoreTypes.java

public static ImmutableSet<TypeElement> asTypeElements(Types types, Iterable<? extends TypeMirror> mirrors) {
    checkNotNull(types);/*from   ww  w.j  a  v  a2  s.co  m*/
    checkNotNull(mirrors);
    ImmutableSet.Builder<TypeElement> builder = ImmutableSet.builder();
    for (TypeMirror mirror : mirrors) {
        builder.add(asTypeElement(types, mirror));
    }
    return builder.build();
}

From source file:com.facebook.presto.sql.ReservedIdentifiers.java

private static Set<String> possibleIdentifiers() {
    ImmutableSet.Builder<String> names = ImmutableSet.builder();
    Vocabulary vocabulary = SqlBaseLexer.VOCABULARY;
    for (int i = 0; i <= vocabulary.getMaxTokenType(); i++) {
        String name = nullToEmpty(vocabulary.getLiteralName(i));
        Matcher matcher = IDENTIFIER.matcher(name);
        if (matcher.matches()) {
            names.add(matcher.group(1));
        }/*from w w  w. j a  v a 2  s .c o m*/
    }
    return names.build();
}

From source file:com.facebook.buck.haskell.HaskellGhciRule.java

public static HaskellGhciRule from(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams params, BuildRuleResolver resolver, HaskellSources srcs,
        ImmutableList<String> compilerFlags, Optional<BuildTarget> ghciBinDep, Optional<SourcePath> ghciInit,
        BuildRule omnibusSharedObject, ImmutableSortedMap<String, SourcePath> solibs,
        ImmutableSet<HaskellPackage> firstOrderHaskellPackages, ImmutableSet<HaskellPackage> haskellPackages,
        ImmutableSet<HaskellPackage> prebuiltHaskellPackages, boolean enableProfiling, Path ghciScriptTemplate,
        Path ghciBinutils, Path ghciGhc, Path ghciLib, Path ghciCxx, Path ghciCc, Path ghciCpp) {

    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ImmutableSet.Builder<BuildRule> extraDeps = ImmutableSet.builder();

    extraDeps.add(omnibusSharedObject);

    for (HaskellPackage pkg : haskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }/*from   w  w w  .j a v a 2  s  .c  o m*/

    for (HaskellPackage pkg : prebuiltHaskellPackages) {
        extraDeps.addAll(pkg.getDeps(ruleFinder)::iterator);
    }

    if (ghciBinDep.isPresent()) {
        extraDeps.add(resolver.getRule(ghciBinDep.get()));
    }

    extraDeps.addAll(ruleFinder.filterBuildRuleInputs(solibs.values()));

    return new HaskellGhciRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()),
            resolver, srcs, compilerFlags, ghciBinDep, ghciInit, omnibusSharedObject, solibs,
            firstOrderHaskellPackages, haskellPackages, prebuiltHaskellPackages, enableProfiling,
            ghciScriptTemplate, ghciBinutils, ghciGhc, ghciLib, ghciCxx, ghciCc, ghciCpp);
}

From source file:com.google.errorprone.util.FindIdentifiers.java

private static void addIfVariable(Tree tree, ImmutableSet.Builder<VarSymbol> setBuilder) {
    if (tree.getKind() == Kind.VARIABLE) {
        setBuilder.add(ASTHelpers.getSymbol((VariableTree) tree));
    }//ww  w .j  a  v  a  2s . com
}

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

/**
 * Gets a set of type names used within a list of Ds3ResponseTypes
 *//*from  w  ww .j  a va 2s  . com*/
protected static ImmutableSet<String> getUsedTypesFromResponseTypes(
        final ImmutableList<Ds3ResponseType> responseTypes) {
    if (isEmpty(responseTypes)) {
        return ImmutableSet.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (final Ds3ResponseType responseType : responseTypes) {
        if (includeResponseType(responseType)) {
            builder.add(getTypeFromResponseType(responseType));
        }
    }
    return builder.build();
}

From source file:com.google.auto.factory.processor.Parameter.java

static Parameter forVariableElement(VariableElement variable, TypeMirror type) {
    ImmutableSet.Builder<String> qualifiers = ImmutableSet.builder();
    for (AnnotationMirror annotationMirror : variable.getAnnotationMirrors()) {
        DeclaredType annotationType = annotationMirror.getAnnotationType();
        if (annotationType.asElement().getAnnotation(Qualifier.class) != null) {
            qualifiers.add(Mirrors.getQualifiedName(annotationType).toString());
        }/*  www  . ja v a2s .  c  o  m*/
    }
    // TODO(gak): check for only one qualifier rather than using the first
    return new Parameter(FluentIterable.from(qualifiers.build()).first(), type.toString(),
            variable.getSimpleName().toString());
}

From source file:co.cask.cdap.common.lang.FilterClassLoader.java

public static FilterClassLoader create(ProgramType programType, ClassLoader parentClassLoader) {
    Set<String> visibleResources = ProgramResources.getVisibleResources(programType);
    ImmutableSet.Builder<String> visiblePackages = ImmutableSet.builder();
    for (String resource : visibleResources) {
        if (resource.endsWith(".class")) {
            int idx = resource.lastIndexOf('/');
            // Ignore empty package
            if (idx > 0) {
                visiblePackages.add(resource.substring(0, idx));
            }//from   w ww. j  a v a  2s .  c o m
        }
    }
    return new FilterClassLoader(Predicates.in(visibleResources), Predicates.in(visiblePackages.build()),
            parentClassLoader);
}

From source file:org.onosproject.cfg.impl.ConfigPropertyDefinitions.java

/**
 * Reads the specified input stream and creates from its contents a
 * set of property definitions./*  ww  w  .ja  v  a  2 s.co m*/
 *
 * @param stream input stream
 * @return properties whose definitions are contained in the stream
 * @throws java.io.IOException if unable to read the stream
 */
public static Set<ConfigProperty> read(InputStream stream) throws IOException {
    ImmutableSet.Builder<ConfigProperty> builder = ImmutableSet.builder();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
        String line;
        while ((line = br.readLine()) != null) {
            if (!line.isEmpty() && !line.startsWith(COMMENT)) {
                String[] f = line.split(SEP, 4);
                builder.add(defineProperty(f[0], Type.valueOf(f[1]), f[2], f[3]));
            }
        }
    }
    return builder.build();
}

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

/**
 * Gets a set of type names used within a Ds3Type
 *//*from  w ww.  j  a v  a  2s  .  c o m*/
protected static ImmutableSet<String> getUsedTypesFromType(final Ds3Type ds3Type) {
    if (isEnum(ds3Type) || isEmpty(ds3Type.getElements())) {
        return ImmutableSet.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (final Ds3Element ds3Element : ds3Type.getElements()) {
        if (includeType(ds3Element.getType())) {
            builder.add(ds3Element.getType());
        }
        if (hasContent(ds3Element.getComponentType()) && includeType(ds3Element.getComponentType())) {
            builder.add(ds3Element.getComponentType());
        }
    }
    return builder.build();
}