List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:com.facebook.buck.cli.EnvironmentFilter.java
/** * Given a map (environment variable name: environment variable * value) pairs, returns a map without the variables which we should * not pass to child processes (buck.py, javac, etc.) * * Keeping the environment map clean helps us avoid jettisoning the * parser cache, as we have to rebuild it any time the environment * changes./*from www . ja va 2s .c om*/ */ public static ImmutableMap<String, String> filteredEnvironment(ImmutableMap<String, String> environment) { ImmutableMap.Builder<String, String> filteredEnvironmentBuilder = ImmutableMap.builder(); for (Map.Entry<String, String> envEntry : environment.entrySet()) { String key = envEntry.getKey(); if (!ENV_TO_REMOVE.contains(key)) { if (Platform.detect() == Platform.WINDOWS) { // Windows environment variables are case insensitive. While an ImmutableMap will throw // if we get duplicate key, we don't have to worry about this for Windows. filteredEnvironmentBuilder.put(key.toUpperCase(Locale.US), envEntry.getValue()); } else { filteredEnvironmentBuilder.put(envEntry); } } } return filteredEnvironmentBuilder.build(); }
From source file:com.google.security.zynamics.binnavi.disassembly.types.BaseTypeCategory.java
private static ImmutableMap<String, BaseTypeCategory> createLookup() { final ImmutableMap.Builder<String, BaseTypeCategory> builder = ImmutableMap.builder(); for (final BaseTypeCategory category : BaseTypeCategory.values()) { builder.put(category.value, category); }/*from w w w .j ava 2 s. com*/ return builder.build(); }
From source file:net.derquinse.common.meta.InterfaceMetaBuilderFactory.java
static <T extends WithMetaClass> InterfaceMetaBuilderFactory<T> of(MetaClass<T> metaClass) { Class<?> klass = metaClass.getType().getRawType(); // 1 - It must be an interface. if (!klass.isInterface()) { return null; }//from w w w . j a va2s . c o m // 2 - Method map builder ImmutableMap.Builder<String, MetaField<? super T, ?>> builder = ImmutableMap.builder(); // 3 - Method loop for (Method m : klass.getMethods()) { if (m.getParameterTypes().length != 0) { // Method with arguments -> not buildable. return null; } MetaField<? super T, ?> field = getField(m, metaClass.getFields()); if (field == null) { // The method is not a getter -> not buildable. return null; } builder.put(m.getName(), field); } return new InterfaceMetaBuilderFactory<T>(metaClass, builder.build()); }
From source file:org.apache.druid.server.http.ServersResource.java
private static Map<String, Object> makeSimpleServer(DruidServer input) { return new ImmutableMap.Builder<String, Object>().put("host", input.getHost()).put("tier", input.getTier()) .put("type", input.getType().toString()).put("priority", input.getPriority()) .put("currSize", input.getCurrSize()).put("maxSize", input.getMaxSize()).build(); }
From source file:io.swagger.codegen.options.ObjcClientOptionsProvider.java
@Override public Map<String, String> createOptions() { ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>(); return builder.put(ObjcClientCodegen.CLASS_PREFIX, CLASS_PREFIX_VALUE) .put(ObjcClientCodegen.POD_NAME, POD_NAME_VALUE) .put(CodegenConstants.POD_VERSION, POD_VERSION_VALUE) .put(ObjcClientCodegen.AUTHOR_NAME, AUTHOR_NAME_VALUE) .put(ObjcClientCodegen.AUTHOR_EMAIL, AUTHOR_EMAIL_VALUE) .put(ObjcClientCodegen.GIT_REPO_URL, GIT_REPO_URL_VALUE) .put(ObjcClientCodegen.LICENSE, LICENSE_VALUE).build(); }
From source file:com.b2international.snowowl.snomed.api.rest.SnomedMergingRestRequests.java
public static ValidatableResponse createMerge(IBranchPath source, IBranchPath target, String commitComment, String reviewId) {/*from w ww.j av a 2 s . co m*/ ImmutableMap.Builder<String, Object> requestBuilder = ImmutableMap.<String, Object>builder() .put("source", source.getPath()).put("target", target.getPath()) .put("commitComment", commitComment); if (null != reviewId) { requestBuilder.put("reviewId", reviewId); } return givenAuthenticatedRequest(SCT_API).contentType(ContentType.JSON).body(requestBuilder.build()) .post("/merges").then(); }
From source file:edu.buaa.satla.analysis.util.ImmutableMapMerger.java
/** * Join two maps taking the key into account, use {@code func} on duplicate values. * @param a input map/*from w w w. ja v a2s.c o m*/ * @param b input map * @param func function to merge two values from different maps. * @return map containing the union of keys in {@code a} and {@code b}, which * contains the value from {@code a} if it contains only in {@code a}, value * from {@code b} if it is contained only in {@code b} and {@code func} * applied on value from {@code a} and a value from {@code b} otherwise. */ public static <K, V> ImmutableMap<K, V> merge(ImmutableMap<K, V> a, ImmutableMap<K, V> b, MergeFunc<K, V> func) { Set<K> allKeys = new HashSet<>(); allKeys.addAll(a.keySet()); allKeys.addAll(b.keySet()); ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); for (K key : allKeys) { if (a.containsKey(key) && !b.containsKey(key)) { builder.put(key, a.get(key)); } else if (!a.containsKey(key) && b.containsKey(key)) { builder.put(key, b.get(key)); } else { builder.put(key, func.apply(key, a.get(key), b.get(key))); } } return builder.build(); }
From source file:com.google.gerrit.util.cli.OptionHandlers.java
private static ImmutableMap<Class<?>, Provider<OptionHandlerFactory<?>>> build(Injector i) { ImmutableMap.Builder<Class<?>, Provider<OptionHandlerFactory<?>>> map = ImmutableMap.builder(); for (; i != null; i = i.getParent()) { for (Entry<Key<?>, Binding<?>> e : i.getBindings().entrySet()) { TypeLiteral<?> type = e.getKey().getTypeLiteral(); if (type.getRawType() == OptionHandlerFactory.class && e.getKey().getAnnotation() == null && type.getType() instanceof ParameterizedType) { map.put(getType(type), cast(e.getValue()).getProvider()); }//from w w w . j a v a 2 s .com } } return map.build(); }
From source file:org.apache.gobblin.util.PropertiesUtils.java
/** * Converts a {@link Properties} object to a {@link Map} where each key is a {@link String}. *///from w w w.ja va 2 s . com public static Map<String, ?> propsToStringKeyMap(Properties properties) { ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.builder(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { mapBuilder.put(entry.getKey().toString(), entry.getValue()); } return mapBuilder.build(); }
From source file:org.apache.gobblin.util.ClusterNameTags.java
/** * Gets all useful Hadoop cluster metrics. * * @param conf a Hadoop {@link Configuration} to collect the metadata from * * @return a {@link Map} of key, value pairs containing the cluster metadata *///ww w. j av a2 s . c om public static Map<String, String> getClusterNameTags(Configuration conf) { ImmutableMap.Builder<String, String> tagMap = ImmutableMap.builder(); String clusterIdentifierTag = ClustersNames.getInstance().getClusterName(conf); if (!Strings.isNullOrEmpty(clusterIdentifierTag)) { tagMap.put(CLUSTER_IDENTIFIER_TAG_NAME, clusterIdentifierTag); } return tagMap.build(); }