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.sun.tools.hat.internal.lang.jruby12.JRubyObject.java

private static void getPropertiesFromPackedFields(JavaObject packedVFields,
        ImmutableMap.Builder<String, JavaThing> builder) {
    for (int i = 1;; ++i) {
        String name = Models.getFieldString(packedVFields, "name" + i);
        if (name == null) {
            return;
        }// w  w  w . ja v a 2 s  .  c  om
        builder.put(name, packedVFields.getField("value" + i));
    }
}

From source file:com.facebook.buck.rules.args.Arg.java

public static <K> ImmutableMap<K, String> stringify(ImmutableMap<K, Arg> argMap) {
    ImmutableMap.Builder<K, String> stringMap = ImmutableMap.builder();
    for (Map.Entry<K, Arg> ent : argMap.entrySet()) {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        ent.getValue().appendToCommandLine(builder);
        stringMap.put(ent.getKey(), Joiner.on(" ").join(builder.build()));
    }/*from w ww  .j av a  2s. c o m*/
    return stringMap.build();
}

From source file:com.facebook.buck.config.Inis.java

public static ImmutableMap<String, ImmutableMap<String, String>> read(Reader reader) throws IOException {
    Ini ini = new Ini();
    Config config = ini.getConfig();/* w ww . j av a2  s. c o  m*/
    config.setEscape(false);
    config.setEscapeNewline(true);
    ini.load(reader);
    validateIni(ini);

    ImmutableMap.Builder<String, ImmutableMap<String, String>> sectionsToEntries = ImmutableMap.builder();
    for (String sectionName : ini.keySet()) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        Profile.Section section = ini.get(sectionName);
        for (String propertyName : section.keySet()) {
            String propertyValue = section.get(propertyName);
            builder.put(propertyName, propertyValue);
        }

        ImmutableMap<String, String> sectionToEntries = builder.build();
        sectionsToEntries.put(sectionName, sectionToEntries);
    }

    return sectionsToEntries.build();

}

From source file:org.ambraproject.wombat.freemarker.TemplateModelUtil.java

static ImmutableMap<String, TemplateModel> getAsMap(TemplateModel value) throws TemplateModelException {
    if (value == null)
        return ImmutableMap.of();
    if (value instanceof TemplateHashModelEx) {
        TemplateHashModelEx ftlHash = (TemplateHashModelEx) value;
        ImmutableMap.Builder<String, TemplateModel> builder = ImmutableMap.builder();
        for (TemplateModelIterator iterator = ftlHash.keys().iterator(); iterator.hasNext();) {
            String key = iterator.next().toString();
            builder.put(key, ftlHash.get(key));
        }/*from   w w w  . jav a2  s  . c om*/
        return builder.build();
    }
    throw new TemplateModelException("Hash type expected");
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.Conversions.java

static void registerInsns(ImmutableMap.Builder<String, BytecodeSequence> m, Class from, Class to, int opcode,
        int... opcodes) {
    m.put(key(from, to), new InstructionsCall(opcode, opcodes));
}

From source file:com.kolich.aws.services.s3.impl.KolichS3Signer.java

/**
 * Given an HttpRequestBase, extracts a Map containing each header to
 * value pair.  The returned Map is unmodifiable.
 *///from   ww w.  j a  v  a 2 s. c  o  m
private static final ImmutableMap<String, String> getHeadersAsMap(final AwsHttpRequest request) {
    final ImmutableMap.Builder<String, String> map = ImmutableMap.builder();
    for (final Header h : request.getRequestBase().getAllHeaders()) {
        map.put(h.getName(), h.getValue());
    }
    return map.build();
}

From source file:ro.cosu.vampires.client.monitoring.MetricsWindow.java

public static ImmutableMap<String, String> convertGaugesToString(SortedMap<String, Gauge> gauges) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

    gauges.entrySet().stream().forEach(entry -> {
        String gaugeName = entry.getKey();
        String gaugeValue = entry.getValue().getValue().toString();
        builder.put(gaugeName.replace(".", "-"), gaugeValue);

    });/*from   w ww.  j  a va  2 s .  c om*/

    return builder.build();
}

From source file:com.google.template.soy.jbcsrc.BytecodeCompiler.java

/**
 * Compiles all the templates in the given registry.
 *
 * @return CompiledTemplates or {@code absent()} if compilation fails, in which case errors will
 *     have been reported to the error reporter.
 *///from   w w  w .ja va  2s  .c  o m
public static Optional<CompiledTemplates> compile(TemplateRegistry registry, ErrorReporter reporter) {
    ErrorReporter.Checkpoint checkpoint = reporter.checkpoint();
    checkForUnsupportedFeatures(registry, reporter);
    if (reporter.errorsSince(checkpoint)) {
        return Optional.absent();
    }
    CompiledTemplateRegistry compilerRegistry = new CompiledTemplateRegistry(registry);

    // TODO(lukes): currently we compile all the classes, but you could easily imagine being
    // configured in such a way that we load the classes from the system class loader.  Then we
    // could add a build phase that writes the compiled templates out to a jar.  Then in the non
    // development mode case we could skip even parsing templates!
    MemoryClassLoader loader = compileTemplates(registry, compilerRegistry, reporter);
    if (reporter.errorsSince(checkpoint)) {
        return Optional.absent();
    }
    ImmutableMap.Builder<String, CompiledTemplate.Factory> factories = ImmutableMap.builder();
    for (TemplateNode node : registry.getAllTemplates()) {
        String name = node.getTemplateName();
        factories.put(name, loadFactory(compilerRegistry.getTemplateInfo(name), loader));
    }
    return Optional.of(new CompiledTemplates(factories.build()));
}

From source file:com.cloudera.gertrude.server.HttpServletExperimentStateImpl.java

private static Map<Integer, String> indexDiversionCookies(List<String> diversionCookies, Cookie[] cookies) {
    ImmutableMap.Builder<Integer, String> b = ImmutableMap.builder();
    for (int i = 0; i < diversionCookies.size(); i++) {
        String cookieName = diversionCookies.get(i);
        for (Cookie c : cookies) {
            if (cookieName.equals(c.getName())) {
                b.put(i, c.getValue());
                break;
            }//from w  ww  .j a va 2 s.  c  om
        }
    }
    return b.build();
}

From source file:com.google.caliper.util.Util.java

public static <T> ImmutableMap<String, T> prefixedSubmap(Map<String, T> props, String prefix) {
    ImmutableMap.Builder<String, T> submapBuilder = ImmutableMap.builder();
    for (Map.Entry<String, T> entry : props.entrySet()) {
        String name = entry.getKey();
        if (name.startsWith(prefix)) {
            submapBuilder.put(name.substring(prefix.length()), entry.getValue());
        }//from ww w  .  j  av a  2 s  .  c o  m
    }
    return submapBuilder.build();
}