Example usage for com.google.common.collect ImmutableMap builder

List of usage examples for com.google.common.collect ImmutableMap builder

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Usage

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

public static ImmutableMap<String, Object> serialize(CellPathResolver resolver) {
    Preconditions.checkArgument(resolver instanceof DefaultCellPathResolver,
            "Unsupported CellPathResolver class: %s", resolver.getClass());

    DefaultCellPathResolver defaultResolver = (DefaultCellPathResolver) resolver;

    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    builder.put(TYPE, TYPE_DEFAULT);/*from w w w.  j  av  a 2 s  .c o  m*/
    builder.put(ROOT_PATH, defaultResolver.getRoot().toString());

    ImmutableMap.Builder<String, String> cellPathAsStrings = ImmutableMap.builder();
    for (Map.Entry<String, Path> entry : defaultResolver.getCellPaths().entrySet()) {
        cellPathAsStrings.put(entry.getKey(), entry.getValue().toString());
    }
    builder.put(CELL_PATHS, cellPathAsStrings.build());
    return builder.build();
}

From source file:com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition.java

public static RuleDefinition fromProto(Build.RuleDefinition rule) {
    boolean hasNameAttr = false;
    ImmutableMap.Builder<String, AttributeDefinition> map = ImmutableMap.builder();
    for (Build.AttributeDefinition attr : rule.getAttributeList()) {
        map.put(attr.getName(), AttributeDefinition.fromProto(attr));
        hasNameAttr |= "name".equals(attr.getName());
    }/*from ww w.j  av a2 s.c o m*/
    if (!hasNameAttr) {
        map.put(NAME_ATTRIBUTE.name, NAME_ATTRIBUTE);
    }
    return new RuleDefinition(rule.getName(), map.build(),
            rule.hasDocumentation() ? rule.getDocumentation() : null);
}

From source file:io.soliton.protobuf.plugin.TypeMap.java

public static TypeMap of(FileDescriptorProto protoFile) {
    ImmutableMap.Builder<String, JavaType> types = ImmutableMap.builder();
    FileOptions options = protoFile.getOptions();

    String protoPackage = "." + (protoFile.hasPackage() ? protoFile.getPackage() : "");
    String javaPackage = options.hasJavaPackage() ? options.getJavaPackage()
            : protoFile.hasPackage() ? protoFile.getPackage() : null;
    String enclosingClass = options.getJavaMultipleFiles() ? null
            : options.hasJavaOuterClassname() ? options.getJavaOuterClassname()
                    : createOuterJavaClassname(protoFile.getName());

    for (DescriptorProto message : protoFile.getMessageTypeList()) {
        types.put(protoPackage + "." + message.getName(),
                new JavaType(javaPackage, enclosingClass, message.getName()));
    }/*from  w  w w . jav a  2 s. c  om*/

    return new TypeMap(types.build());
}

From source file:graph.features.degree.Degree.java

private static <T> Map<T, Integer> computeData(final UndirectedGraph<T> graph) {
    final Builder<T, Integer> builder = new ImmutableMap.Builder<T, Integer>();
    for (final T node : graph)
        builder.put(node, graph.getConnectedEndPoints(node).size());
    return builder.build();
}

From source file:com.spotify.styx.state.TimeoutConfig.java

public static TimeoutConfig createFromConfig(Config ttlSubConfig) {
    final Duration defaultTtl = Duration.parse(ttlSubConfig.getString(DEFAULT_TTL_KEY));

    final ImmutableMap.Builder<RunState.State, Duration> map = ImmutableMap.builder();
    for (RunState.State state : RunState.State.values()) {
        final String key = state.name().toLowerCase();
        if (ttlSubConfig.hasPath(key)) {
            final Duration ttl = Duration.parse(ttlSubConfig.getString(key));
            map.put(state, ttl);/*from  ww  w . j  a  v a  2  s.c o  m*/
        }
    }

    return new TimeoutConfig(map.build(), defaultTtl);
}

From source file:com.facebook.buck.apple.xcode.xcspec.SDKSettings.java

/**
 * Parses the contents of the provided SDKSettings.plist input stream
 * and extracts the dictionary of DefaultProperties values.
 *///from  w w  w.j  a va  2  s  .c om
public static void parseDefaultPropertiesFromPlist(InputStream sdkSettingsPlist,
        ImmutableMap.Builder<String, String> defaultPropertiesBuilder) throws Exception {
    NSObject sdkSettings = PropertyListParser.parse(sdkSettingsPlist);
    if (!(sdkSettings instanceof NSDictionary)) {
        throw new RuntimeException(
                "Unexpected SDKSettings.plist contents (expected NSDictionary, got " + sdkSettings + ")");
    }
    getDefaultPropertiesFromNSDictionary((NSDictionary) sdkSettings, defaultPropertiesBuilder);
}

From source file:com.tozny.mobiledemo.UserDAO.java

public void insertUser(User user) {
    userMap = new ImmutableMap.Builder<String, User>().putAll(userMap).put(user.getEmail(), user).build();
}

From source file:google.registry.tmch.SmdrlCsvParser.java

/** Converts the lines from the DNL CSV file into a data structure. */
public static SignedMarkRevocationList parse(List<String> lines) {
    ImmutableMap.Builder<String, DateTime> revokes = new ImmutableMap.Builder<>();

    // First line: <version>,<SMD Revocation List creation datetime>
    List<String> firstLine = Splitter.on(',').splitToList(lines.get(0));
    checkArgument(firstLine.size() == 2,
            String.format("Line 1: Expected 2 elements, found %d", firstLine.size()));
    Integer version = Integer.valueOf(firstLine.get(0));
    checkArgument(version == 1, String.format("Line 1: Expected version 1, found %d", version));
    DateTime creationTime = DateTime.parse(firstLine.get(1)).withZone(UTC);

    // Second line contains headers: smd-id,insertion-datetime
    List<String> secondLine = Splitter.on(',').splitToList(lines.get(1));
    checkArgument(secondLine.size() == 2,
            String.format("Line 2: Expected 2 elements, found %d", secondLine.size()));
    checkArgument("smd-id".equals(secondLine.get(0)),
            String.format("Line 2: Expected header \"smd-id\", found \"%s\"", secondLine.get(0)));
    checkArgument("insertion-datetime".equals(secondLine.get(1)),
            String.format("Line 2: Expected header \"insertion-datetime\", found \"%s\"", secondLine.get(1)));

    // Subsequent lines: <smd-id>,<revoked SMD datetime>
    for (int i = 2; i < lines.size(); i++) {
        List<String> currentLine = Splitter.on(',').splitToList(lines.get(i));
        checkArgument(currentLine.size() == 2,
                String.format("Line %d: Expected 2 elements, found %d", i + 1, currentLine.size()));
        String smdId = currentLine.get(0);
        DateTime revokedTime = DateTime.parse(currentLine.get(1));
        revokes.put(smdId, revokedTime);
    }/*from  www  .  ja v  a  2 s.c  o  m*/

    return SignedMarkRevocationList.create(creationTime, revokes.build());
}

From source file:com.google.caliper.runner.ParameterSet.java

public static ParameterSet create(Class<?> theClass, Class<? extends Annotation> annotationClass)
        throws InvalidBenchmarkException {
    // deterministic order, not reflection order
    ImmutableMap.Builder<String, Parameter> parametersBuilder = ImmutableSortedMap.naturalOrder();

    for (Field field : theClass.getDeclaredFields()) {
        if (field.isAnnotationPresent(annotationClass)) {
            Parameter parameter = Parameter.create(field);
            parametersBuilder.put(field.getName(), parameter);
        }//w  w w .  ja v  a 2  s . c  o  m
    }
    return new ParameterSet(parametersBuilder.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);
        }//from w ww . j  a va 2  s  .co  m
    }
    return new PortalAPIMethodMap<T>(builder.build());
}