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:net.minecrell.quartz.launch.util.ParsedAnnotation.java

public static ParsedAnnotation parse(AnnotationNode annotationNode) {
    Type type = Type.getType(annotationNode.desc);
    ImmutableMap<String, Object> values;

    if (annotationNode.values != null) {
        ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
        Iterator<Object> itr = annotationNode.values.iterator();
        do {/*  w w w.j  a  v a2s  . c  om*/
            builder.put((String) itr.next(), itr.next());
        } while (itr.hasNext());

        values = builder.build();
    } else {
        values = ImmutableMap.of();
    }

    return new ParsedAnnotation(type, values);
}

From source file:com.spotify.heroic.grammar.Expression.java

static Map<String, Expression> evalMap(Map<String, Expression> input, Scope scope) {
    final ImmutableMap.Builder<String, Expression> evaled = ImmutableMap.builder();

    for (final Map.Entry<String, Expression> e : input.entrySet()) {
        evaled.put(e.getKey(), e.getValue().eval(scope));
    }//  w  ww. j  av  a 2  s  . c  om

    return evaled.build();
}

From source file:org.plos.crepo.model.metadata.RepoMetadata.java

private static ImmutableMap<String, Object> defensiveCopy(Map<String, Object> raw) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    for (Map.Entry<String, Object> entry : raw.entrySet()) {
        builder.put(entry.getKey(), recursiveImmutableCopy(entry.getValue()));
    }/*from w w  w  . ja  va2 s .co m*/
    return builder.build();
}

From source file:io.prestosql.plugin.ml.StringClassifierAdapter.java

public static StringClassifierAdapter deserialize(byte[] data) {
    Slice slice = Slices.wrappedBuffer(data);
    BasicSliceInput input = slice.getInput();
    int classifierLength = input.readInt();

    Model classifier = ModelUtils.deserialize(input.readSlice(classifierLength));
    int numEnumerations = input.readInt();

    ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();

    for (int i = 0; i < numEnumerations; i++) {
        int key = input.readInt();
        int valueLength = input.readInt();
        String value = input.readSlice(valueLength).toStringUtf8();
        builder.put(key, value);
    }//w w w  . j av a 2 s.co  m

    return new StringClassifierAdapter((Classifier) classifier, builder.build());
}

From source file:com.facebook.presto.ml.StringClassifierAdapter.java

public static StringClassifierAdapter deserialize(byte[] data) {
    Slice slice = Slices.wrappedBuffer(data);
    BasicSliceInput input = slice.getInput();
    int classifierLength = input.readInt();

    Model classifier = ModelUtils.deserialize(input.readSlice(classifierLength));
    int numEnumerations = input.readInt();

    ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();

    for (int i = 0; i < numEnumerations; i++) {
        int key = input.readInt();
        int valueLength = input.readInt();
        String value = input.readSlice(valueLength).toStringUtf8();
        builder.put(key, value);
    }//from   w w  w  .  j  ava 2 s  .c  om

    return new StringClassifierAdapter(checkType(classifier, Classifier.class, "classifier"), builder.build());
}

From source file:com.facebook.buck.rules.KnownBuildRuleTypesTestUtil.java

protected static ImmutableMap<ProcessExecutorParams, FakeProcess> getPythonProcessMap(List<String> paths) {
    Set<String> uniquePaths = new HashSet<>(paths);
    ImmutableMap.Builder<ProcessExecutorParams, FakeProcess> processMap = ImmutableMap.builder();
    for (Map.Entry<String, String> python : PYTHONS.entrySet()) {
        for (String path : uniquePaths) {
            for (String extension : new String[] { "", ".exe", ".EXE" }) {
                processMap.put(
                        ProcessExecutorParams.builder()
                                .setCommand(ImmutableList
                                        .of(path + File.separator + python.getKey() + extension, "-"))
                                .build(),
                        new FakeProcess(0, "CPython " + python.getValue().replace('.', ' '), ""));
            }//from   ww  w . java  2  s . com
        }
    }
    return processMap.build();
}

From source file:org.eclipse.xtext.xbase.lib.CollectionLiterals.java

/**
 * Returns an immutable map containing the given entries. Repeated occurrences of a keys will cause an
 * {@link IllegalArgumentException}./*from ww  w. j a v a  2  s . c  o  m*/
 * 
 * @param entries
 *            the entries that should be contained in the map. May not be <code>null</code> and may
 *            not contain any <code>null</code> keys or values.
 * @return an immutable map containing the given entries.
 * @throws NullPointerException
 *             if {@code entries} or any key or value in {@code entries} is <code>null</code>
 * @throws IllegalArgumentException
 *             if duplicate keys are contained in {@code entries}.
 */
@Pure
public static <K, V> Map<K, V> newImmutableMap(Pair<? extends K, ? extends V>... entries) {
    if (entries.length == 0)
        return emptyMap();
    ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
    for (Pair<? extends K, ? extends V> entry : entries) {
        builder.put(entry.getKey(), entry.getValue());
    }
    return builder.build();
}

From source file:org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl.java

private static Map<String, String> createNamespaceToModuleName(Iterable<ModuleConfig> moduleConfigs) {
    final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (ModuleConfig moduleConfig : moduleConfigs) {
        if (moduleConfig.getNameSpace() != null) {
            builder.put(moduleConfig.getNameSpace(), moduleConfig.getName());
        }/*from   www.j a va 2 s .com*/
    }

    return builder.build();
}

From source file:com.facebook.buck.rules.DefaultKnownBuildRuleTypes.java

protected static ImmutableMap<ProcessExecutorParams, FakeProcess> getPythonProcessMap(List<String> paths) {
    Set<String> uniquePaths = new HashSet<>(paths);
    ImmutableMap.Builder<ProcessExecutorParams, FakeProcess> processMap = ImmutableMap.builder();
    for (Map.Entry<String, String> python : PYTHONS.entrySet()) {
        for (String path : uniquePaths) {
            for (String extension : new String[] { "", ".exe", ".EXE" }) {
                processMap.put(
                        ProcessExecutorParams.builder()
                                .setCommand(ImmutableList
                                        .of(path + File.separator + python.getKey() + extension, "-V"))
                                .build(),
                        new FakeProcess(0, "Python " + python.getValue(), ""));
            }// w  w w  .  ja  v  a  2s.c  o m
        }
    }
    return processMap.build();
}

From source file:dk.ilios.spanner.benchmark.ParameterSet.java

/**
 * Returns the set of all parameters and their possible values.
 * @param benchmarkClass    Benchmark class.
 * @param annotationClass   Annotation specifying a parameter.
 * @return//w  w  w  . ja v a2s.c  o  m
 * @throws InvalidBenchmarkException
 */
public static ParameterSet create(Class<?> benchmarkClass, Class<? extends Annotation> annotationClass)
        throws InvalidBenchmarkException {
    // deterministic order, not reflection order
    ImmutableMap.Builder<String, Parameter> parametersBuilder = ImmutableSortedMap.naturalOrder();

    for (Field field : benchmarkClass.getDeclaredFields()) {
        if (field.isAnnotationPresent(annotationClass)) {
            Parameter parameter = Parameter.create(field);
            parametersBuilder.put(field.getName(), parameter);
        }
    }
    return new ParameterSet(parametersBuilder.build());
}