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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.facebook.presto.sql.planner.SubExpressionExtractor.java

public static List<Expression> extractAll(Iterable<Expression> expressions) {
    ImmutableList.Builder<Expression> builder = ImmutableList.builder();
    for (Expression expression : expressions) {
        extract(builder, expression);//from w ww .  j a  v a2 s . co  m
    }
    return builder.build();
}

From source file:dagger.internal.codegen.MissingBindingSuggestions.java

/**
 * Searches the entire binding graph from the top-level graph for a binding matching
 * {@code key}./* w w w.  j a  v  a  2  s.co m*/
 */
static ImmutableList<String> forKey(BindingGraph topLevelGraph, BindingKey key) {
    ImmutableList.Builder<String> resolutions = new ImmutableList.Builder<>();
    Deque<BindingGraph> graphsToTry = new ArrayDeque<>();

    graphsToTry.add(topLevelGraph);
    do {
        BindingGraph graph = graphsToTry.removeLast();
        ResolvedBindings bindings = graph.resolvedBindings().get(key);
        if ((bindings == null) || bindings.bindings().isEmpty()) {
            graphsToTry.addAll(graph.subgraphs());
        } else {
            resolutions.add("A binding with matching key exists in component: "
                    + graph.componentType().getQualifiedName());
        }
    } while (!graphsToTry.isEmpty());

    return resolutions.build();
}

From source file:com.spotify.heroic.lifecycle.LifeCycle.java

static LifeCycle combined(Stream<LifeCycle> many) {
    final ImmutableList.Builder<LifeCycle> cycles = ImmutableList.builder();
    many.forEach(cycles::add);/*from  www . j  a  v a2  s  .  c o m*/
    return ManyLifeCycle.of(cycles.build());
}

From source file:com.facebook.presto.operator.scalar.ListLiteralCast.java

@ScalarOperator(OperatorType.CAST)
@SqlType(ListLiteralType.NAME)/*from  w  w w.j a va2  s.c o m*/
public static List<Integer> castArrayToListLiteral(@SqlType("array(integer)") Block array) {
    ImmutableList.Builder<Integer> listBuilder = ImmutableList.builder();
    for (int i = 0; i < array.getPositionCount(); i++) {
        listBuilder.add(array.getInt(i, 0));
    }

    return listBuilder.build();
}

From source file:com.squareup.wire.schema.Extend.java

static ImmutableList<Extend> fromElements(String packageName, ImmutableList<ExtendElement> extendElements) {
    ImmutableList.Builder<Extend> extendBuilder = new ImmutableList.Builder<>();
    for (ExtendElement extendElement : extendElements) {
        extendBuilder.add(new Extend(extendElement.location(), extendElement.documentation(),
                extendElement.name(), Field.fromElements(packageName, extendElement.fields(), true)));
    }// w w  w.  j  a v a2s  . c  o  m
    return extendBuilder.build();
}

From source file:org.gradle.launcher.daemon.server.DaemonExpirationStrategies.java

public static DaemonExpirationStrategy getDefaultStrategy(Daemon daemon, DaemonServices daemonServices,
        final DaemonServerConfiguration params) {
    ImmutableList.Builder<DaemonExpirationStrategy> strategies = ImmutableList
            .<DaemonExpirationStrategy>builder();
    strategies.add(getHealthStrategy(daemonServices.get(DaemonHealthServices.class).getDaemonStatus()));
    strategies.add(//from  w  w w .j  a v a  2  s.c om
            new DaemonIdleTimeoutExpirationStrategy(daemon, params.getIdleTimeout(), TimeUnit.MILLISECONDS));
    try {
        strategies
                .add(new AllDaemonExpirationStrategy(ImmutableList.of(
                        new DaemonIdleTimeoutExpirationStrategy(daemon, params.getIdleTimeout() / 8,
                                TimeUnit.MILLISECONDS),
                        LowMemoryDaemonExpirationStrategy.belowFreePercentage(0.2))));
    } catch (UnsupportedOperationException e) {
        logger.info("This JVM does not support getting free system memory, so daemons will not check for it");
    }

    strategies.add(new DaemonRegistryUnavailableExpirationStrategy(daemon));
    return new AnyDaemonExpirationStrategy(strategies.build());
}

From source file:org.sonar.plugins.jacoco.JaCoCoExtensions.java

public static List getExtensions(Version sonarQubeVersion) {
    ImmutableList.Builder<Object> extensions = ImmutableList.builder();

    extensions.addAll(JacocoConfiguration.getPropertyDefinitions(sonarQubeVersion));
    extensions.add(JacocoConfiguration.class,
            // Unit tests
            JaCoCoSensor.class);
    if (!sonarQubeVersion.isGreaterThanOrEqual(JacocoConfiguration.SQ_6_2)) {
        extensions.add(//w w  w.  j av a2 s  . co m
                // Integration tests
                JaCoCoItSensor.class, JaCoCoOverallSensor.class);
    }

    return extensions.build();
}

From source file:org.cyclop.common.Gullectors.java

public static <T> Collector<T, ?, ImmutableList<T>> toImmutableList() {
    Supplier<ImmutableList.Builder<T>> supplier = ImmutableList.Builder::new;
    BiConsumer<ImmutableList.Builder<T>, T> accumulator = (b, v) -> b.add(v);
    BinaryOperator<ImmutableList.Builder<T>> combiner = (l, r) -> l.addAll(r.build());
    Function<ImmutableList.Builder<T>, ImmutableList<T>> finisher = ImmutableList.Builder::build;

    return Collector.of(supplier, accumulator, combiner, finisher);
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.UnionVersionSelector.java

public static UnionVersionSelector of(List<String> selectors, VersionSelectorScheme scheme) {
    ImmutableList.Builder<VersionSelector> builder = new ImmutableList.Builder<VersionSelector>();
    for (String selector : selectors) {
        builder.add(scheme.parseSelector(selector));
    }//from  ww w .j  av a  2  s  .co m
    return new UnionVersionSelector(builder.build());
}

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

/**
 * Returns an iterable which contains the name of each given framework in the same order.
 *//*from  www. j av a2s . c o  m*/
static Iterable<String> names(Iterable<SdkFramework> frameworks) {
    ImmutableList.Builder<String> result = new ImmutableList.Builder<>();
    for (SdkFramework framework : frameworks) {
        result.add(framework.getName());
    }
    return result.build();
}