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.api.codegen.util.py.PythonRenderingUtil.java

public List<String> trimDocs(List<String> docLines) {
    // TODO (geigerj): "trimming" the docs means we don't support code blocks. Investigate
    // supporting code blocks here.
    ImmutableList.Builder<String> trimmedDocLines = ImmutableList.builder();
    for (int i = 0; i < docLines.size(); ++i) {
        String line = docLines.get(i).trim();
        if (line.equals("::")) {
            ++i;/*from   ww w. j a va 2  s. c om*/
        } else {
            trimmedDocLines.add(line);
        }
    }
    return trimmedDocLines.build();
}

From source file:com.olacabs.fabric.compute.sources.kafka.impl.KafkaMetadataClient.java

public static List<HostPort> parseBrokerString(final String brokers) {
    ImmutableList.Builder<HostPort> listBuilder = ImmutableList.builder();
    for (String hostport : brokers.split(",")) {
        final String[] components = hostport.split(":");
        HostPort hostPort = HostPort.builder().host(components[0]).port(Integer.parseInt(components[1]))
                .build();//ww w.  j  a  va 2  s.c o m
        listBuilder.add(hostPort);
    }
    return listBuilder.build();
}

From source file:org.jclouds.rackspace.autoscale.v1.internal.ParseHelper.java

public static ImmutableMap<String, Object> buildLaunchConfigurationRequestMap(Map<String, Object> postParams) {
    LaunchConfiguration launchConfigurationRequest = (LaunchConfiguration) postParams
            .get("launchConfiguration");

    ImmutableMap.Builder<String, Object> launchConfigurationMapBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<String, Object> argsBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<String, Object> serverBuilder = ImmutableMap.builder();
    ImmutableList.Builder<Map<String, String>> networksBuilder = ImmutableList.builder();

    for (String networkId : launchConfigurationRequest.getNetworks()) {
        Map<String, String> network = Maps.newHashMap();
        network.put("uuid", networkId);
        networksBuilder.add(network);//w w  w  .  j  av  a 2  s.c o  m
    }

    serverBuilder.put("name", launchConfigurationRequest.getServerName());
    serverBuilder.put("imageRef", launchConfigurationRequest.getServerImageRef());
    serverBuilder.put("flavorRef", launchConfigurationRequest.getServerFlavorRef());
    serverBuilder.put("OS-DCF:diskConfig", launchConfigurationRequest.getServerDiskConfig());
    serverBuilder.put("metadata", launchConfigurationRequest.getServerMetadata());
    serverBuilder.put("personality", launchConfigurationRequest.getPersonalities());
    serverBuilder.put("networks", networksBuilder.build());

    argsBuilder.put("loadBalancers", launchConfigurationRequest.getLoadBalancers());
    argsBuilder.put("server", serverBuilder.build());

    launchConfigurationMapBuilder.put("type", launchConfigurationRequest.getType().toString());
    launchConfigurationMapBuilder.put("args", argsBuilder.build());

    return launchConfigurationMapBuilder.build();
}

From source file:org.eclipse.buildship.core.gradle.MissingFeatures.java

public List<Pair<GradleVersion, String>> getMissingFeatures() {
    ImmutableList.Builder<Pair<GradleVersion, String>> missingFeatures = ImmutableList.builder();
    addIfNeeded("2.1", "Cancellation support", missingFeatures);
    addIfNeeded("2.4", "Test progress visualization", missingFeatures);
    addIfNeeded("2.5", "Build/task progress visualization", missingFeatures);
    addIfNeeded("2.5", "Transitive dependency managament", missingFeatures);
    addIfNeeded("2.6", "Tests can be run from the Executions View", missingFeatures);
    addIfNeeded("2.6", "Failed tests can be re-run from the Executions View", missingFeatures);
    addIfNeeded("2.7", "Test classes and methods can be run from the Editor", missingFeatures);
    addIfNeeded("2.9", "Custom project natures and build commands are added", missingFeatures);
    addIfNeeded("2.10", "Language source level is set on Java projects", missingFeatures);
    addIfNeeded("2.11", "Target bytecode version is set on Java projects", missingFeatures);
    addIfNeeded("2.11", "Java runtime is set on Java projects", missingFeatures);
    addIfNeeded("2.13", "Improved performance when loading models", missingFeatures);
    addIfNeeded("2.14", "Attributes defined for Java classpath entries", missingFeatures);
    addIfNeeded("2.14", "WTP deployment attributes defined for web projects", missingFeatures);
    addIfNeeded("3.0",
            "Output location, classpath containers, source folder excludes-includes and JRE name are set on Java projects",
            missingFeatures);/*from   w  w w  .ja v  a  2  s.c o  m*/
    addIfNeeded("3.0",
            "Java classpath customization done in 'eclipse.classpath.file.whenMerged' is synchronized",
            missingFeatures);
    return missingFeatures.build();
}

From source file:ru.org.linux.paginator.PagesInfo.java

public PagesInfo(List<String> pageLinks, int currentPage) {
    ImmutableList.Builder<Page> builder = ImmutableList.builder();

    for (int i = 0; i < pageLinks.size(); i++) {
        builder.add(new Page(pageLinks.get(i), i, i == currentPage));
    }/*from  ww  w  . ja  va 2 s.  c o m*/

    this.pageLinks = builder.build();

    hasPrevious = currentPage > 0;
    hasNext = currentPage >= 0 && (currentPage < pageLinks.size() - 1);

    if (hasPrevious) {
        previous = this.pageLinks.get(currentPage - 1).getUrl();
    } else {
        previous = null;
    }

    if (hasNext) {
        next = this.pageLinks.get(currentPage + 1).getUrl();
    } else {
        next = null;
    }
}

From source file:net.devbase.jfreesteel.Utils.java

/**
 * Formats an array of bytes as a string.
 * <p>//from   w  w  w  .  j av  a 2 s.co m
 * Silently skips leading zero bytes.
 * <p>
 * TODO(filmil): Silent zero-skipping is weird, check if this is the right thing to do.
 *
 * @param bytes the bytes to print
 * @return formatted byte string, e.g. an array of 0x00, 0x01, 0x02, 0x03
 *         gets printed as: "01:02:03"
 */
public static String bytes2HexString(byte... bytes) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    boolean skipZeros = true;
    for (byte b : bytes) {
        if (skipZeros && b == 0x00) {
            continue;
        }
        skipZeros = false;
        builder.add(String.format("%02X", b));
    }
    return Joiner.on(":").join(builder.build());
}

From source file:com.spotify.heroic.ingestion.Ingestion.java

public static Collector<Ingestion, Ingestion> reduce() {
    return results -> {
        final ImmutableList.Builder<RequestError> errors = ImmutableList.builder();
        final ImmutableList.Builder<Long> times = ImmutableList.builder();

        for (final Ingestion r : results) {
            errors.addAll(r.errors);//from w w w  .j  a  va 2s . c  o  m
            times.addAll(r.times);
        }

        return new Ingestion(errors.build(), times.build());
    };
}

From source file:com.gradleware.tooling.testing.Combinations.java

private static ImmutableList<List<Object>> getCombinationsRecursive(Map<Integer, List<?>> lists, int depth,
        Object[] current) {/*ww  w .  ja  v a2 s  .com*/
    ImmutableList.Builder<List<Object>> result = ImmutableList.builder();
    Collection<?> listAtCurrentDepth = lists.get(depth);
    for (Object element : listAtCurrentDepth) {
        current[depth] = element;
        if (depth < lists.size() - 1) {
            result.addAll(getCombinationsRecursive(lists, depth + 1, current));
        } else {
            result.add(Lists.newArrayList(current)); // use ArrayList to support null values
        }
    }
    return result.build();
}

From source file:com.google.errorprone.bugpatterns.testdata.CollectorShouldNotUseStatePositiveCases.java

public void test() {
    // BUG: Diagnostic contains: Collector.of() should not use state
    Collector.of(ImmutableList::builder, new BiConsumer<ImmutableList.Builder<Object>, Object>() {

        boolean isFirst = true;
        private static final String bob = "bob";

        @Override/* ww  w.j a va2 s .  c  o m*/
        public void accept(Builder<Object> objectBuilder, Object o) {
            if (isFirst) {
                System.out.println("it's first");
            } else {
                objectBuilder.add(o);
            }
        }
    }, (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build);

    // BUG: Diagnostic contains: Collector.of() should not use state
    Collector.of(ImmutableList::builder, new BiConsumer<ImmutableList.Builder<Object>, Object>() {

        boolean isFirst = true;
        private final String bob = "bob";
        private final String joe = "joe";

        @Override
        public void accept(Builder<Object> objectBuilder, Object o) {
            if (isFirst) {
                System.out.println("it's first");
            } else {
                objectBuilder.add(o);
            }
        }
    }, (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build);
}

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

static void addAccumulateClassNamesStep(JavaLibrary javaLibrary, BuildableContext buildableContext,
        ImmutableList.Builder<Step> steps) {

    Path pathToClassHashes = JavaLibraryRules.getPathToClassHashes(javaLibrary.getBuildTarget(),
            javaLibrary.getProjectFilesystem());
    steps.add(new MkdirStep(javaLibrary.getProjectFilesystem(), pathToClassHashes.getParent()));
    steps.add(new AccumulateClassNamesStep(javaLibrary.getProjectFilesystem(),
            Optional.ofNullable(javaLibrary.getPathToOutput()), pathToClassHashes));
    buildableContext.recordArtifact(pathToClassHashes);
}