Example usage for com.google.common.collect ImmutableMap.Builder put

List of usage examples for com.google.common.collect ImmutableMap.Builder put

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap.Builder put.

Prototype

public final V put(K k, V v) 

Source Link

Usage

From source file:com.facebook.buck.rules.macros.MacroHandler.java

private static ImmutableMap<String, MacroExpander> addOutputToFileExpanders(
        ImmutableMap<String, MacroExpander> source) {
    ImmutableMap.Builder<String, MacroExpander> builder = ImmutableMap.builder();
    for (Map.Entry<String, MacroExpander> entry : source.entrySet()) {
        builder.put(entry.getKey(), entry.getValue());
        builder.put("@" + entry.getKey(), new OutputToFileExpander(entry.getValue()));
    }/*from w w w . ja v  a 2  s.c  o  m*/
    return builder.build();
}

From source file:edu.cmu.lti.oaqa.baseqa.learning_base.Scorer.java

static Map<String, Double> generateSummaryFeatures(double[] ratios, String keyword, String... operators) {
    ImmutableMap.Builder<String, Double> feat2value = ImmutableMap.builder();
    Set<String> operatorSet = ImmutableSet.copyOf(operators);
    if (operatorSet.contains("avg")) {
        feat2value.put(keyword + "-avg", DoubleStream.of(ratios).average().orElse(0));
    }// ww  w .  j ava  2 s.c  o m
    if (operatorSet.contains("max")) {
        feat2value.put(keyword + "-max", DoubleStream.of(ratios).max().orElse(0));
    }
    if (operatorSet.contains("min")) {
        feat2value.put(keyword + "-min", DoubleStream.of(ratios).min().orElse(0));
    }
    if (operatorSet.contains("pos-ratio")) {
        feat2value.put(keyword + "-pos-ratio",
                DoubleStream.of(ratios).mapToInt(r -> r == 0.0 ? 0 : 1).average().orElse(0));
    }
    if (operatorSet.contains("one-ratio")) {
        feat2value.put(keyword + "-one-ratio",
                DoubleStream.of(ratios).mapToInt(r -> r == 1.0 ? 1 : 0).average().orElse(0));
    }
    if (operatorSet.contains("any-one")) {
        feat2value.put(keyword + "-any-one", DoubleStream.of(ratios).anyMatch(r -> r == 1.0) ? 1.0 : 0.0);
    }
    return feat2value.build();
}

From source file:org.apache.cassandra.db.lifecycle.Helpers.java

/**
 * @return the identity function, as a Map, with domain of the provided values
 *//*from  w  ww . jav  a 2  s  .c  o m*/
static <T> Map<T, T> identityMap(Iterable<T> values) {
    ImmutableMap.Builder<T, T> builder = ImmutableMap.<T, T>builder();
    for (T t : values)
        builder.put(t, t);
    return builder.build();
}

From source file:com.google.api.codegen.transformer.RetryDefinitionsTransformer.java

public static ImmutableMap<String, RetryParamsDefinitionProto> createRetrySettingsDefinition(
        InterfaceConfigProto interfaceConfigProto) {
    ImmutableMap.Builder<String, RetryParamsDefinitionProto> builder = ImmutableMap.builder();
    for (RetryParamsDefinitionProto retryDef : interfaceConfigProto.getRetryParamsDefList()) {
        builder.put(retryDef.getName(), retryDef);
    }//  w ww .  java 2  s .c  om
    return builder.build();
}

From source file:com.isotrol.impe3.freemarker.wrap.PortalAPIMethodMap.java

private static <T> PortalAPIMethodMap<T> build(PortalAPIMethod<? super T>[]... values) {
    ImmutableMap.Builder<String, PortalAPIMethod<? super T>> builder = ImmutableMap.builder();
    for (PortalAPIMethod<? super T>[] methods : values) {
        for (PortalAPIMethod<? super T> method : methods) {
            builder.put(method.getName(), method);
        }/*www.j  av  a 2s . co m*/
    }
    return new PortalAPIMethodMap<T>(builder.build());
}

From source file:org.apache.drill.common.scanner.persistence.AnnotationDescriptor.java

static Map<String, AnnotationDescriptor> buildAnnotationsMap(List<AnnotationDescriptor> annotations) {
    ImmutableMap.Builder<String, AnnotationDescriptor> annMapBuilder = ImmutableMap.builder();
    for (AnnotationDescriptor ann : annotations) {
        annMapBuilder.put(ann.getAnnotationType(), ann);
    }/*from  w w w  .  j  a  va2s  . c  o  m*/
    return annMapBuilder.build();
}

From source file:com.noorq.casser.mapping.javatype.MappingJavaTypes.java

private static void add(ImmutableMap.Builder<Class<?>, AbstractJavaType> builder, AbstractJavaType jt) {

    builder.put(jt.getJavaClass(), jt);

    Optional<Class<?>> primitiveJavaClass = jt.getPrimitiveJavaClass();
    if (primitiveJavaClass.isPresent()) {
        builder.put(primitiveJavaClass.get(), jt);
    }//from  w  ww .  j  a v a  2 s  .co  m

}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.AppEngineLibraries.java

private static ImmutableMap<String, Library> loadLibraryDefinitions() {
    IConfigurationElement[] elements = RegistryFactory.getRegistry()
            .getConfigurationElementsFor("com.google.cloud.tools.eclipse.appengine.libraries");
    LibraryFactory factory = new LibraryFactory();
    ImmutableMap.Builder<String, Library> builder = ImmutableMap.builder();
    for (IConfigurationElement element : elements) {
        try {/*from  ww  w  .  j  a  va 2  s.co  m*/
            Library library = factory.create(element);
            builder.put(library.getId(), library);
        } catch (LibraryFactoryException ex) {
            logger.log(Level.SEVERE, "Error loading library definition", ex);
        }
    }
    return builder.build();
}

From source file:org.mule.module.extension.internal.util.MuleExtensionUtils.java

/**
 * Returns a {@link Map} in which the keys are the {@link Described#getName() names} of the items
 * in the {@code objects} {@link List}, and the values are the items themselves.
 *
 * @param objects a {@link List} with items that implement the {@link Described} interface
 * @param <T>     the generic type of the items in {@code objects}
 * @return a {@link Map} in which the keys are the item's names and the values are the items
 *//*ww w .  jav  a 2s  .c o m*/
public static <T extends Described> Map<String, T> toMap(List<T> objects) {
    ImmutableMap.Builder<String, T> map = ImmutableMap.builder();
    for (T object : objects) {
        map.put(object.getName(), object);
    }

    return map.build();
}

From source file:google.registry.model.domain.launch.LaunchPhase.java

/**
 * Returns a map of the static final fields to their values, case-converted.
 *//*  ww  w.  j a v a 2  s .  c  om*/
private static final ImmutableMap<String, LaunchPhase> initEnumMapping() {
    ImmutableMap.Builder<String, LaunchPhase> builder = new ImmutableMap.Builder<>();
    for (Entry<String, LaunchPhase> entry : getTypesafeEnumMapping(LaunchPhase.class).entrySet()) {
        builder.put(UPPER_UNDERSCORE.to(LOWER_CAMEL, entry.getKey()), entry.getValue());
    }
    return builder.build();
}