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.google.cloud.datastore.IncompleteKey.java

static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) {
    String projectId = "";
    String namespace = "";
    if (keyPb.hasPartitionId()) {
        com.google.datastore.v1.PartitionId partitionIdPb = keyPb.getPartitionId();
        projectId = partitionIdPb.getProjectId();
        namespace = partitionIdPb.getNamespaceId();
    }/*from w w w  .  ja va  2 s. c  o m*/
    List<com.google.datastore.v1.Key.PathElement> pathElementsPb = keyPb.getPathList();
    Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");
    ImmutableList.Builder<PathElement> pathBuilder = ImmutableList.builder();
    for (com.google.datastore.v1.Key.PathElement pathElementPb : pathElementsPb) {
        pathBuilder.add(PathElement.fromPb(pathElementPb));
    }
    ImmutableList<PathElement> path = pathBuilder.build();
    PathElement leaf = path.get(path.size() - 1);
    if (leaf.getNameOrId() != null) {
        return new Key(projectId, namespace, path);
    }
    return new IncompleteKey(projectId, namespace, path);
}

From source file:com.acme.scramble.ScrambleScorerMain.java

public ScrambleScorerMain(ScrambleScorer scorer, ImmutableList.Builder<String> resultBuilder) {
    this.scorer = scorer;
    this.resultBuilder = resultBuilder;
}

From source file:com.facebook.presto.plugin.blackhole.BlackHoleSplitManager.java

@Override
public ConnectorSplitSource getSplits(ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    BlackHoleTableLayoutHandle layout = checkType(layoutHandle, BlackHoleTableLayoutHandle.class,
            "BlackHoleTableLayoutHandle");

    ImmutableList.Builder<BlackHoleSplit> builder = ImmutableList.<BlackHoleSplit>builder();

    for (int i = 0; i < layout.getSplitCount(); i++) {
        builder.add(new BlackHoleSplit(layout.getPagesPerSplit(), layout.getRowsPerPage(),
                layout.getFieldsLength()));
    }/*  w  w  w.  j a v a 2  s  .  c  o  m*/
    return new FixedSplitSource("blackhole", builder.build());
}

From source file:org.apache.calcite.interpreter.UnionNode.java

public UnionNode(Interpreter interpreter, Union rel) {
    ImmutableList.Builder<Source> builder = ImmutableList.builder();
    for (int i = 0; i < rel.getInputs().size(); i++) {
        builder.add(interpreter.source(rel, i));
    }/* w  ww.j  a  v  a 2s.  co m*/
    this.sources = builder.build();
    this.sink = interpreter.sink(rel);
    this.rel = rel;
}

From source file:com.google.acai.Dependencies.java

/**
 * Returns a topological sorting.//from   w  w  w  .  jav a 2  s .  c om
 *
 * <p>Algorithm due to Kahn, Arthur B. (1962), Topological sorting of large networks,
 * Communications of the ACM 5 (11): 558562,
 * <a href="http://dl.acm.org/citation.cfm?doid=368996.369025">doi:10.1145/368996.369025</a>.
 */
private static ImmutableList<TestingService> topologicalSorting(DirectedGraph<TestingService> dependencyGraph) {
    Queue<TestingService> rootVertices = new ArrayDeque<>(dependencyGraph.getRootVertices());
    ImmutableList.Builder<TestingService> ordered = ImmutableList.builder();
    while (!rootVertices.isEmpty()) {
        TestingService vertex = rootVertices.remove();
        ordered.add(vertex);
        for (TestingService successor : dependencyGraph.getSuccessors(vertex)) {
            dependencyGraph.removeEdge(vertex, successor);
            if (dependencyGraph.isRootVertex(successor)) {
                rootVertices.add(successor);
            }
        }
    }
    if (dependencyGraph.hasEdges()) {
        throw new IllegalArgumentException("Cycle exists in @DependsOn dependencies.");
    }
    return ordered.build();
}

From source file:com.wrmsr.nativity.util.MultiPeekingIteratorImpl.java

@Override
public Iterable<E> peek(int size) {
    while (peeked.size() < size) {
        peeked.add(iterator.next());//from  w  ww .  j  av  a 2  s .c  o m
    }
    Iterator<E> peekedIterator = peeked.iterator();
    ImmutableList.Builder<E> builder = ImmutableList.builder();
    for (int i = 0; i < size; ++i) {
        peeked.add(peekedIterator.next());
    }
    return builder.build();
}

From source file:com.google.api.codegen.config.BatchingConfig.java

/**
 * Creates an instance of BatchingConfig based on BatchingConfigProto, linking it up with the
 * provided method. On errors, null will be returned, and diagnostics are reported to the diag
 * collector./* w w w  . java  2  s  .c  o  m*/
 */
@Nullable
static BatchingConfig createBatching(DiagCollector diagCollector, BatchingConfigProto batchingConfig,
        MethodModel method) {

    BatchingDescriptorProto batchDescriptor = batchingConfig.getBatchDescriptor();
    String batchedFieldName = batchDescriptor.getBatchedField();
    FieldModel batchedField;
    batchedField = method.getInputField(batchedFieldName);
    if (batchedField == null) {
        diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL,
                "Batched field missing for batch config: method = %s, message type = %s, field = %s",
                method.getFullName(), method.getInputFullName(), batchedFieldName));
    }

    ImmutableList.Builder<GenericFieldSelector> discriminatorsBuilder = ImmutableList.builder();
    for (String discriminatorName : batchDescriptor.getDiscriminatorFieldsList()) {
        GenericFieldSelector selector = method.getInputFieldSelector(discriminatorName);
        if (selector == null) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL,
                    "Discriminator field missing for batch config: method = %s, message type = %s, "
                            + "field = %s",
                    method.getFullName(), method.getInputFullName(), discriminatorName));
        }
        discriminatorsBuilder.add(selector);
    }

    String subresponseFieldName = batchDescriptor.getSubresponseField();
    FieldModel subresponseField = null;
    if (!subresponseFieldName.isEmpty()) {
        subresponseField = method.getOutputField(subresponseFieldName);
    }

    BatchingSettingsProto batchingSettings = batchingConfig.getThresholds();
    int elementCountThreshold = batchingSettings.getElementCountThreshold();
    long requestByteThreshold = batchingSettings.getRequestByteThreshold();
    int elementCountLimit = batchingSettings.getElementCountLimit();
    long requestByteLimit = batchingSettings.getRequestByteLimit();
    long delayThresholdMillis = batchingConfig.getThresholds().getDelayThresholdMillis();
    Long flowControlElementLimit = (long) batchingConfig.getThresholds().getFlowControlElementLimit();
    if (flowControlElementLimit == 0) {
        flowControlElementLimit = null;
    }
    Long flowControlByteLimit = (long) batchingConfig.getThresholds().getFlowControlByteLimit();
    if (flowControlByteLimit == 0) {
        flowControlByteLimit = null;
    }
    FlowControlLimitConfig flowControlLimitConfig = FlowControlLimitConfig
            .fromProto(batchingConfig.getThresholds().getFlowControlLimitExceededBehavior());

    if (batchedFieldName == null) {
        return null;
    }

    return new AutoValue_BatchingConfig(elementCountThreshold, requestByteThreshold, elementCountLimit,
            requestByteLimit, delayThresholdMillis, batchedField, discriminatorsBuilder.build(),
            subresponseField, flowControlElementLimit, flowControlByteLimit, flowControlLimitConfig);
}

From source file:com.google.javascript.jscomp.ConformanceWhitelister.java

public static ImmutableList<JSError> getConformanceErrors(Compiler compiler, Node externs, Node ast,
        Requirement requirement) {//from w w  w  .  j a  v a2  s  .  c o m
    Requirement cleanedRequirement = requirement.toBuilder().clearWhitelist().clearWhitelistRegexp()
            .clearWhitelistEntry().setSeverity(Severity.ERROR).build(); // So we only have one type of error.
    ConformanceConfig cleanedConfig = ConformanceConfig.newBuilder().addRequirement(cleanedRequirement).build();

    ErrorManager oldErrorManager = compiler.getErrorManager();
    final ImmutableList.Builder<JSError> errors = ImmutableList.builder();
    try {
        // TODO(bangert): handle invalid conformance requirements
        compiler.setErrorManager(new ThreadSafeDelegatingErrorManager(oldErrorManager) {
            @Override
            public synchronized boolean shouldReportConformanceViolation(Requirement requirement,
                    Optional<Requirement.WhitelistEntry> whitelistEntry, JSError diagnostic) {
                errors.add(diagnostic);
                return false;
            }
        });
        CheckConformance check = new CheckConformance(compiler, ImmutableList.of(cleanedConfig));
        check.process(externs, ast);
    } finally {
        compiler.setErrorManager(oldErrorManager);
    }
    return errors.build();
}

From source file:ch.piratenpartei.pivote.serialize.handlers.ListHandler.java

@Override
public Object read(DataInput input) throws IOException {
    ImmutableList.Builder<Object> builder = ImmutableList.builder();
    int size = input.readInt32();
    for (int i = 0; i < size; i++) {
        builder.add(elementHandler.read(input));
    }/*w w  w . jav  a2s .  c om*/
    return builder.build();
}

From source file:com.facebook.presto.operator.StandardJoinFilterFunctionVerifier.java

public StandardJoinFilterFunctionVerifier(JoinFilterFunction filterFunction, List<List<Block>> channels) {
    this.filterFunction = requireNonNull(filterFunction, "filterFunction can not be null");

    requireNonNull(channels, "channels can not be null");
    ImmutableList.Builder<Block[]> pagesBuilder = ImmutableList.builder();
    if (!channels.isEmpty()) {
        int pagesCount = channels.get(0).size();
        for (int pageIndex = 0; pageIndex < pagesCount; ++pageIndex) {
            Block[] blocks = new Block[channels.size()];
            for (int channelIndex = 0; channelIndex < channels.size(); ++channelIndex) {
                blocks[channelIndex] = channels.get(channelIndex).get(pageIndex);
            }/*from ww  w  .j av a  2 s  . c o  m*/
            pagesBuilder.add(blocks);
        }
    }
    this.pages = pagesBuilder.build();
}