List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:io.prestosql.type.FunctionType.java
private static List<TypeSignatureParameter> typeParameters(List<Type> argumentTypes, Type returnType) { requireNonNull(returnType, "returnType is null"); requireNonNull(argumentTypes, "argumentTypes is null"); ImmutableList.Builder<TypeSignatureParameter> builder = ImmutableList.builder(); argumentTypes.stream().map(Type::getTypeSignature).map(TypeSignatureParameter::of).forEach(builder::add); builder.add(TypeSignatureParameter.of(returnType.getTypeSignature())); return builder.build(); }
From source file:com.facebook.presto.type.TypeUtils.java
public static Page getHashPage(Page page, List<? extends Type> types, List<Integer> hashChannels) { Block[] blocks = Arrays.copyOf(page.getBlocks(), page.getChannelCount() + 1); ImmutableList.Builder<Type> hashTypes = ImmutableList.builder(); Block[] hashBlocks = new Block[hashChannels.size()]; int hashBlockIndex = 0; for (int channel : hashChannels) { hashTypes.add(types.get(channel)); hashBlocks[hashBlockIndex++] = blocks[channel]; }/*from w ww. ja v a 2 s .c o m*/ blocks[page.getChannelCount()] = getHashBlock(hashTypes.build(), hashBlocks); return new Page(blocks); }
From source file:org.terasology.util.io.FileScanning.java
/** * Scans a path, recursing all paths matching the scanFilter and returning all files matching the fileFilter * @param rootPath The path to scan// w w w . ja v a 2s . c o m * @param scanFilter A PathMatcher indicating which subpaths to scan * @param fileFilter A PathMatcher indicating which files to return * @return A list of matching files within the path tree * @throws IOException If there is a problem walking the file tree */ public static List<Path> findFilesInPath(Path rootPath, PathMatcher scanFilter, PathMatcher fileFilter) throws IOException { final ImmutableList.Builder<Path> resultBuilder = ImmutableList.builder(); Files.walkFileTree(rootPath, new FileScanning.FilteredFileVisitor(scanFilter, fileFilter) { @Override protected void onMatch(Path file) { resultBuilder.add(file); } }); return resultBuilder.build(); }
From source file:com.facebook.buck.config.Configs.java
/** * Generates a Buck config by merging configs from specified locations on disk. * * In order://from w ww. j a v a 2 s . c o m * * <ol> * <li>{@code /etc/buckconfig}</li> * <li>Files (in lexicographical order) in {@code /etc/buckconfig.d}</li> * <li>{@code <HOME>/.buckconfig}</li> * <li>Files (in lexicographical order) in {@code <HOME>/buckconfig.d}</li> * <li>{@code <PROJECT ROOT>/.buckconfig}</li> * <li>{@code <PROJECT ROOT>/.buckconfig.local}</li> * <li>Any overrides (usually from the command line)</li> * </ol> * * @param root Project root. * @param configOverrides Config overrides to merge in after the other sources. * @return the resulting {@code Config}. * @throws IOException on any exceptions during the underlying filesystem operations. */ public static Config createDefaultConfig(Path root, RawConfig configOverrides) throws IOException { LOG.debug("Loading configuration for %s", root); ImmutableList.Builder<Path> configFileBuilder = ImmutableList.builder(); configFileBuilder.addAll(listFiles(GLOBAL_BUCK_CONFIG_DIRECTORY_PATH)); if (Files.isRegularFile(GLOBAL_BUCK_CONFIG_FILE_PATH)) { configFileBuilder.add(GLOBAL_BUCK_CONFIG_FILE_PATH); } Path homeDirectory = Paths.get(System.getProperty("user.home")); Path userConfigDir = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_DIRECTORY_NAME); configFileBuilder.addAll(listFiles(userConfigDir)); Path userConfigFile = homeDirectory.resolve(DEFAULT_BUCK_CONFIG_FILE_NAME); if (Files.isRegularFile(userConfigFile)) { configFileBuilder.add(userConfigFile); } Path configFile = root.resolve(DEFAULT_BUCK_CONFIG_FILE_NAME); if (Files.isRegularFile(configFile)) { configFileBuilder.add(configFile); } Path overrideConfigFile = root.resolve(DEFAULT_BUCK_CONFIG_OVERRIDE_FILE_NAME); if (Files.isRegularFile(overrideConfigFile)) { configFileBuilder.add(overrideConfigFile); } ImmutableList<Path> configFiles = configFileBuilder.build(); RawConfig.Builder builder = RawConfig.builder(); for (Path file : configFiles) { try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { ImmutableMap<String, ImmutableMap<String, String>> parsedConfiguration = Inis.read(reader); LOG.debug("Loaded a configuration file %s: %s", file, parsedConfiguration); builder.putAll(parsedConfiguration); } } LOG.debug("Adding configuration overrides %s", configOverrides); builder.putAll(configOverrides); return new Config(builder.build()); }
From source file:com.spectralogic.ds3autogen.c.converters.RequestConverter.java
public static ImmutableList<Parameter> getParamList(final String responseType, final Ds3DocSpec docSpec) { final ImmutableList.Builder<Parameter> builder = ImmutableList.builder(); builder.add(new Parameter(ParameterModifier.CONST, "ds3_client", "client", ParameterPointerType.SINGLE_POINTER, true)); builder.add(new Parameter(ParameterModifier.CONST, "ds3_request", "request", ParameterPointerType.SINGLE_POINTER, true)); if (!responseType.isEmpty()) { builder.add(new Parameter(ParameterModifier.NONE, responseType, "response", ParameterPointerType.DOUBLE_POINTER, true, toParamDocs(Helper.underscoreToCamel(responseType), docSpec))); }/*from w w w . j a va 2s. c o m*/ return builder.build(); }
From source file:net.devbase.jfreesteel.Utils.java
/** * Formats an array of bytes as a string. * <p>// w ww . j a v a2 s . c o 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.teradata.tpcds.distribution.StringValuesDistribution.java
public static StringValuesDistribution buildStringValuesDistribution(String valuesAndWeightsFilename, int numValueFields, int numWeightFields) { Iterator<List<String>> iterator = getDistributionIterator(valuesAndWeightsFilename); List<ImmutableList.Builder<String>> valuesBuilders = new ArrayList<>(numValueFields); for (int i = 0; i < numValueFields; i++) { valuesBuilders.add(ImmutableList.<String>builder()); }/*from ww w . j av a 2s . co m*/ List<WeightsBuilder> weightsBuilders = new ArrayList<>(numWeightFields); for (int i = 0; i < numWeightFields; i++) { weightsBuilders.add(new WeightsBuilder()); } while (iterator.hasNext()) { List<String> fields = iterator.next(); checkState(fields.size() == 2, "Expected line to contain 2 parts but it contains %s: %s", fields.size(), fields); List<String> values = getListFromCommaSeparatedValues(fields.get(0)); checkState(values.size() == numValueFields, "Expected line to contain %s values, but it contained %s, %s", numValueFields, values.size(), values); for (int i = 0; i < values.size(); i++) { valuesBuilders.get(i).add(values.get(i)); } List<String> weights = getListFromCommaSeparatedValues(fields.get(1)); checkState(weights.size() == numWeightFields, "Expected line to contain %s weights, but it contained %s, %s", numWeightFields, weights.size(), weights); for (int i = 0; i < weights.size(); i++) { weightsBuilders.get(i).computeAndAddNextWeight(Integer.parseInt(weights.get(i))); } } ImmutableList.Builder<ImmutableList<String>> valuesListsBuilder = ImmutableList .<ImmutableList<String>>builder(); for (ImmutableList.Builder<String> valuesBuilder : valuesBuilders) { valuesListsBuilder.add(valuesBuilder.build()); } ImmutableList<ImmutableList<String>> valuesLists = valuesListsBuilder.build(); ImmutableList.Builder<ImmutableList<Integer>> weightsListBuilder = ImmutableList .<ImmutableList<Integer>>builder(); for (WeightsBuilder weightsBuilder : weightsBuilders) { weightsListBuilder.add(weightsBuilder.build()); } ImmutableList<ImmutableList<Integer>> weightsLists = weightsListBuilder.build(); return new StringValuesDistribution(valuesLists, weightsLists); }
From source file:com.google.devtools.build.lib.runtime.commands.InfoCommand.java
public static List<String> getHardwiredInfoItemNames(String productName) { ImmutableList.Builder<String> result = new ImmutableList.Builder<>(); for (String name : InfoCommand.getHardwiredInfoItemMap(null, productName).keySet()) { result.add(name); }/*from ww w . j a v a2s . c o m*/ return result.build(); }
From source file:com.textocat.textokit.commons.cas.FSUtils.java
public static List<String> toList(StringArrayFS fsArr) { if (fsArr == null) return ImmutableList.of(); ImmutableList.Builder<String> resultBuilder = ImmutableList.builder(); for (int i = 0; i < fsArr.size(); i++) { resultBuilder.add(fsArr.get(i)); }//from w w w .j ava2s . com return resultBuilder.build(); }
From source file:com.spectralogic.ds3autogen.net.generators.requestmodels.BaseRequestGenerator.java
/** * Converts the list of optional arguments into a list of arguments requiring a with constructor. There may * be more with-constructors that optional arguments if an optional argument is of type Guid. *//*w w w . j av a2 s. c o m*/ protected static ImmutableList<WithConstructorVariable> toWithConstructorList( final ImmutableList<NetNullableVariable> optionalArgs, final String requestName, final Ds3DocSpec docSpec) { if (isEmpty(optionalArgs)) { return ImmutableList.of(); } final ImmutableList.Builder<WithConstructorVariable> builder = ImmutableList.builder(); for (final NetNullableVariable arg : optionalArgs) { builder.add(toWithConstructor(arg, requestName, docSpec)); if (arg.getType().equals("Guid")) { builder.add(toWithConstructor(convertGuidToString(arg), requestName, docSpec)); } } return builder.build(); }