List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:org.chaston.oakfunds.security.PermissionRegistry.java
@Inject PermissionRegistry(Set<Permission> permissions) { ImmutableMap.Builder<String, Permission> permissionsBuilder = ImmutableMap.builder(); for (Permission permission : permissions) { permissionsBuilder.put(permission.getName(), permission); }//w w w .j a v a 2 s . c om this.permissions = permissionsBuilder.build(); }
From source file:harp.script.node.NodeContext.java
NodeContext(List<NodeSpec> nodes) { ImmutableMap.Builder<String, NodeSpec> builder = ImmutableMap.builder(); for (NodeSpec node : nodes) { builder.put(node.getName(), node); }/*from ww w . j a v a2 s .co m*/ this.namesToNodes = builder.build(); }
From source file:ratpack.thymeleaf3.Template.java
public static Template thymeleafTemplate(String name, Consumer<? super ImmutableMap.Builder<String, Object>> modelBuilder) { return thymeleafTemplate(name, null, modelBuilder); }
From source file:com.isotrol.impe3.core.impl.ContentTypesFactory.java
/** * Returns a collection of cookies containing the provided content types. * @param types Content types to add to the collection. * @return The requested collection.//ww w . j av a 2 s.c o m * @throws NullPointerException if the argument is null. * @throws IllegalArgumentException if there are more than one content type with the same id. */ public static ContentTypes of(Iterable<ContentType> types) { Preconditions.checkNotNull(types); final ImmutableMap.Builder<UUID, ContentType> builder = ImmutableMap.builder(); for (final ContentType type : types) { builder.put(type.getId(), type); } return new Immutable(builder.build()); }
From source file:harp.script.root.RootContext.java
RootContext(List<Environment> environments) { ImmutableMap.Builder<String, Environment> builder = ImmutableMap.builder(); // TODO: Consider throwing a Harp-specific Exception for duplicate names. For now, guard against // this via ImmutableMap.Builder's checks for duplicate keys. for (Environment env : environments) { builder.put(env.getName(), env); }/* ww w . j a va 2s. co m*/ this.nameToEnvironment = builder.build(); }
From source file:com.google.devtools.build.lib.skylarkbuildapi.cpp.CcBootstrap.java
@Override public void addBindingsToBuilder(ImmutableMap.Builder<String, Object> builder) { builder.put("cc_common", ccModule); }
From source file:com.foudroyantfactotum.tool.structure.utility.PartBlockState.java
public static PartBlockState of(IBlockState b, String s) { final Collection<IProperty<?>> defaultProp = b.getPropertyKeys(); final ImmutableMap.Builder<IProperty, Comparable> builderDef = ImmutableMap.builder(); final Set<IProperty> properties = new HashSet<>(defaultProp); for (final String singleFullState : s.split(",")) { if (!singleFullState.contains(":")) { throw new StructureDefinitionBuilder.StructureDefinitionError("Missing property divider"); }// w w w .j a v a 2s. c o m final String propName = singleFullState.split(":")[0]; final String propVal = singleFullState.split(":")[1]; boolean hasFoundProp = false; for (final IProperty prop : defaultProp) { if (prop.getName().equalsIgnoreCase(propName)) { boolean hasFoundVal = false; for (final Comparable val : (Collection<Comparable>) prop.getAllowedValues()) { if (val.toString().equalsIgnoreCase(propVal)) { builderDef.put(prop, val); properties.remove(prop); hasFoundVal = true; break; } } if (!hasFoundVal) { throw new StructureDefinitionBuilder.StructureDefinitionError("Property value missing: '" + prop.getName() + "' value missing: '" + propVal + "' in '" + prop.getAllowedValues() + "' on '" + b.getBlock().getUnlocalizedName() + "' with property: '" + b.getPropertyKeys()); } hasFoundProp = true; break; } } if (!hasFoundProp) { throw new StructureDefinitionBuilder.StructureDefinitionError( "Missing property: '" + propName + "' value: '" + propVal + "' on block: '" + b.getBlock().getUnlocalizedName() + "' with property: '" + b.getPropertyKeys()); } } final ImmutableMap<IProperty, Comparable> definitive = builderDef.build(); for (Map.Entry<IProperty, Comparable> entry : definitive.entrySet()) { b = b.withProperty(entry.getKey(), entry.getValue()); } return new PartBlockState(builderDef.build(), ImmutableList.copyOf(properties), b); }
From source file:com.google.devtools.build.lib.query2.engine.VariableContext.java
/** * Returns a {@link VariableContext} that has all the same bindings as the given * {@code variableContext} and also the binding of {@code name} to {@code value}. *//*from w w w . j av a 2s . c o m*/ static <T> VariableContext<T> with(VariableContext<T> variableContext, String name, Set<T> value) { ImmutableMap.Builder<String, Set<T>> newContextBuilder = ImmutableMap.builder(); for (Map.Entry<String, Set<T>> entry : variableContext.context.entrySet()) { if (!entry.getKey().equals(name)) { // The binding of 'name' to 'value' should override any existing binding of name in // 'variableContext'. These are the semantics we want in order for nested let-expressions // to have the semantics we want. newContextBuilder.put(entry); } } newContextBuilder.put(name, value); return new VariableContext<>(newContextBuilder.build()); }
From source file:com.netflix.atlas.client.util.NetflixTagKey.java
private static void put(ImmutableMap.Builder<String, String> builder, String k, String v) { if (v != null && v.length() > 0) { builder.put(k, v);/*ww w . j a v a 2s. c o m*/ } }
From source file:com.lambdautils.util.stream.MoreCollectors.java
public static <T, K, V> Collector<T, ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> toImmutableMap( final Function<? super T, ? extends K> keyMapper, final Function<? super T, ? extends V> valueMapper) { return Collector.of(ImmutableMap.Builder::new, (b, t) -> b.put(keyMapper.apply(t), valueMapper.apply(t)), (l, r) -> l.putAll(r.build()), ImmutableMap.Builder::build); }