Example usage for com.google.common.collect ImmutableList.Builder add

List of usage examples for com.google.common.collect ImmutableList.Builder add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:com.infobip.jira.IssueKey.java

/**
 * Generates {@link IssueKey IssueKeys} from {@link Commit#getMessage()}  changesets message}.
 *
 * @param changeset containing message with Jira issue key
 *
 * @return all {@link IssueKey IssueKeys} that could be extracted from
 *//*w  w  w .ja v  a  2 s .  c o  m*/
public static Iterable<IssueKey> of(Commit changeset) {

    Matcher matcher = pattern.matcher(changeset.getMessage());

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

    while (matcher.find()) {
        builder.add(new IssueKey(new ProjectKey(matcher.group(1)), new IssueId(matcher.group(2))));
    }

    return builder.build();
}

From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.CreateObjectRequestGenerator.java

/**
 * Creates the create deprecated object request constructor that
 * uses the Channel parameter//from  w ww  .ja  v a 2  s  .  c  o  m
 */
protected static RequestConstructor createDeprecatedConstructor(final ImmutableList<Arguments> constructorArgs,
        final String requestName, final Ds3DocSpec docSpec) {
    final ImmutableList.Builder<Arguments> builder = ImmutableList.builder();
    builder.addAll(constructorArgs);
    builder.add(new Arguments("SeekableByteChannel", "Channel"));

    final ImmutableList<String> additionalLines = ImmutableList
            .of("this.stream = new SeekableByteChannelInputStream(channel);");

    final ImmutableList<Arguments> updatedArgs = builder.build();
    final ImmutableList<String> argNames = updatedArgs.stream().map(Arguments::getName)
            .collect(GuavaCollectors.immutableList());

    return new RequestConstructor(true, additionalLines, updatedArgs, updatedArgs, ImmutableList.of(),
            toConstructorDocs(requestName, argNames, docSpec, 1));
}

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

/**
 * Returns a shortest path from {@code nodeU} to {@code nodeV} in {@code graph} as a list of the
 * nodes visited in sequence, including both {@code nodeU} and {@code nodeV}. (Note that there may
 * be many possible shortest paths.)//from  w ww  .  j a  v  a2s.  c  o m
 *
 * <p>If {@code nodeV} is not {@link
 * com.google.common.graph.Graphs#reachableNodes(com.google.common.graph.Graph, Object) reachable}
 * from {@code nodeU}, the list returned is empty.
 *
 * @throws IllegalArgumentException if {@code nodeU} or {@code nodeV} is not present in {@code
 *     graph}
 */
public static <N> ImmutableList<N> shortestPath(SuccessorsFunction<N> graph, N nodeU, N nodeV) {
    if (nodeU.equals(nodeV)) {
        return ImmutableList.of(nodeU);
    }
    Set<N> successors = ImmutableSet.copyOf(graph.successors(nodeU));
    if (successors.contains(nodeV)) {
        return ImmutableList.of(nodeU, nodeV);
    }

    Map<N, N> visitedNodeToPathPredecessor = new HashMap<>(); // encodes shortest path tree
    for (N node : successors) {
        visitedNodeToPathPredecessor.put(node, nodeU);
    }
    Queue<N> currentNodes = new ArrayDeque<N>(successors);
    Queue<N> nextNodes = new ArrayDeque<N>();

    // Perform a breadth-first traversal starting with the successors of nodeU.
    while (!currentNodes.isEmpty()) {
        while (!currentNodes.isEmpty()) {
            N currentNode = currentNodes.remove();
            for (N nextNode : graph.successors(currentNode)) {
                if (visitedNodeToPathPredecessor.containsKey(nextNode)) {
                    continue; // we already have a shortest path to nextNode
                }
                visitedNodeToPathPredecessor.put(nextNode, currentNode);
                if (nextNode.equals(nodeV)) {
                    ImmutableList.Builder<N> builder = ImmutableList.builder();
                    N node = nodeV;
                    builder.add(node);
                    while (!node.equals(nodeU)) {
                        node = visitedNodeToPathPredecessor.get(node);
                        builder.add(node);
                    }
                    return builder.build().reverse();
                }
                nextNodes.add(nextNode);
            }
        }
        Queue<N> emptyQueue = currentNodes;
        currentNodes = nextNodes;
        nextNodes = emptyQueue; // reusing empty queue faster than allocating new one
    }

    return ImmutableList.of();
}

From source file:com.facebook.buck.cpp.AbstractNativeBuildable.java

private static void addMkdirStepIfNeeded(Set<Path> createdDirectories, ImmutableList.Builder<Step> steps,
        Path directory) {//  w  ww  .  j  a  v  a2s.co m
    if (createdDirectories.add(directory)) {
        steps.add(new MkdirStep(directory));
    }
}

From source file:com.spotify.apollo.route.Rule.java

private static ImmutableList<String> processMethods(List<String> methods) {
    ImmutableList.Builder<String> builder = ImmutableList.<String>builder().addAll(methods);
    if (methods.contains("GET")) {
        builder.add("HEAD");
    }//from  w ww  .  j  a v  a 2s .c  o  m
    return builder.build();
}

From source file:io.prestosql.tests.statistics.MetricComparator.java

private static List<OptionalDouble> getActualValues(List<Metric> metrics, String query, QueryRunner runner) {
    String statsQuery = "SELECT "
            + metrics.stream().map(Metric::getComputingAggregationSql).collect(joining(",")) + " FROM (" + query
            + ")";
    try {// w w  w.  ja  va  2 s. co m
        MaterializedRow actualValuesRow = getOnlyElement(runner.execute(statsQuery).getMaterializedRows());

        ImmutableList.Builder<OptionalDouble> actualValues = ImmutableList.builder();
        for (int i = 0; i < metrics.size(); ++i) {
            actualValues.add(metrics.get(i).getValueFromAggregationQueryResult(actualValuesRow.getField(i)));
        }
        return actualValues.build();
    } catch (Exception e) {
        throw new RuntimeException(format("Failed to execute query to compute actual values: %s", statsQuery),
                e);
    }
}

From source file:com.spectralogic.ds3autogen.utils.Ds3TypeClassificationUtil.java

/**
 * Gets the list of Ds3Element names contained within the Ds3Type, or an
 * empty list if no elements exist.// w  w w  .j a v  a 2s.  co  m
 */
protected static ImmutableList<String> getElementNames(final Ds3Type type) {
    if (isEmpty(type.getElements())) {
        return ImmutableList.of();
    }
    final ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (final Ds3Element element : type.getElements()) {
        builder.add(element.getName());
    }
    return builder.build();
}

From source file:com.spotify.helios.common.Resolver.java

private static List<URI> resolve(final String srvName, final String protocol, final String domain,
        final DnsSrvResolver resolver) {
    final String name;
    switch (protocol) {
    case "https":
        name = httpsSrv(srvName, domain);
        break;//  w w  w  .j  av  a 2 s . com
    case "http":
        name = httpSrv(srvName, domain);
        break;
    default:
        throw new IllegalArgumentException(
                String.format("Invalid protocol: %s. Helios SRV record can only be https or http.", protocol));
    }

    final List<LookupResult> lookupResults = resolver.resolve(name);

    final ImmutableList.Builder<URI> endpoints = ImmutableList.builder();
    for (final LookupResult result : lookupResults) {
        endpoints.add(protocol(protocol, result.host(), result.port()));
    }

    return endpoints.build();
}

From source file:org.sonar.duplications.internal.pmd.TokenizerBridge.java

private static void addNewTokensLine(ImmutableList.Builder<TokensLine> result, int startUnit, int endUnit,
        int startLine, StringBuilder sb) {
    if (sb.length() != 0) {
        result.add(new TokensLine(startUnit, endUnit, startLine, sb.toString()));
        sb.setLength(0);//  w w w.  j  a  v  a  2 s  .com
    }
}

From source file:org.sonar.java.model.expression.NewArrayTreeImpl.java

private static ImmutableList.Builder<Tree> addIfNotNull(ImmutableList.Builder<Tree> builder,
        @Nullable Tree tree) {//from  w  ww. j a va 2  s .com
    if (tree != null) {
        builder.add(tree);
    }
    return builder;
}