List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:com.teradata.tpcds.distribution.FipsCountyDistribution.java
public static FipsCountyDistribution buildFipsCountyDistribution() { ImmutableList.Builder<String> countiesBuilder = ImmutableList.builder(); ImmutableList.Builder<String> stateAbbreviationsBuilder = ImmutableList.builder(); ImmutableList.Builder<Integer> zipPrefixesBuilder = ImmutableList.builder(); ImmutableList.Builder<Integer> gmtOffsetsBuilder = ImmutableList.builder(); List<WeightsBuilder> weightsBuilders = new ArrayList<>(NUM_WEIGHT_FIELDS); for (int i = 0; i < NUM_WEIGHT_FIELDS; i++) { weightsBuilders.add(new WeightsBuilder()); }/*from ww w . j ava2 s . c o m*/ Iterator<List<String>> iterator = getDistributionIterator(VALUES_AND_WEIGHTS_FILENAME); while (iterator.hasNext()) { List<String> fields = iterator.next(); checkState(fields.size() == 2, "Expected line to contain 2 parts but it contains %d: %s", fields.size(), fields); List<String> values = getListFromCommaSeparatedValues(fields.get(0)); checkState(values.size() == 6, "Expected line to contain 6 values, but it contained %d, %s", values.size(), values); // fips codes and state names are never used, so we leave them out countiesBuilder.add(values.get(1)); stateAbbreviationsBuilder.add(values.get(2)); zipPrefixesBuilder.add(Integer.parseInt(values.get(4))); gmtOffsetsBuilder.add(Integer.parseInt(values.get(5))); List<String> weights = getListFromCommaSeparatedValues(fields.get(1)); checkState(weights.size() == NUM_WEIGHT_FIELDS, "Expected line to contain %d weights, but it contained %d, %s", NUM_WEIGHT_FIELDS, weights.size(), values); for (int i = 0; i < weights.size(); i++) { weightsBuilders.get(i).computeAndAddNextWeight(Integer.valueOf(weights.get(i))); } } ImmutableList.Builder<ImmutableList<Integer>> weightsListBuilder = ImmutableList .<ImmutableList<Integer>>builder(); for (WeightsBuilder weightsBuilder : weightsBuilders) { weightsListBuilder.add(weightsBuilder.build()); } return new FipsCountyDistribution(countiesBuilder.build(), stateAbbreviationsBuilder.build(), zipPrefixesBuilder.build(), gmtOffsetsBuilder.build(), weightsListBuilder.build()); }
From source file:org.apache.whirr.service.vblob.VBlobStatements.java
private static Statement writeConfigJson(VBlobConfig config) { Map<Object, Object> configJ = ImmutableMap.builder() .put("drivers", ImmutableList.builder() .add(ImmutableMap.of("fs-1", ImmutableMap.builder().put("type", "fs").put("option", ImmutableMap.of()).build())) .build())//from www . jav a 2 s . c o m .put("port", config.getS3Port()).put("current_driver", "fs-1").put("logtype", "winston") .put("logfile", config.getHome() + "/log.txt").put("auth", "s3").put("debug", true) .put("account_api", false).put("keyID", config.getAuthorizedAccessKey()) .put("secretID", config.getAuthorizedSecretKey()).build(); String configJson = new GsonBuilder().setPrettyPrinting().create().toJson(configJ); String fileName = config.getHome() + "/config.json"; return createOrOverwriteFile(fileName, Collections.singleton(configJson)); }
From source file:com.netflix.exhibitor.core.state.ServerList.java
public ServerList(String serverSpec) { ImmutableList.Builder<ServerSpec> builder = ImmutableList.builder(); String[] items = serverSpec.split(","); for (String item : items) { String trimmed = item.trim(); if (trimmed.length() > 0) { String[] parts = trimmed.split(":"); String code = getPart(parts, 0); String id = getPart(parts, 1); String hostname = getPart(parts, 2); if ((code != null) && (id != null) && (hostname != null)) { try { int serverId = Integer.parseInt(id); builder.add(new ServerSpec(hostname, serverId, ServerType.fromCode(code))); } catch (NumberFormatException ignore) { // ignore }// w w w. java 2 s . co m } } } specs = builder.build(); }
From source file:com.facebook.presto.raptor.RaptorPageSource.java
public RaptorPageSource(Iterable<Iterable<Block>> channels) { ImmutableList.Builder<Iterator<Block>> iterators = ImmutableList.builder(); for (Iterable<Block> channel : channels) { iterators.add(channel.iterator()); }/*from w w w . j a v a 2s . c om*/ this.iterators = iterators.build(); blockPositions = new ArrayList<>(this.iterators.size()); if (this.iterators.get(0).hasNext()) { for (Iterator<Block> iterator : this.iterators) { blockPositions.add(new BlockPosition(iterator.next())); } } else { // no data for (Iterator<Block> iterator : this.iterators) { checkState(!iterator.hasNext()); } finished = true; } }
From source file:org.ratpackframework.path.internal.TokenPathBinder.java
public TokenPathBinder(String path, boolean exact) { Validations.noLeadingForwardSlash(path, "token path"); ImmutableList.Builder<String> namesBuilder = ImmutableList.builder(); String pattern = Pattern.quote(path); Pattern placeholderPattern = Pattern.compile("(/?:(\\w+)\\??)"); Matcher matchResult = placeholderPattern.matcher(path); boolean hasOptional = false; while (matchResult.find()) { String name = matchResult.group(1); boolean optional = name.endsWith("?"); hasOptional = hasOptional || optional; if (hasOptional && !optional) { throw new IllegalArgumentException(String.format( "path %s should not define mandatory parameters after an optional parameter", path)); }/*from w ww.ja v a 2 s . c o m*/ pattern = pattern.replaceFirst(Pattern.quote(name), "\\\\E/?([^/?&#]+)" + (optional ? "?" : "") + "\\\\Q"); namesBuilder.add(matchResult.group(2)); } StringBuilder patternBuilder = new StringBuilder("(").append(pattern).append(")"); if (!exact) { patternBuilder.append("(?:/.*)?"); } this.regex = Pattern.compile(patternBuilder.toString()); this.tokenNames = namesBuilder.build(); }
From source file:com.facebook.buck.rules.args.Arg.java
public static ImmutableList<String> stringifyList(Arg input) { ImmutableList.Builder<String> builder = ImmutableList.builder(); input.appendToCommandLine(builder);//from w w w . j a va2s.c om return builder.build(); }
From source file:be.dnsbelgium.rdap.core.Notice.java
@JsonCreator public Notice(@JsonProperty("title") String title, @JsonProperty("type") String type, @JsonProperty("description") List<String> description, @JsonProperty("links") List<Link> links) { this.title = title; this.type = type; this.description = (description == null) ? null : new ImmutableList.Builder<String>().addAll(description).build(); this.links = (links == null) ? null : new ImmutableList.Builder<Link>().addAll(links).build(); }
From source file:org.gradle.internal.component.LegacyConfigurationsSupplier.java
@Override public ImmutableList<? extends ConfigurationMetadata> get() { Set<String> configurationNames = targetComponent.getConfigurationNames(); ImmutableList.Builder<ConfigurationMetadata> builder = new ImmutableList.Builder<ConfigurationMetadata>(); for (String configurationName : configurationNames) { ConfigurationMetadata configuration = targetComponent.getConfiguration(configurationName); if (configuration.isCanBeConsumed()) { builder.add(configuration);// ww w . ja v a 2 s . c o m } } return builder.build(); }
From source file:com.greensopinion.finance.services.domain.CategorizerService.java
public List<Transaction> categorize(List<Transaction> transactions) { checkNotNull(transactions);/* w w w. j a va2s . c o m*/ ImmutableList.Builder<Transaction> builder = ImmutableList.builder(); for (Transaction transaction : transactions) { builder.add(categorize(transaction)); } return builder.build(); }
From source file:nz.co.fortytwo.signalk.util.TrackSimplifier.java
static List<Position> dpReduction(List<Position> track, double tolerance) { // degenerate case if (track.size() < 3) { return track; }/*from w w w. j ava 2s .c om*/ double tol2 = tolerance * tolerance; boolean[] marks = new boolean[track.size()]; marks[0] = true; marks[marks.length - 1] = true; mark(track, tol2, 0, track.size() - 1, marks); ImmutableList.Builder<Position> result = ImmutableList.builder(); for (int i = 0; i < marks.length; i++) { if (marks[i]) { result.add(track.get(i)); } } return result.build(); }