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.spotify.trickle.GraphExceptionWrapper.java

private static List<CallInfo> callInfos(TraverseState state) {
    ImmutableList.Builder<CallInfo> builder = builder();

    for (TraverseState.FutureCallInformation futureCallInformation : state.getCalls()) {
        if (futureCallInformation.isComplete()) {
            builder.add(asCallInfo(futureCallInformation));
        }//  ww w.j a  v  a 2  s. c  o  m
    }

    return builder.build();
}

From source file:org.basepom.mojo.propertyhelper.DateField.java

public static List<DateField> createDates(final ValueCache valueCache, final DateDefinition[] dateDefinitions)
        throws IOException {
    checkNotNull(valueCache, "valueCache is null");
    checkNotNull(dateDefinitions, "dateDefinitions is null");

    final ImmutableList.Builder<DateField> result = ImmutableList.builder();

    for (DateDefinition dateDefinition : dateDefinitions) {
        dateDefinition.check();/*www .  j a  v  a  2  s .  co m*/
        final ValueProvider dateValue = valueCache.getValueProvider(dateDefinition);
        final DateField dateField = new DateField(dateDefinition, dateValue);
        result.add(dateField);
    }
    return result.build();
}

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

static ImmutableList<Extensions> fromElements(ImmutableList<ExtensionsElement> elements) {
    ImmutableList.Builder<Extensions> extensions = ImmutableList.builder();
    for (ExtensionsElement element : elements) {
        extensions.add(//  w w w.  j  av a 2s .c o m
                new Extensions(element.location(), element.documentation(), element.start(), element.end()));
    }
    return extensions.build();
}

From source file:com.spectralogic.ds3autogen.testutil.Ds3ResponseCodeFixture.java

/**
 * Creates a list of populated response codes for testing purposes. If hasPayload is true,
 * then one of the response types will be non-null. Else, both non-error response types
 * will have a type of "null"//from   ww  w.  j  av  a2s . c om
 */
public static ImmutableList<Ds3ResponseCode> createTestResponseCodes(final boolean hasPayload) {
    final ImmutableList.Builder<Ds3ResponseCode> builder = ImmutableList.builder();

    if (hasPayload) {
        builder.add(new Ds3ResponseCode(200, ImmutableList
                .of(new Ds3ResponseType("com.spectralogic.s3.server.domain.JobWithChunksApiBean", null))));
    } else {
        builder.add(new Ds3ResponseCode(200, ImmutableList.of(new Ds3ResponseType("null", null))));
    }

    builder.add(new Ds3ResponseCode(204, ImmutableList.of(new Ds3ResponseType("null", null))));

    builder.add(new Ds3ResponseCode(404, ImmutableList
            .of(new Ds3ResponseType("com.spectralogic.s3.server.domain.HttpErrorResultApiBean", null))));

    return builder.build();
}

From source file:com.facebook.buck.core.util.graph.TopologicalSort.java

public static <T extends Comparable<?>> ImmutableList<T> sort(TraversableGraph<T> graph) {

    // AtomicInteger is used to decrement the integer value in-place.
    Map<T, AtomicInteger> effectiveOutDegreesOfExplorableNodes = new HashMap<>();
    Queue<T> nextLevel = Queues.newArrayDeque(graph.getNodesWithNoOutgoingEdges());
    Set<T> visitedNodes = new HashSet<>();
    ImmutableList.Builder<T> toReturn = ImmutableList.builder();

    while (!nextLevel.isEmpty()) {
        Queue<T> toExplore = nextLevel;
        nextLevel = Queues.newArrayDeque();

        Set<T> level = new TreeSet<>();

        while (!toExplore.isEmpty()) {
            T node = toExplore.remove();
            Preconditions.checkState(!visitedNodes.contains(node),
                    "The queue of nodes to explore should not contain a node that has already been"
                            + " visited.");

            level.add(node);//  w w  w  .  jav a2 s . co m
            visitedNodes.add(node);

            // Only add a node to the set of nodes to be explored if all the nodes it depends on have
            // been visited already. We achieve the same by keeping track of the out degrees of
            // explorable nodes. After visiting a node, decrement the out degree of each of its parent
            // node. When the out degree reaches zero, it is safe to add that node to the list of nodes
            // to explore next.
            for (T exploreCandidate : graph.getIncomingNodesFor(node)) {
                if (!effectiveOutDegreesOfExplorableNodes.containsKey(exploreCandidate)) {
                    effectiveOutDegreesOfExplorableNodes.put(exploreCandidate,
                            new AtomicInteger(Iterables.size(graph.getOutgoingNodesFor(exploreCandidate))));
                }
                if (effectiveOutDegreesOfExplorableNodes.get(exploreCandidate).decrementAndGet() == 0) {
                    nextLevel.add(exploreCandidate);
                }
            }
        }
        toReturn.addAll(level);
    }

    return toReturn.build();
}

From source file:com.google.devtools.build.xcode.xcodegen.RelativePaths.java

/**
 * Converts each item in {@code pathStrings} using {@link #fromString(FileSystem, String)}.
 *///from w ww  .  ja va  2  s  .  c o  m
static List<Path> fromStrings(FileSystem fileSystem, Iterable<String> pathStrings) {
    ImmutableList.Builder<Path> result = new ImmutableList.Builder<>();
    for (String pathString : pathStrings) {
        result.add(fromString(fileSystem, pathString));
    }
    return result.build();
}

From source file:com.google.api.codegen.FlatteningConfig.java

/**
 * Creates an instance of FlatteningConfig based on FlatteningConfigProto, linking it up with the
 * provided method.//from  w  ww  . j a  v  a  2s . co m
 */
@Nullable
public static FlatteningConfig createFlattening(DiagCollector diagCollector, FlatteningConfigProto flattening,
        Method method) {
    boolean missing = false;
    ImmutableList.Builder<ImmutableList<Field>> flatteningGroupsBuilder = ImmutableList.builder();
    for (FlatteningGroupProto flatteningGroup : flattening.getGroupsList()) {
        ImmutableList.Builder<Field> parametersBuilder = ImmutableList.builder();
        for (String parameter : flatteningGroup.getParametersList()) {
            Field parameterField = method.getInputMessage().lookupField(parameter);
            if (parameterField != null) {
                parametersBuilder.add(parameterField);
            } else {
                diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL,
                        "Field missing for flattening: method = %s, message type = %s, field = %s",
                        method.getFullName(), method.getInputMessage().getFullName(), parameter));
                missing = true;
            }
        }
        flatteningGroupsBuilder.add(parametersBuilder.build());
    }
    if (missing) {
        return null;
    }
    return new FlatteningConfig(flatteningGroupsBuilder.build());
}

From source file:org.apache.beam.runners.spark.SparkTransformOverrides.java

public static List<PTransformOverride> getDefaultOverrides(boolean streaming) {
    ImmutableList.Builder<PTransformOverride> builder = ImmutableList.builder();
    // TODO: [BEAM-5358] Support @RequiresStableInput on Spark runner
    builder.add(//from   w ww.ja v a 2s.  com
            PTransformOverride.of(PTransformMatchers.requiresStableInputParDoMulti(), UnsupportedOverrideFactory
                    .withMessage("Spark runner currently doesn't support @RequiresStableInput annotation.")));
    if (!streaming) {
        builder.add(PTransformOverride.of(PTransformMatchers.splittableParDo(),
                new SplittableParDo.OverrideFactory()))
                .add(PTransformOverride.of(
                        PTransformMatchers.urnEqualTo(PTransformTranslation.SPLITTABLE_PROCESS_KEYED_URN),
                        new SplittableParDoNaiveBounded.OverrideFactory()));
    }
    return builder.build();
}

From source file:org.hawkular.client.test.utils.CounterDataGenerator.java

public static List<CounterDataPoint> gen(int size) {
    BTG ts = new BTG();
    Random random = new Random();
    long value = 1000;
    Builder<CounterDataPoint> builder = new ImmutableList.Builder<>();
    for (int i = 0; i < size; i++) {
        DataPoint<Long> point = new DataPoint<>(ts.nextMilli(), value);
        builder.add(new CounterDataPoint(point));
        value = value + random.nextInt(100);
    }//from  w  ww . j av a  2  s  .  co m
    return builder.build();
}

From source file:com.google.api.tools.framework.importers.swagger.aspects.auth.model.SecurityRequirementModel.java

public static ImmutableList<AuthRequirement> createAuthRequirements(
        Map<String, SecurityRequirementModel> authRequirements) {
    ImmutableList.Builder<AuthRequirement> authRequirementsList = ImmutableList.builder();
    for (Map.Entry<String, SecurityRequirementModel> authReq : authRequirements.entrySet()) {
        AuthRequirement.Builder authRequirement = AuthRequirement.newBuilder();
        authRequirement.setProviderId(authReq.getKey());
        authRequirement.setAudiences(Joiner.on(",").join(authReq.getValue().getAudiences()));
        authRequirementsList.add(authRequirement.build());
    }//from  www.j a v a  2 s .c  om
    return authRequirementsList.build();
}