List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:com.google.api.codegen.util.StaticResourcesHandler.java
public Map<String, byte[]> getResources() throws IOException { ClassLoader cl = getClass().getClassLoader(); ImmutableMap.Builder<String, byte[]> resources = ImmutableMap.builder(); for (Map.Entry<String, String> entry : resourceFilesMap.entrySet()) { String resourcePath = SnippetSetRunner.SNIPPET_RESOURCE_ROOT + '/' + entry.getKey(); InputStream resourceStream = cl.getResourceAsStream(resourcePath); // Hack necessary to allow jar files to be included in the fat jar if (resourceStream == null && resourcePath.endsWith(".jar")) { resourcePath = resourcePath.replace(".jar", ".zjar"); resourceStream = cl.getResourceAsStream(resourcePath); }// w ww. j a va2 s . c om if (resourceStream == null) { throw new IllegalArgumentException("Static resource not found: '" + resourcePath + "'"); } byte[] resource = ByteStreams.toByteArray(resourceStream); resources.put(entry.getValue(), resource); } return resources.build(); }
From source file:org.gradle.internal.operations.trace.BuildOperationTree.java
private void visit(ImmutableMap.Builder<Long, BuildOperationRecord> records, BuildOperationRecord record) { records.put(record.id, record);/*from ww w .j ava2 s .c om*/ for (BuildOperationRecord child : record.children) { visit(records, child); } }
From source file:com.facebook.buck.cxx.ByteBufferReplacer.java
/** * Build a replacer using the given map of paths to replacement paths, using {@code charset} * to convert to underlying byte arrays. If the replacement paths are not long enough, use * the given path separator to fill.// w ww .j a v a 2s . c o m */ public static ByteBufferReplacer fromPaths(ImmutableMap<Path, Path> paths, char separator, Charset charset) { ImmutableMap.Builder<byte[], byte[]> replacements = ImmutableMap.builder(); for (Map.Entry<Path, Path> entry : paths.entrySet()) { String original = entry.getKey().toString(); String replacement = entry.getValue().toString(); // If the replacement string is too small, keep adding the path separator until it's long // enough. while (getBytes(original, charset).length > getBytes(replacement, charset).length) { replacement += separator; } // Depending on what was passed in, or the character encoding, we can end up with a // replacement string that is too long, which we can't recover from. Preconditions .checkArgument(getBytes(original, charset).length == getBytes(replacement, charset).length); replacements.put(getBytes(original, charset), getBytes(replacement, charset)); } return new ByteBufferReplacer(replacements.build()); }
From source file:org.chaston.oakfunds.bootstrap.BootstrapConfigReader.java
@Inject BootstrapConfigReader(Set<BootstrapConfigLoader> configLoaders) { ImmutableMap.Builder<String, BootstrapConfigLoader> configLoadersBuilder = ImmutableMap.builder(); for (BootstrapConfigLoader configLoader : configLoaders) { configLoadersBuilder.put(configLoader.getConfigElementName(), configLoader); }/*from w w w . j a va2 s . c om*/ this.configLoaders = configLoadersBuilder.build(); }
From source file:com.google.api.codegen.clientconfig.ClientConfigGapicContext.java
public Map<String, String> batchingParams(BatchingConfig batching) { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder(); if (batching.getElementCountThreshold() > 0) { builder.put("element_count_threshold", Integer.toString(batching.getElementCountThreshold())); }//from www .j a v a2 s. c o m if (batching.getElementCountLimit() > 0) { builder.put("element_count_limit", Integer.toString(batching.getElementCountLimit())); } if (batching.getRequestByteThreshold() > 0) { builder.put("request_byte_threshold", Long.toString(batching.getRequestByteThreshold())); } if (batching.getRequestByteLimit() > 0) { builder.put("request_byte_limit", Long.toString(batching.getRequestByteLimit())); } if (batching.getDelayThresholdMillis() > 0) { builder.put("delay_threshold_millis", Long.toString(batching.getDelayThresholdMillis())); } return builder.build(); }
From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.CaseEnforcer.java
static CaseEnforcer forTree(final ChoiceCaseNode schema, final DataTreeConfiguration treeConfig) { final TreeType type = treeConfig.getTreeType(); final Builder<NodeIdentifier, DataSchemaNode> childrenBuilder = ImmutableMap.builder(); final Builder<AugmentationIdentifier, AugmentationSchema> augmentationsBuilder = ImmutableMap.builder(); if (SchemaAwareApplyOperation.belongsToTree(type, schema)) { for (final DataSchemaNode child : schema.getChildNodes()) { if (SchemaAwareApplyOperation.belongsToTree(type, child)) { childrenBuilder.put(NodeIdentifier.create(child.getQName()), child); }/*from w w w .j a v a2 s.c om*/ } for (final AugmentationSchema augment : schema.getAvailableAugmentations()) { if (augment.getChildNodes().stream() .anyMatch(child -> SchemaAwareApplyOperation.belongsToTree(type, child))) { augmentationsBuilder.put(SchemaUtils.getNodeIdentifierForAugmentation(augment), augment); } } } final Map<NodeIdentifier, DataSchemaNode> children = childrenBuilder.build(); final Map<AugmentationIdentifier, AugmentationSchema> augmentations = augmentationsBuilder.build(); return children.isEmpty() ? null : new CaseEnforcer(children, augmentations, MandatoryLeafEnforcer.forContainer(schema, treeConfig)); }
From source file:ratpack.thymeleaf3.Template.java
public static Template thymeleafTemplate(String name, String contentType, Consumer<? super ImmutableMap.Builder<String, Object>> modelBuilder) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); modelBuilder.accept(builder);//from w ww .ja v a 2 s . c o m return thymeleafTemplate(builder.build(), name, contentType); }
From source file:com.ojuslabs.oct.lib.FunctionalGroups.java
/** * Builds the list of functional groups in the singleton instance. *///w ww . j av a2 s. c om void init() { ImmutableMap.Builder<Integer, FunctionalGroup> builder = ImmutableMap.builder(); /* TODO(js): fill functional group values. */ _groups = builder.build(); }
From source file:org.scassandra.http.client.AlreadyExistsConfig.java
@Override Map<String, ?> getProperties() { ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder(); mapBuilder.put(ErrorConstants.Keyspace(), keyspace); mapBuilder.put(ErrorConstants.Table(), table); if (message != null) { mapBuilder.put(ErrorConstants.Message(), message); }// w ww. ja v a 2 s .co m return mapBuilder.build(); }
From source file:org.scassandra.http.client.UnavailableConfig.java
@Override Map<String, ?> getProperties() { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder() .put(ErrorConstants.Alive(), String.valueOf(this.alive)) .put(ErrorConstants.RequiredResponse(), String.valueOf(this.requiredAcknowledgements)); if (consistencyLevel != null) { builder.put(ErrorConstants.ConsistencyLevel(), String.valueOf(consistencyLevel.toString())); }/*from w w w . j av a 2s .com*/ return builder.build(); }