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.addthis.hydra.job.spawn.SpawnUtils.java

public static Map<String, JobMacro> getMacroMapFromMacroManager(JobEntityManager<JobMacro> jobMacroManager) {
    ImmutableMap.Builder<String, JobMacro> builder = ImmutableMap.builder();

    for (String macroName : jobMacroManager.getKeys()) {
        builder.put(macroName, jobMacroManager.getEntity(macroName));
    }/*from www. java 2  s .  c  o m*/

    return builder.build();
}

From source file:com.wrmsr.kleist.util.collect.MoreMaps.java

public static <T> Map<T, Integer> indexMap(Iterator<T> it) {
    int size = 0;
    ImmutableMap.Builder<T, Integer> builder = ImmutableMap.builder();
    while (it.hasNext()) {
        T item = it.next();/*from   w w w .  j  a va 2  s  . c om*/
        builder.put(item, size++);
    }
    return builder.build();
}

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

public static ImmutableMap<String, ImmutableMap<String, String>> read(Reader reader) throws IOException {
    Ini ini = new Ini();
    ini.load(reader);// w  w w .  j  ava  2  s .  com
    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:com.facebook.buck.util.Optionals.java

public static <K, T> void putIfPresent(Optional<T> optional, K key, ImmutableMap.Builder<K, T> collection) {
    if (optional.isPresent()) {
        collection.put(key, optional.get());
    }/*ww  w  .  j av  a 2s  .com*/
}

From source file:com.facebook.buck.android.AppModularityMetadataUtil.java

public static ImmutableMap<String, String> getClassToModuleMap(ProjectFilesystem filesystem, Path metadataFile)
        throws IOException {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

    List<String> metadataLines = filesystem.readLines(metadataFile);
    Iterator<String> lineIterator = metadataLines.iterator();

    // find classes header
    while (true) {
        if (!lineIterator.hasNext()) {
            // failed to hit class header
            return builder.build();
        }/*w w  w. j a v  a  2s  . c o m*/
        String headerCheck = lineIterator.next();
        if (headerCheck.equals(WriteAppModuleMetadataStep.CLASS_SECTION_HEADER)) {
            break;
        }
    }

    boolean inClassCheck = false;
    String currentModule = "";

    while (lineIterator.hasNext()) {
        String line = lineIterator.next();
        if (inClassCheck) {
            // check to see if the line is a class.
            if (line.startsWith(WriteAppModuleMetadataStep.ITEM_INDENTATION)) {
                String className = line.trim();
                // add the pair to the map.
                builder.put(className, currentModule);
            } else {
                // otherwise we are done with the current module.
                // and a module check is necessary.
                inClassCheck = false;
            }
        }
        if (!inClassCheck) {
            // if the module check fails we are done with class metadata
            if (!line.startsWith(WriteAppModuleMetadataStep.MODULE_INDENTATION)) {
                break;
            }
            // otherwise need to check classes for the new module.
            currentModule = line.trim();
            inClassCheck = true;
        }
    }
    return builder.build();
}

From source file:org.gradle.model.dsl.internal.inputs.RuleInputAccessBacking.java

public static void runWithContext(Inputs inputs, Runnable runnable) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    for (ModelRuleInput<?> ruleInput : inputs.getRuleInputs()) {
        assert ruleInput.getBinding().getReference().isUntyped(); // We are relying on inputs being untyped
        builder.put(ruleInput.getBinding().getPath().toString(), ruleInput.getView().getInstance());
    }/*ww  w  . j av a2  s  .co m*/

    ImmutableMap<String, Object> inputsMap = builder.build();
    INPUT.set(inputsMap);
    try {
        runnable.run();
    } finally {
        INPUT.remove();
    }
}

From source file:com.b2international.snowowl.snomed.api.rest.SnomedIdentifierRestRequests.java

public static ValidatableResponse generateSctId(SnomedComponentType type, String namespaceId) {
    final ImmutableMap.Builder<String, String> requestBuilder = ImmutableMap.builder();
    requestBuilder.put("type", type.toString());

    if (namespaceId != null) {
        requestBuilder.put("namespace", namespaceId);
    }/* www.java2 s  . c o m*/

    return givenAuthenticatedRequest(SnomedApiTestConstants.SCT_API).contentType(ContentType.JSON)
            .body(requestBuilder.build()).post("/ids").then();
}

From source file:co.cask.cdap.internal.app.runtime.Datasets.java

public static Map<String, Dataset> createDatasets(DatasetContext context, Iterable<String> datasetNames,
        Map<String, String> arguments) {

    ImmutableMap.Builder<String, Dataset> builder = ImmutableMap.builder();
    for (String name : datasetNames) {
        Dataset dataset;//  w  w w.ja  va 2s.  com
        if (arguments != null && !arguments.isEmpty()) {
            Map<String, String> datasetArguments = RuntimeArguments.extractScope(Scope.DATASET, name,
                    arguments);
            dataset = context.getDataset(name, datasetArguments);
        } else {
            dataset = context.getDataset(name);
        }
        builder.put(name, dataset);
    }
    return builder.build();
}

From source file:com.google.idea.blaze.base.lang.buildfile.lexer.BuildToken.java

private static ImmutableMap<TokenKind, BuildToken> createMap() {
    ImmutableMap.Builder<TokenKind, BuildToken> builder = ImmutableMap.builder();
    for (TokenKind kind : TokenKind.values()) {
        builder.put(kind, new BuildToken(kind));
    }// w w w . j a  va  2  s .  co  m
    return builder.build();
}

From source file:org.apache.tajo.util.TimeZoneUtil.java

private static ImmutableMap<String, String> load() {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder();
    String[] timezoneIds = java.util.TimeZone.getAvailableIDs();
    for (String timezoneId : timezoneIds) {
        builder.put(timezoneId.toUpperCase(), timezoneId);
    }/*from w  w w  . ja  v a2 s  . c  om*/

    return builder.build();
}