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:dagger2.internal.codegen.Util.java

static ImmutableSet<ExecutableElement> getUnimplementedMethods(Elements elements, TypeElement type) {
    ImmutableSet.Builder<ExecutableElement> unimplementedMethods = ImmutableSet.builder();
    List<ExecutableElement> methods = findLocalAndInheritedMethods(elements, type);
    for (ExecutableElement method : methods) {
        if (method.getModifiers().contains(Modifier.ABSTRACT)) {
            unimplementedMethods.add(method);
        }/* w w w .java  2  s.  c  o  m*/
    }
    return unimplementedMethods.build();
}

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

/**
 * Constructs set of flavors given in a .buckconfig file, as is specified by section names
 * of the form cxx#{flavor name}.//  w w w.  j  a v  a  2 s  .  c o  m
 */
public static ImmutableSet<Flavor> getCxxFlavors(BuckConfig config) {
    ImmutableSet.Builder<Flavor> builder = ImmutableSet.builder();
    ImmutableSet<String> sections = config.getSections();
    for (String section : sections) {
        if (section.startsWith(FLAVORED_CXX_SECTION_PREFIX)) {
            builder.add(ImmutableFlavor.of(section.substring(FLAVORED_CXX_SECTION_PREFIX.length())));
        }
    }
    return builder.build();
}

From source file:com.facebook.buck.cli.QueryTargetAccessor.java

public static <T extends AbstractDescriptionArg> ImmutableSet<QueryTarget> getTargetsInAttribute(
        TargetNode<T> node, String attribute) throws QueryException {
    try {//from w  ww. j a va 2s. c  o  m
        final ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
        Field field = node.getConstructorArg().getClass().getField(attribute);
        ParamInfo<T> info = new ParamInfo<>(typeCoercerFactory, field);
        info.traverse(new ParamInfo.Traversal() {
            @Override
            public void traverse(Object value) {
                if (value instanceof Path) {
                    builder.add(QueryFileTarget.of((Path) value));
                } else if (value instanceof SourcePath) {
                    builder.add(extractSourcePath((SourcePath) value));
                } else if (value instanceof HasBuildTarget) {
                    builder.add(extractBuildTargetContainer((HasBuildTarget) value));
                }
            }
        }, node.getConstructorArg());
        return builder.build();
    } catch (NoSuchFieldException e) {
        // Ignore if the field does not exist in this rule.
        return ImmutableSet.of();
    }
}

From source file:org.waveprotocol.wave.model.conversation.TagsDocument.java

static public ImmutableSet<String> getTags(Document doc) {
    final ImmutableSet.Builder<String> tags = ImmutableSet.builder();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    TagsDocument tagsDocument = new TagsDocument(doc);
    tagsDocument.addListener(new TagsDocument.Listener() {
        @Override//from   ww w  . j a  v a2 s  .c o  m
        public void onAdd(String tagName) {
            tags.add(tagName);
        }

        @Override
        public void onRemove(int tagPosition) {
            // Not called.
        }
    });
    tagsDocument.processInitialState();
    return tags.build();
}

From source file:com.facebook.buck.core.model.targetgraph.impl.TargetNodeFactory.java

private static void detectBuildTargetsAndPathsForConstructorArg(BuildTarget buildTarget,
        CellPathResolver cellRoots, ImmutableSet.Builder<BuildTarget> depsBuilder,
        ImmutableSet.Builder<Path> pathsBuilder, ParamInfo info, Object constructorArg)
        throws NoSuchBuildTargetException {
    // We'll make no test for optionality here. Let's assume it's done elsewhere.

    try {/*from w w w . j  av  a2 s.  c  o m*/
        info.traverse(cellRoots, object -> {
            if (object instanceof PathSourcePath) {
                pathsBuilder.add(((PathSourcePath) object).getRelativePath());
            } else if (object instanceof BuildTargetSourcePath) {
                depsBuilder.add(((BuildTargetSourcePath) object).getTarget());
            } else if (object instanceof Path) {
                pathsBuilder.add((Path) object);
            } else if (object instanceof BuildTarget) {
                depsBuilder.add((BuildTarget) object);
            }
        }, constructorArg);
    } catch (RuntimeException e) {
        if (e.getCause() instanceof NoSuchBuildTargetException) {
            throw (NoSuchBuildTargetException) e.getCause();
        }
        throw new HumanReadableException(e, "Cannot traverse attribute %s of %s: %s", info.getName(),
                buildTarget, e.getMessage());
    }
}

From source file:com.google.errorprone.bugpatterns.threadsafety.WellKnownMutability.java

private static ImmutableSet<String> getKnownUnsafeClasses() {
    ImmutableSet.Builder<String> result = ImmutableSet.<String>builder();
    for (Class<?> clazz : ImmutableSet.<Class<?>>of(java.lang.Iterable.class, java.lang.Object.class,
            java.util.ArrayList.class, java.util.Collection.class, java.util.List.class, java.util.Map.class,
            java.util.Set.class, java.util.EnumSet.class, java.util.EnumMap.class)) {
        result.add(clazz.getName());
    }/*from w w  w  . j  av  a  2s  . c om*/
    return result.build();
}

From source file:com.google.caliper.runner.resultprocessor.ResultProcessorModule.java

@Provides
static ImmutableSet<ResultProcessor> provideResultProcessors(CaliperConfig config,
        Map<Class<? extends ResultProcessor>, Provider<ResultProcessor>> availableProcessors) {
    ImmutableSet.Builder<ResultProcessor> builder = ImmutableSet.builder();
    for (Class<? extends ResultProcessor> processorClass : config.getConfiguredResultProcessors()) {
        Provider<ResultProcessor> resultProcessorProvider = availableProcessors.get(processorClass);
        ResultProcessor resultProcessor = resultProcessorProvider == null
                ? ResultProcessorCreator.createResultProcessor(processorClass)
                : resultProcessorProvider.get();
        builder.add(resultProcessor);
    }/*  w  ww. j  a  va  2  s.c o  m*/
    return builder.build();
}

From source file:suneido.util.Util.java

public static <T> ImmutableSet<T> setDifference(Collection<T> x, Collection<T> y) {
    ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    for (T s : x)
        if (!y.contains(s))
            builder.add(s);
    return builder.build();
}

From source file:suneido.util.Util.java

public static <T> ImmutableSet<T> setIntersect(Collection<T> x, Collection<T> y) {
    if (y instanceof Set) {
        Collection<T> tmp = x;
        x = y;//w  w w  .  j a v a  2  s .com
        y = tmp;
    }
    ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    for (T e : y)
        if (x.contains(e))
            builder.add(e);
    return builder.build();
}

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

public static HaskellGhciRule from(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams params, SourcePathRuleFinder ruleFinder, HaskellSources srcs,
        ImmutableList<String> compilerFlags, Optional<SourcePath> ghciBinDep, Optional<SourcePath> ghciInit,
        BuildRule omnibusSharedObject, ImmutableSortedMap<String, SourcePath> solibs,
        ImmutableSortedMap<String, SourcePath> preloadLibs,
        ImmutableSet<HaskellPackage> firstOrderHaskellPackages, ImmutableSet<HaskellPackage> haskellPackages,
        ImmutableSet<HaskellPackage> prebuiltHaskellPackages, boolean enableProfiling, Path ghciScriptTemplate,
        ImmutableList<SourcePath> extraScriptTemplates, Path ghciIservScriptTemplate, Path ghciBinutils,
        Path ghciGhc, Path ghciIServ, Path ghciIServProf, Path ghciLib, Path ghciCxx, Path ghciCc, Path ghciCpp,
        Path ghciPackager) {/*from   w w  w .  ja  v a2 s.  c om*/

    ImmutableSet.Builder<BuildRule> extraDeps = ImmutableSet.builder();

    extraDeps.add(omnibusSharedObject);

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

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

    ghciBinDep.flatMap(ruleFinder::getRule).ifPresent(extraDeps::add);

    extraDeps.addAll(ruleFinder.filterBuildRuleInputs(solibs.values()));
    extraDeps.addAll(ruleFinder.filterBuildRuleInputs(preloadLibs.values()));
    return new HaskellGhciRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(extraDeps.build()),
            srcs, compilerFlags, ghciBinDep, ghciInit, omnibusSharedObject, solibs, preloadLibs,
            firstOrderHaskellPackages, haskellPackages, prebuiltHaskellPackages, enableProfiling,
            ghciScriptTemplate, extraScriptTemplates, ghciIservScriptTemplate, ghciBinutils, ghciGhc, ghciIServ,
            ghciIServProf, ghciLib, ghciCxx, ghciCc, ghciCpp, ghciPackager);
}