List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.codice.ddf.catalog.ui.security.ShareableMetacardSharingPolicyPlugin.java
private static Map<String, Set<String>> getShareablePermissions() { ImmutableMap.Builder<String, Set<String>> builder = new ImmutableMap.Builder<>(); Constants.SHAREABLE_TAGS.forEach(t -> builder.put(t, ImmutableSet.of(t))); return builder.build(); }
From source file:org.apache.joshua.decoder.ff.lm.ClassMap.java
/** * Reads a class map from file_name//from www. j a va 2s.c om */ private static ImmutableMap<Integer, Integer> read(String file_name) { final ImmutableMap.Builder<Integer, Integer> builder = ImmutableMap.builder(); int lineno = 0; try { for (String line : new LineReader(file_name, false)) { lineno++; String[] lineComp = line.trim().split("\\s+"); try { builder.put(Vocabulary.id(lineComp[0]), Vocabulary.id(lineComp[1])); } catch (java.lang.ArrayIndexOutOfBoundsException e) { LOG.warn("bad vocab line #{} '{}'. skipping!", lineno, line); LOG.warn(e.getMessage(), e); } } } catch (IOException e) { throw new RuntimeException(e); } return builder.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);//from www . ja v 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:com.icosilune.fn.nodes.FnNode.java
public FnNode(NodeGraph graph, AbstractFn fn) { super(graph); this.fn = fn; ImmutableMap.Builder<String, Socket> inputSockets = ImmutableMap.builder(); ImmutableMap.Builder<String, Socket> outputSockets = ImmutableMap.builder(); for (Map.Entry<String, FnType> inputEntry : fn.getInputTypes().entrySet()) { inputSockets.put(inputEntry.getKey(), Socket.create(inputEntry.getKey(), inputEntry.getValue(), Socket.SocketType.INPUT)); }/*w ww . j a va 2 s . c om*/ for (Map.Entry<String, FnType> outputEntry : fn.getOutputTypes().entrySet()) { outputSockets.put(outputEntry.getKey(), Socket.create(outputEntry.getKey(), outputEntry.getValue(), Socket.SocketType.OUTPUT)); } this.inputSockets = inputSockets.build(); this.outputSockets = outputSockets.build(); }
From source file:com.google.template.soy.shared.internal.InternalPlugins.java
public static ImmutableMap<String, SoyFunction> internalLegacyFunctionMap() { ImmutableMap.Builder<String, SoyFunction> builder = ImmutableMap.builder(); for (String builtinFunctionName : BuiltinFunction.names()) { builder.put(builtinFunctionName, BuiltinFunction.forFunctionName(builtinFunctionName)); }/*from w ww .j a va2 s. c o m*/ return builder.build(); }
From source file:ch.ethz.system.mt.tpch.DistributionLoader.java
private static Distribution loadDistribution(Iterator<String> lines, String name) { int count = -1; ImmutableMap.Builder<String, Integer> members = ImmutableMap.builder(); while (lines.hasNext()) { // advance to "begin" String line = lines.next(); if (isEnd(name, line)) { Map<String, Integer> weights = members.build(); checkState(count == weights.size(), "Expected %d entries in distribution %s, but only %d entries were found", count, weights.size());//w w w .j a va 2s . com return new Distribution(name, weights); } List<String> parts = ImmutableList .copyOf(Splitter.on('|').trimResults().omitEmptyStrings().split(line)); checkState(parts.size() == 2, "Expected line to contain two parts, but it contains %d parts: %s", parts.size(), line); String value = parts.get(0); int weight; try { weight = Integer.parseInt(parts.get(1)); } catch (NumberFormatException e) { throw new IllegalStateException( String.format("Invalid distribution %s: invalid weight on line %s", name, line)); } if (value.equalsIgnoreCase("count")) { count = weight; } else { members.put(value, weight); } } throw new IllegalStateException(String.format("Invalid distribution %s: no end statement", name)); }
From source file:org.pentaho.di.trans.dataservice.ui.AbstractModel.java
private static ImmutableMap<String, Object> buildSnapshot(Map<String, Object> snapshot) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (Map.Entry<String, Object> entry : snapshot.entrySet()) { Object value = entry.getValue(); if (value != null) { builder.put(entry);//from w w w. jav a 2s .c o m } } return builder.build(); }
From source file:org.gradle.caching.configuration.internal.BuildCacheServiceFactoryRegistry.java
private static Map<Class<? extends BuildCache>, BuildCacheServiceFactory<? extends BuildCache>> findFactories( DependencyInjectingServiceLoader serviceLoader, ClassLoader classLoader) { ImmutableMap.Builder<Class<? extends BuildCache>, BuildCacheServiceFactory<? extends BuildCache>> registryBuilder = ImmutableMap .builder();//from www . j a v a2 s . c o m Iterable<BuildCacheServiceFactory> serviceFactories = serviceLoader.load(BuildCacheServiceFactory.class, classLoader); for (BuildCacheServiceFactory<?> serviceFactory : serviceFactories) { Class<? extends BuildCache> configurationType = serviceFactory.getConfigurationType(); registryBuilder.put(configurationType, serviceFactory); LOGGER.info("Loaded {} implementation {}", BuildCacheServiceFactory.class.getSimpleName(), serviceFactory.getClass().getName()); } return registryBuilder.build(); }
From source file:com.google.devtools.build.lib.analysis.config.TransitiveOptionDetails.java
/** * Computes and returns the transitive optionName -> "option info" map for the given set of * options sets, using the given map as defaults for options which would otherwise be null. *//* w w w . ja v a 2s . co m*/ public static TransitiveOptionDetails forOptionsWithDefaults(Iterable<? extends OptionsBase> buildOptions, Map<String, Object> lateBoundDefaults) { ImmutableMap.Builder<String, OptionDetails> map = ImmutableMap.builder(); try { for (OptionsBase options : buildOptions) { for (Field field : options.getClass().getFields()) { if (field.isAnnotationPresent(Option.class)) { Option option = field.getAnnotation(Option.class); if (option.category().equals("internal")) { // ignore internal options continue; } Object value = field.get(options); if (value == null) { if (lateBoundDefaults.containsKey(option.name())) { value = lateBoundDefaults.get(option.name()); } else if (!option.defaultValue().equals("null")) { // See {@link Option#defaultValue} for an explanation of default "null" strings. value = option.defaultValue(); } } map.put(option.name(), new OptionDetails(options.getClass(), value, option.allowMultiple())); } } } } catch (IllegalAccessException e) { throw new IllegalStateException( "Unexpected illegal access trying to create this configuration's options map: ", e); } return new TransitiveOptionDetails(map.build()); }
From source file:ru.bozaro.protobuf.ServiceHolderImpl.java
public ServiceHolderImpl(@NotNull BlockingService... services) { final ImmutableMap.Builder<String, ServiceInfo> builder = ImmutableMap.<String, ServiceInfo>builder(); for (BlockingService service : services) { String name = service.getDescriptorForType().getName().toLowerCase(); ServiceInfo info = new ServiceInfo(new BlockingServiceWrapper(service)); builder.put(name, info);// www . j av a2 s . c o m } this.services = builder.build(); }