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.google.idea.blaze.base.lang.projectview.language.ProjectViewKeywords.java

/** We get the parser so we have access to both the keyword and the divider char. */
private static ImmutableMap<String, ScalarSectionParser> getScalarKeywordMap() {
    ImmutableMap.Builder<String, ScalarSectionParser> builder = ImmutableMap.builder();
    for (SectionParser parser : Sections.getParsers()) {
        if (parser instanceof ScalarSectionParser) {
            builder.put(parser.getName(), (ScalarSectionParser) parser);
        }/*from w w  w .  j  a v a2s .c  om*/
    }
    return builder.build();
}

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

private static void getDefaultPropertiesFromNSDictionary(NSDictionary sdkSettingsDict,
        ImmutableMap.Builder<String, String> defaultPropertiesBuilder) {
    NSObject defaultProperties = sdkSettingsDict.objectForKey(DEFAULT_PROPERTIES_KEY);
    if (!(defaultProperties instanceof NSDictionary)) {
        throw new RuntimeException("Unexpected " + DEFAULT_PROPERTIES_KEY
                + " contents (expected NSDictionary, got " + defaultProperties + ")");
    }/* w w  w . j  a  va2s  .  c o  m*/
    NSDictionary defaultPropertiesDict = (NSDictionary) defaultProperties;
    for (String key : defaultPropertiesDict.allKeys()) {
        NSObject value = defaultPropertiesDict.objectForKey(key);
        if (!(value instanceof NSString)) {
            throw new RuntimeException(
                    "Unexpected key " + key + " contents (expected NSString, got " + value + ")");
        }
        NSString stringValue = (NSString) value;
        defaultPropertiesBuilder.put(key, stringValue.toString());
    }
}

From source file:org.apache.beam.runners.core.ReplacementOutputs.java

public static Map<PValue, ReplacementOutput> ordered(List<TaggedPValue> original, POutput replacement) {
    ImmutableMap.Builder<PValue, ReplacementOutput> result = ImmutableMap.builder();
    List<TaggedPValue> replacements = replacement.expand();
    checkArgument(original.size() == replacements.size(),
            "Original and Replacements must be the same size. Original: %s Replacement: %s", original.size(),
            replacements.size());//from   w  w w .  ja va2s  .c o  m
    int i = 0;
    for (TaggedPValue replacementPvalue : replacements) {
        result.put(replacementPvalue.getValue(), ReplacementOutput.of(original.get(i), replacementPvalue));
        i++;
    }
    return result.build();
}

From source file:org.scassandra.http.client.FunctionFailureConfig.java

@Override
Map<String, ?> getProperties() {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder()
            .put(ErrorConstants.Keyspace(), String.valueOf(this.keyspace))
            .put(ErrorConstants.Function(), String.valueOf(this.function))
            .put(ErrorConstants.Argtypes(), String.valueOf(this.argTypes));
    return builder.build();
}

From source file:com.google.errorprone.refaster.UPlaceholderStatement.java

static UPlaceholderStatement create(PlaceholderMethod placeholder, Iterable<? extends UExpression> arguments,
        ControlFlowVisitor.Result implementationFlow) {
    ImmutableList<UVariableDecl> placeholderParams = placeholder.parameters().asList();
    ImmutableList<UExpression> argumentsList = ImmutableList.copyOf(arguments);
    ImmutableMap.Builder<UVariableDecl, UExpression> builder = ImmutableMap.builder();
    for (int i = 0; i < placeholderParams.size(); i++) {
        builder.put(placeholderParams.get(i), argumentsList.get(i));
    }// w w w. j a  va  2  s . com
    return new AutoValue_UPlaceholderStatement(placeholder, builder.build(), implementationFlow);
}

From source file:org.chaston.oakfunds.storage.EnumIdentifiableSource.java

public EnumIdentifiableSource(Class<E> enumClass) {
    this.enumClass = enumClass;
    ImmutableMap.Builder<Byte, E> valuesByIdentifierBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<String, E> valuesByJsonBuilder = ImmutableMap.builder();
    EnumSet<? extends E> enumSet = EnumSet.allOf(enumClass);
    for (E enumValue : enumSet) {
        valuesByIdentifierBuilder.put(enumValue.identifier(), enumValue);
        valuesByJsonBuilder.put(enumValue.toJson(), enumValue);
    }/*from  w w w. j a  v  a  2 s  . c  o m*/
    valuesByIdentifier = valuesByIdentifierBuilder.build();
    valuesByJson = valuesByJsonBuilder.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(/*from  w ww . j av  a 2  s.c o  m*/
                        ProcessExecutorParams.builder()
                                .setCommand(ImmutableList
                                        .of(path + File.separator + python.getKey() + extension, "-"))
                                .build(),
                        new FakeProcess(0, "CPython " + python.getValue().replace('.', ' '), ""));
            }
        }
    }
    return processMap.build();
}

From source file:com.google.api.codegen.config.ResourceNameMessageConfigs.java

@Nullable
public static ResourceNameMessageConfigs createMessageResourceTypesConfig(Model model, ConfigProto configProto,
        String defaultPackage) {//from ww w .j a  va  2  s  . c  o  m
    ImmutableMap.Builder<String, ResourceNameMessageConfig> builder = ImmutableMap.builder();
    for (ResourceNameMessageConfigProto messageResourceTypesProto : configProto
            .getResourceNameGenerationList()) {
        ResourceNameMessageConfig messageResourceTypeConfig = ResourceNameMessageConfig
                .createResourceNameMessageConfig(model.getDiagCollector(), messageResourceTypesProto,
                        defaultPackage);
        builder.put(messageResourceTypeConfig.messageName(), messageResourceTypeConfig);
    }
    ImmutableMap<String, ResourceNameMessageConfig> messageResourceTypeConfigMap = builder.build();

    ListMultimap<String, FieldModel> fieldsByMessage = ArrayListMultimap.create();
    Set<String> seenProtoFiles = new HashSet<>();
    for (ProtoFile protoFile : model.getFiles()) {
        if (!seenProtoFiles.contains(protoFile.getSimpleName())) {
            seenProtoFiles.add(protoFile.getSimpleName());
            for (MessageType msg : protoFile.getMessages()) {
                ResourceNameMessageConfig messageConfig = messageResourceTypeConfigMap.get(msg.getFullName());
                if (messageConfig == null) {
                    continue;
                }
                for (Field field : msg.getFields()) {
                    if (messageConfig.getEntityNameForField(field.getSimpleName()) != null) {
                        fieldsByMessage.put(msg.getFullName(), new ProtoField(field));
                    }
                }
            }
        }
    }
    return new AutoValue_ResourceNameMessageConfigs(messageResourceTypeConfigMap, fieldsByMessage);
}

From source file:rabbit.data.internal.access.model.KeyMapBuilder.java

/**
 * Constructs a new builder.
 */
public KeyMapBuilder() {
    builder = ImmutableMap.builder();
}

From source file:com.helion3.prism.commands.PrismCommands.java

/**
 * Build a complete command hierarchy//from  www  .j  a v a2s .co m
 * @return
 */
public static CommandSpec getCommand() {
    // Build child commands
    ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
    builder.put(ImmutableList.of("i", "wand"), new InspectCommand());
    builder.put(ImmutableList.of("l", "lookup"), LookupCommand.getCommand());
    builder.put(ImmutableList.of("near"), NearCommand.getCommand());
    builder.put(ImmutableList.of("rb", "rollback"),
            ApplierCommand.getCommand(ApplierCommand.ApplierMode.ROLLBACK));
    builder.put(ImmutableList.of("rs", "restore"),
            ApplierCommand.getCommand(ApplierCommand.ApplierMode.RESTORE));
    builder.put(ImmutableList.of("undo"), UndoCommand.getCommand());
    builder.put(ImmutableList.of("ext"), ExtinguishCommand.getCommand());
    builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());

    return CommandSpec.builder().executor((source, args) -> {
        source.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
                TextColors.DARK_AQUA, "Tracking so good the NSA stole our name.\n", TextColors.GRAY, "Help: ",
                TextColors.WHITE, "/pr ?\n", TextColors.GRAY, "IRC: ", TextColors.WHITE,
                "irc.esper.net #prism\n", TextColors.GRAY, "Site: ", TextColors.WHITE,
                "http://discover-prism.com"));
        return CommandResult.empty();
    }).children(builder.build()).build();
}