List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:com.google.devtools.kythe.platform.shared.FileDataCache.java
public FileDataCache(Iterable<FileData> fileData) { ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder(); for (FileData data : fileData) { builder.put(data.getInfo().getDigest(), data.getContent().toByteArray()); }//from w ww.j a v a2 s. co m fileContents = builder.build(); }
From source file:com.google.template.soy.shared.internal.FunctionAdapters.java
/** * Given the set of all Soy function implementations and a specific Soy function type (subtype * of SoyFunction) to look for, finds the Soy functions that implement the specific type * and returns them in the form of a map from function name to function. * * @param <T> The specific Soy function type to look for. * @param soyFunctionsSet The set of all Soy functions. * @param specificSoyFunctionType The class of the specific Soy function type to look for. * @return A map of the relevant specific Soy functions (name to function). *///from w w w . ja va 2s .com public static <T extends SoyFunction> ImmutableMap<String, T> buildSpecificSoyFunctionsMap( Set<SoyFunction> soyFunctionsSet, Class<T> specificSoyFunctionType) { ImmutableMap.Builder<String, T> mapBuilder = ImmutableMap.builder(); Set<String> seenFnNames = Sets.newHashSetWithExpectedSize(soyFunctionsSet.size()); for (SoyFunction fn : soyFunctionsSet) { if (specificSoyFunctionType.isAssignableFrom(fn.getClass())) { String fnName = fn.getName(); if (seenFnNames.contains(fnName) || BuiltinFunction.forFunctionName(fnName) != null) { throw new IllegalStateException( "Found two implementations of " + specificSoyFunctionType.getSimpleName() + " with the same function name '" + fnName + "'."); } seenFnNames.add(fnName); mapBuilder.put(fnName, specificSoyFunctionType.cast(fn)); } } return mapBuilder.build(); }
From source file:org.apache.bigtop.datagenerators.samplers.markovmodels.MarkovModelBuilder.java
public MarkovModelBuilder() { transitionWeights = ImmutableTable.builder(); startWeights = ImmutableMap.builder(); }
From source file:org.opendaylight.yangtools.yang.data.impl.codec.EnumStringCodec.java
private EnumStringCodec(final Optional<EnumTypeDefinition> typeDef) { super(typeDef, String.class); if (typeDef.isPresent()) { final Builder<String, String> b = ImmutableMap.builder(); for (final EnumPair pair : typeDef.get().getValues()) { // Intern the String to get wide reuse final String v = pair.getName().intern(); b.put(v, v);/*from w w w .j a v a 2 s .c o m*/ } values = b.build(); } else { values = null; } }
From source file:com.helion3.safeguard.commands.ZoneCommands.java
/** * Build a complete command hierarchy// w w w . ja v a 2s. c o m * @return */ public static CommandSpec getCommand() { // Build child commands ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder(); builder.put(ImmutableList.of("create", "c"), new ZoneCreateCommand()); builder.put(ImmutableList.of("allow", "a"), new ZoneAllowCommand()); builder.put(ImmutableList.of("deny", "d"), new ZoneDenyCommand()); builder.put(ImmutableList.of("delete"), ZoneDeleteCommand.getCommand()); builder.put(ImmutableList.of("flag", "f"), ZoneFlagCommand.getCommand()); return CommandSpec.builder().executor((source, args) -> { if (!(source instanceof Player)) { source.sendMessage(Format.error("Command usable only by a player.")); return CommandResult.empty(); } Player player = (Player) source; List<Zone> zones = SafeGuard.getZoneManager().getZones(player.getLocation()); if (zones.isEmpty()) { source.sendMessage(Format.error("No zone found for your position.")); return CommandResult.empty(); } for (Zone zone : zones) { source.sendMessage(Format.heading("Zone " + zone.getName())); // Owners source.sendMessage(Format.subdued("Owners:")); for (GameProfile profile : zone.getOwners()) { source.sendMessage(Format.message(profile.getName())); } // Volume source.sendMessage(Format.subdued("Volume:")); source.sendMessage(Format.message( zone.getVolume().getMin().toString() + ", " + zone.getVolume().getMax().toString())); source.sendMessage(Format.message("Blocks: " + zone.getVolume().getVolume())); // Flags source.sendMessage(Format.subdued("Flags:")); for (Map.Entry<String, Boolean> entry : zone.getPermissions().getPermissions().entrySet()) { source.sendMessage(Format.message(entry.getKey(), TextColors.YELLOW, entry.getValue())); } } return CommandResult.empty(); }).children(builder.build()).build(); }
From source file:org.scassandra.http.client.UnpreparedConfig.java
@Override Map<String, ?> getProperties() { ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); mapBuilder.put(ErrorConstants.PrepareId(), prepareId); if (message != null) { mapBuilder.put(ErrorConstants.Message(), message); }/*from www . j a v a2 s .c o m*/ return mapBuilder.build(); }
From source file:com.jgaap.backend.Languages.java
private static Map<String, Language> loadLanguagesMap() { // Load the classifiers dynamically ImmutableMap.Builder<String, Language> builder = ImmutableMap.builder(); for (Language language : LANGUAGES) { builder.put(language.displayName().toLowerCase().trim(), language); }/* ww w. j a v a 2 s . co m*/ return builder.build(); }
From source file:org.opendaylight.infrautils.caches.CheckedCacheFunction.java
/** * See {@link CacheFunction#get(Iterable)}. *///from ww w. j av a 2s. c o m default ImmutableMap<K, V> get(Iterable<? extends K> keys) throws E { Builder<K, V> mapBuilder = ImmutableMap.builder(); for (K key : keys) { mapBuilder.put(key, get(key)); } return mapBuilder.build(); }
From source file:org.onos.yangtools.yang.data.util.ChoiceNodeContextNode.java
protected ChoiceNodeContextNode(final ChoiceSchemaNode schema) { super(new NodeIdentifier(schema.getQName()), schema); ImmutableMap.Builder<QName, DataSchemaContextNode<?>> byQNameBuilder = ImmutableMap.builder(); ImmutableMap.Builder<PathArgument, DataSchemaContextNode<?>> byArgBuilder = ImmutableMap.builder(); for (ChoiceCaseNode caze : schema.getCases()) { for (DataSchemaNode cazeChild : caze.getChildNodes()) { DataSchemaContextNode<?> childOp = fromDataSchemaNode(cazeChild); byArgBuilder.put(childOp.getIdentifier(), childOp); for (QName qname : childOp.getQNameIdentifiers()) { byQNameBuilder.put(qname, childOp); }//from w w w .j a v a 2 s.co m } } byQName = byQNameBuilder.build(); byArg = byArgBuilder.build(); }
From source file:com.ccreanga.bitbucket.rest.client.http.responseparsers.BuildStatsParser.java
@Override public Map<String, BuildStatsSummary> apply(JsonElement jsonElement) { JsonObject json = jsonElement.getAsJsonObject(); ImmutableMap.Builder<String, BuildStatsSummary> builder = ImmutableMap.builder(); for (Map.Entry<String, JsonElement> commitEntries : json.entrySet()) { BuildStatsSummary.Builder element = BuildStatsSummary.builder(); for (Map.Entry<String, JsonElement> e : commitEntries.getValue().getAsJsonObject().entrySet()) { if ("failed".equals(e.getKey())) { element.setFailed(e.getValue().getAsLong()); } else if ("inProgress".equals(e.getKey())) { element.setInProgress(e.getValue().getAsLong()); } else if ("successful".equals(e.getKey())) { element.setSuccessful(e.getValue().getAsLong()); }//from www . ja v a 2s . c o m } builder.put(commitEntries.getKey(), element.build()); } return builder.build(); }