List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:io.leishvl.core.util.LocaleUtils.java
/** * Obtains an unmodifiable list of installed locales. This method is a wrapper around * {@link Locale#getAvailableLocales()}, which caches the locales and uses generics. * @return country names./*w ww .j ava2 s . c o m*/ */ public static ImmutableList<Locale> availableLocaleList() { if (availableLocaleList == null) { synchronized (LocaleUtils.class) { if (availableLocaleList == null) { final ImmutableList.Builder<Locale> builder = new ImmutableList.Builder<>(); final String[] locales = getISOCountries(); for (final String countryCode : locales) { builder.add(new Locale("", countryCode)); } availableLocaleList = builder.build(); } } } return availableLocaleList; }
From source file:com.facebook.buck.jvm.java.DirectToJarOutputSettingsSerializer.java
public static ImmutableMap<String, Object> serialize(DirectToJarOutputSettings settings) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put(OUTPUT_PATH, settings.getDirectToJarOutputPath().toString()); ImmutableList.Builder<ImmutableMap<String, Object>> serializedPatterns = ImmutableList.builder(); for (Pattern pattern : settings.getClassesToRemoveFromJar()) { serializedPatterns.add(ImmutableMap.<String, Object>of(CLASSES_TO_REMOVE_PATTERN, pattern.pattern(), CLASSES_TO_REMOVE_PATTERN_FLAGS, pattern.flags())); }/*from w w w . ja va 2 s. c om*/ builder.put(CLASSES_TO_REMOVE, serializedPatterns.build()); ImmutableList.Builder<String> serializedEntries = ImmutableList.builder(); for (Path entry : settings.getEntriesToJar()) { serializedEntries.add(entry.toString()); } builder.put(ENTRIES, serializedEntries.build()); if (settings.getMainClass().isPresent()) { builder.put(MAIN_CLASS, settings.getMainClass().get()); } if (settings.getManifestFile().isPresent()) { builder.put(MANIFEST_FILE, settings.getManifestFile().get().toString()); } return builder.build(); }
From source file:vazkii.botania.client.integration.jei.elventrade.ElvenTradeRecipeWrapper.java
@SuppressWarnings("unchecked") public ElvenTradeRecipeWrapper(RecipeElvenTrade recipe) { ImmutableList.Builder builder = ImmutableList.builder(); for (Object o : recipe.getInputs()) { if (o instanceof ItemStack) { builder.add(o);//from w ww. java 2 s. c o m } if (o instanceof String) { builder.add(OreDictionary.getOres((String) o)); } } input = builder.build(); outputs = ImmutableList.copyOf(recipe.getOutputs()); }
From source file:vazkii.botania.api.recipe.RecipeBrew.java
public RecipeBrew(Brew brew, Object... inputs) { this.brew = brew; ImmutableList.Builder<Object> inputsToSet = ImmutableList.builder(); for (Object obj : inputs) { if (obj instanceof String || obj instanceof ItemStack) inputsToSet.add(obj);// w w w. j av a2s . c om else throw new IllegalArgumentException("Invalid input"); } this.inputs = inputsToSet.build(); }
From source file:com.facebook.buck.cxx.CxxPrepareForLinkStep.java
public static CxxPrepareForLinkStep create(Path argFilePath, Path fileListPath, Iterable<Arg> linkerArgsToSupportFileList, Path output, ImmutableList<Arg> args, Linker linker, Path currentCellPath, SourcePathResolver resolver) { ImmutableList<Arg> allArgs = new ImmutableList.Builder<Arg>() .addAll(StringArg.from(linker.outputArgs(output.toString()))).addAll(args) .addAll(linkerArgsToSupportFileList).build(); boolean hasLinkArgsToSupportFileList = linkerArgsToSupportFileList.iterator().hasNext(); LOG.debug("Link command (pwd=%s): %s %s", currentCellPath.toString(), String.join("", linker.getCommandPrefix(resolver)), String.join(" ", CxxWriteArgsToFileStep.stringify(allArgs, currentCellPath))); CxxWriteArgsToFileStep createArgFileStep = new CxxWriteArgsToFileStep(argFilePath, hasLinkArgsToSupportFileList ? allArgs.stream().filter(input -> !(input instanceof FileListableLinkerInputArg)).collect( MoreCollectors.toImmutableList()) : allArgs,// w w w . j a v a2 s . c om Optional.of(Javac.ARGFILES_ESCAPER), currentCellPath); if (!hasLinkArgsToSupportFileList) { LOG.verbose("linkerArgsToSupportFileList is empty, filelist feature is not supported"); return new CxxPrepareForLinkStep(ImmutableList.of(createArgFileStep)); } CxxWriteArgsToFileStep createFileListStep = new CxxWriteArgsToFileStep(fileListPath, allArgs.stream().filter(input -> input instanceof FileListableLinkerInputArg) .collect(MoreCollectors.toImmutableList()), Optional.empty(), currentCellPath); return new CxxPrepareForLinkStep(ImmutableList.of(createArgFileStep, createFileListStep)); }
From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java
private static Iterable<InetSocketAddress> getZkAddresses(URI uri) { String zkServers = getZKServersFromDLUri(uri); String[] zkServerList = StringUtils.split(zkServers, ','); ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder(); for (String zkServer : zkServerList) { HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181); builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort())); }//from ww w . j av a 2s . co m return builder.build(); }
From source file:org.ow2.chameleon.core.hook.HookManager.java
public synchronized Collection<Hook> addHook(Hook hook) { hooks = new ImmutableList.Builder<Hook>().addAll(hooks).add(hook).build(); return hooks; }
From source file:com.facebook.buck.apple.xcode.RuleDependencyFinder.java
/** * Retrieve all rules related to the given roots in the given graph. * * "Related" is defined as:/*from w w w . j a va 2 s . c o m*/ * - The rules themselves * - Their transitive dependencies * - The tests of the above rules * - Any additional dependencies of the tests */ public static ImmutableSet<BuildRule> getAllRules(PartialGraph graph, Iterable<BuildTarget> initialTargets) { ImmutableList.Builder<BuildRule> initialRulesBuilder = ImmutableList.builder(); for (BuildTarget target : initialTargets) { initialRulesBuilder.add(graph.getDependencyGraph().findBuildRuleByTarget(target)); } ImmutableSet<BuildRule> buildRules = gatherTransitiveDependencies(initialRulesBuilder.build()); ImmutableMultimap<BuildRule, BuildRule> ruleToTestRules = buildRuleToTestRulesMap(graph); // Extract the test rules for the initial rules and their dependencies. ImmutableSet.Builder<BuildRule> testRulesBuilder = ImmutableSet.builder(); for (BuildRule rule : buildRules) { testRulesBuilder.addAll(ruleToTestRules.get(rule)); } ImmutableSet<BuildRule> additionalBuildRules = gatherTransitiveDependencies(testRulesBuilder.build()); return ImmutableSet.<BuildRule>builder().addAll(buildRules).addAll(additionalBuildRules).build(); }
From source file:com.google.api.tools.framework.tools.configgen.ServiceConfigGeneratorTool.java
/** * Add all options that will be accepted on the command line. */// w ww . j a v a2 s .co m private static ImmutableList<Option<?>> buildFrameworkOptions() { ImmutableList.Builder<Option<?>> frameworkOptions = new ImmutableList.Builder<Option<?>>(); frameworkOptions.add(ToolOptions.DESCRIPTOR_SET); frameworkOptions.add(ToolOptions.CONFIG_FILES); frameworkOptions.add(ConfigGeneratorDriver.BIN_OUT); frameworkOptions.add(ConfigGeneratorDriver.TXT_OUT); frameworkOptions.add(ConfigGeneratorDriver.JSON_OUT); frameworkOptions.add(ConfigGeneratorFromProtoDescriptor.SUPPRESS_WARNINGS); frameworkOptions.add(SwaggerToolDriverBase.OPEN_API); frameworkOptions.add(SwaggerToolDriverBase.SERVICE_NAME); frameworkOptions.add(SwaggerToolDriverBase.TYPE_NAMESPACE); return frameworkOptions.build(); }
From source file:com.stackframe.sarariman.LDAPDirectory.java
private static Iterable<String> getAttributes(Attributes attributes, String attributeName) throws NamingException { Attribute attribute = attributes.get(attributeName); ImmutableList.Builder<String> b = ImmutableList.<String>builder(); if (attribute == null) { return null; } else {//from w w w . j av a 2 s . c o m NamingEnumeration<?> ne = attribute.getAll(); while (ne.hasMoreElements()) { b.add((String) ne.nextElement()); } return b.build(); } }