Example usage for com.google.common.collect ImmutableSet builder

List of usage examples for com.google.common.collect ImmutableSet builder

Introduction

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

Prototype

public static <E> Builder<E> builder() 

Source Link

Usage

From source file:com.google.template.soy.jssrc.dsl.Call.java

static Call create(CodeChunk.WithValue receiver, ImmutableList<CodeChunk.WithValue> args) {
    ImmutableSet.Builder<CodeChunk> builder = ImmutableSet.builder();
    builder.addAll(receiver.initialStatements());
    for (CodeChunk.WithValue arg : args) {
        builder.addAll(arg.initialStatements());
    }//  w  w w  .j a va2 s  .c o  m
    return new AutoValue_Call(builder.build(), receiver, args);
}

From source file:com.google.devtools.build.lib.rules.java.JavaPluginInfoProvider.java

public static JavaPluginInfoProvider merge(Iterable<JavaPluginInfoProvider> providers) {
    ImmutableSet.Builder<String> processorClasses = ImmutableSet.builder();
    NestedSetBuilder<Artifact> processorClasspath = NestedSetBuilder.naiveLinkOrder();
    ImmutableSet.Builder<String> apiGeneratingProcessorClasses = ImmutableSet.builder();
    NestedSetBuilder<Artifact> apiGeneratingProcessorClasspath = NestedSetBuilder.naiveLinkOrder();

    for (JavaPluginInfoProvider provider : providers) {
        processorClasses.addAll(provider.getProcessorClasses());
        processorClasspath.addTransitive(provider.getProcessorClasspath());
        apiGeneratingProcessorClasses.addAll(provider.getApiGeneratingProcessorClasses());
        apiGeneratingProcessorClasspath.addTransitive(provider.getApiGeneratingProcessorClasspath());
    }/*  ww  w  .  j  a  v  a 2  s. c om*/
    return new JavaPluginInfoProvider(processorClasses.build(), processorClasspath.build(),
            apiGeneratingProcessorClasses.build(), apiGeneratingProcessorClasspath.build());
}

From source file:com.isotrol.impe3.pms.core.obj.Builders.java

static <T> ImmutableSet<T> build(ImmutableSet.Builder<T> builder) {
    if (builder == null) {
        return ImmutableSet.of();
    }/*from   ww w  . j a v  a  2  s.  c o m*/
    return builder.build();
}

From source file:org.jooby.fn.Collectors.java

public static <T> Collector<T, ImmutableSet.Builder<T>, Set<T>> toSet() {
    BinaryOperator<ImmutableSet.Builder<T>> combiner = (l, r) -> l.addAll(r.build());
    return Collector.of(ImmutableSet.Builder::new, (b, e) -> b.add(e), combiner, ImmutableSet.Builder::build);
}

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

static LabelSelector fromString(String raw) {
    Preconditions.checkNotNull(raw);//from  ww  w . j a  v  a 2 s.  co  m
    Preconditions.checkState(!raw.isEmpty());

    boolean isInclusive = true;
    if (raw.charAt(0) == '!') {
        isInclusive = false;
        raw = raw.substring(1);
    }

    ImmutableSet.Builder<Label> labelBuilder = new ImmutableSet.Builder<>();
    Iterable<String> labelStrings = splitter.split(raw);
    for (String labelString : labelStrings) {
        BuckConfig.validateLabelName(labelString);
        labelBuilder.add(new Label(labelString));
    }

    return new LabelSelector(isInclusive, labelBuilder.build());
}

From source file:com.google.caliper.runner.EffectiveClassPath.java

private static ImmutableSet<File> getClassPathFiles(ClassLoader classLoader) {
    ImmutableSet.Builder<File> files = ImmutableSet.builder();
    @Nullable//from  w  ww.j a v a  2s  .c  o  m
    ClassLoader parent = classLoader.getParent();
    if (parent != null) {
        files.addAll(getClassPathFiles(parent));
    }
    if (classLoader instanceof URLClassLoader) {
        URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
        for (URL url : urlClassLoader.getURLs()) {
            try {
                files.add(new File(url.toURI()));
            } catch (URISyntaxException e) {
                // skip it then
            } catch (IllegalArgumentException e) {
                // skip it then
            }
        }
    }
    return files.build();
}

From source file:com.facebook.buck.jvm.java.JavaLibraryClasspathProvider.java

public static ImmutableSet<Path> getOutputClasspathJars(JavaLibrary javaLibraryRule,
        SourcePathResolver resolver, Optional<SourcePath> outputJar) {
    ImmutableSet.Builder<Path> outputClasspathBuilder = ImmutableSet.builder();
    Iterable<JavaLibrary> javaExportedLibraryDeps;
    if (javaLibraryRule instanceof ExportDependencies) {
        javaExportedLibraryDeps = getJavaLibraryDeps(((ExportDependencies) javaLibraryRule).getExportedDeps());
    } else {//from  w ww  .ja v  a 2  s  . co  m
        javaExportedLibraryDeps = Sets.newHashSet();
    }

    for (JavaLibrary rule : javaExportedLibraryDeps) {
        outputClasspathBuilder.addAll(rule.getOutputClasspaths());
    }

    if (outputJar.isPresent()) {
        outputClasspathBuilder.add(resolver.getAbsolutePath(outputJar.get()));
    }

    return outputClasspathBuilder.build();
}

From source file:org.opendaylight.controller.config.manager.impl.dynamicmbean.AnnotationsHelper.java

/**
 * Look for annotation specified by annotationType on method. First observe
 * method's class, then its super classes, then all provided interfaces.
 * Used for finding @Description and @RequireInterface
 *
 * @param <T>// w w w .ja v a2s .c  om
 *            generic type of annotation
 * @return list of found annotations
 */
static <T extends Annotation> List<T> findMethodAnnotationInSuperClassesAndIfcs(final Method setter,
        final Class<T> annotationType, final Set<Class<?>> inspectedInterfaces) {
    Builder<T> result = ImmutableSet.builder();
    Class<?> inspectedClass = setter.getDeclaringClass();
    do {
        try {
            Method foundSetter = inspectedClass.getMethod(setter.getName(), setter.getParameterTypes());
            T annotation = foundSetter.getAnnotation(annotationType);
            if (annotation != null) {
                result.add(annotation);
            }
            // we need to go deeper
            inspectedClass = inspectedClass.getSuperclass();
        } catch (NoSuchMethodException e) {
            inspectedClass = Object.class; // no need to go further
        }
    } while (!inspectedClass.equals(Object.class));

    // inspect interfaces
    for (Class<?> ifc : inspectedInterfaces) {
        if (ifc.isInterface() == false) {
            throw new IllegalArgumentException(ifc + " is not an interface");
        }
        try {
            Method foundSetter = ifc.getMethod(setter.getName(), setter.getParameterTypes());
            T annotation = foundSetter.getAnnotation(annotationType);
            if (annotation != null) {
                result.add(annotation);
            }
        } catch (NoSuchMethodException e) {

        }
    }
    return new ArrayList<>(result.build());
}

From source file:com.google.caliper.runner.target.TargetModule.java

@Singleton
@Provides/*from   w ww .j a  v a2 s  . co m*/
static ImmutableSet<Target> provideTargets(Device device, CaliperOptions options, CaliperConfig config) {
    ImmutableSet<String> vmNames = options.vmNames();
    if (vmNames.isEmpty()) {
        return ImmutableSet.of(device.createDefaultTarget());
    }

    ImmutableSet.Builder<Target> builder = ImmutableSet.builder();
    for (String vmName : vmNames) {
        builder.add(device.createTarget(config.getVmConfig(vmName)));
    }
    return builder.build();
}

From source file:io.ytcode.reflect.Reflect.java

public static ImmutableSet<Class<?>> superTypes(Class<?> c, Predicate<Class<?>> p) {
    checkNotNull(c);//  w w  w .  j  ava  2s.c o m
    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();
}