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:org.sonar.server.setting.NopSettingLoader.java

@Override
public void loadAll(ImmutableMap.Builder<String, String> appendTo) {
    // nothing to load
}

From source file:com.facebook.presto.connector.informationSchema.InformationSchemaColumnHandle.java

public static Map<String, ColumnHandle> toInformationSchemaColumnHandles(ConnectorTableMetadata tableMetadata) {
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
        columnHandles.put(columnMetadata.getName(),
                new InformationSchemaColumnHandle(columnMetadata.getName()));
    }// w w w.ja  v  a 2  s  . c  om

    return columnHandles.build();
}

From source file:io.dfox.junit.http.util.Collectors.java

/**
 * Create a new Collector for a Guava ImmutableMap.
 * /*  ww w. j a v a  2  s.  c om*/
 * @param <T> The type of value being collected
 * @param <K> The type of key
 * @param <U> The type of value
 * @param keyMapper The mapper for the keys of the map
 * @param valueMapper The mapper for the values of the map
 * @return The Collector for a Guava ImmutableMap
 */
public static <T, K, U> Collector<T, ?, ImmutableMap<K, U>> toImmutableMap(
        final Function<? super T, ? extends K> keyMapper, final Function<? super T, ? extends U> valueMapper) {

    return Collector.of(ImmutableMap.Builder<K, U>::new,
            (builder, e) -> builder.put(keyMapper.apply(e), valueMapper.apply(e)),
            (b1, b2) -> b1.putAll(b2.build()), (builder) -> builder.build());
}

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

public static ValidatableResponse createMergeReview(String source, String target) {
    ImmutableMap.Builder<String, Object> requestBuilder = ImmutableMap.<String, Object>builder()
            .put("source", source).put("target", target);

    return givenAuthenticatedRequest(SCT_API).contentType(ContentType.JSON).body(requestBuilder.build())
            .post("/merge-reviews").then();
}

From source file:org.openqa.selenium.server.htmlrunner.NonReflectiveSteps.java

private static ImmutableMap<String, CoreStepFactory> build() {
    ImmutableMap.Builder<String, CoreStepFactory> steps = ImmutableMap.builder();

    CoreStepFactory nextCommandFails = (locator,
            value) -> (selenium, state) -> new NextCommandFails(state.expand(locator));
    steps.put("assertErrorOnNext", nextCommandFails);
    steps.put("assertFailureOnNext", nextCommandFails);

    steps.put("verifyErrorOnNext",
            (locator, value) -> (selenium, state) -> new VerifyNextCommandFails(state.expand(locator)));
    steps.put("verifyFailureOnNext",
            (locator, value) -> (selenium, state) -> new VerifyNextCommandFails(state.expand(locator)));

    class SelectedOption implements CoreStep {

        private final String locator;
        private final String value;
        private final NextStepDecorator onFailure;

        public SelectedOption(String locator, String value, NextStepDecorator onFailure) {
            this.locator = locator;
            this.value = value;
            this.onFailure = onFailure;
        }/*from  www.  j a va 2s  . c o m*/

        @Override
        public NextStepDecorator execute(Selenium selenium, TestState state) {
            JavascriptLibrary library = new JavascriptLibrary();
            ElementFinder finder = new ElementFinder(library);
            SeleniumSelect select = new SeleniumSelect(library, finder,
                    ((WrapsDriver) selenium).getWrappedDriver(), locator);

            WebElement element = select.findOption(value);
            if (element == null) {
                return onFailure;
            }
            return NextStepDecorator.IDENTITY;
        }
    }

    steps.put("assertSelected", ((locator, value) -> new SelectedOption(locator, value,
            NextStepDecorator.ASSERTION_FAILED(value + " not selected"))));
    steps.put("verifySelected", ((locator, value) -> new SelectedOption(locator, value,
            NextStepDecorator.VERIFICATION_FAILED(value + " not selected"))));

    steps.put("echo", ((locator, value) -> (selenium, state) -> {
        LOG.info(locator);
        return NextStepDecorator.IDENTITY;
    }));

    steps.put("pause", ((locator, value) -> (selenium, state) -> {
        try {
            long timeout = Long.parseLong(state.expand(locator));
            Thread.sleep(timeout);
            return NextStepDecorator.IDENTITY;
        } catch (NumberFormatException e) {
            return NextStepDecorator
                    .ERROR(new SeleniumException("Unable to parse timeout: " + state.expand(locator)));
        } catch (InterruptedException e) {
            System.exit(255);
            throw new CoreRunnerError("We never get this far");
        }
    }));

    steps.put("store", (((locator, value) -> ((selenium, state) -> {
        state.store(state.expand(locator), state.expand(value));
        return NextStepDecorator.IDENTITY;
    }))));

    return steps.build();
}

From source file:org.janusgraph.diskstorage.es.ElasticSearchMutation.java

public static ElasticSearchMutation createUpdateRequest(String index, String type, String id,
        ImmutableMap.Builder builder, Map upsert) {
    final Map source = upsert == null ? builder.build() : builder.put(ES_UPSERT_KEY, upsert).build();
    return new ElasticSearchMutation(RequestType.UPDATE, index, type, id, source);
}

From source file:org.glowroot.plugin.servlet.DetailCapture.java

static ImmutableMap<String, Object> captureRequestParameters(Map<String, String[]> requestParameters) {
    ImmutableList<Pattern> capturePatterns = ServletPluginProperties.captureRequestParameters();
    ImmutableList<Pattern> maskPatterns = ServletPluginProperties.maskRequestParameters();
    ImmutableMap.Builder<String, Object> map = ImmutableMap.builder();
    for (Entry<String, String[]> entry : requestParameters.entrySet()) {
        String name = entry.getKey();
        if (name == null) {
            // null check just to be safe in case this is a very strange servlet container
            continue;
        }//from   w  w  w  .  j  av a2  s.  c o m
        // converted to lower case for case-insensitive matching (patterns are lower case)
        String keyLowerCase = name.toLowerCase(Locale.ENGLISH);
        if (!matchesOneOf(keyLowerCase, capturePatterns)) {
            continue;
        }
        if (matchesOneOf(keyLowerCase, maskPatterns)) {
            map.put(name, "****");
            continue;
        }
        String[] values = entry.getValue();
        if (values == null) {
            // just to be safe since ImmutableMap won't accept nulls
            map.put(name, "");
        } else if (values.length == 1) {
            map.put(name, values[0]);
        } else {
            map.put(name, ImmutableList.copyOf(values));
        }
    }
    return map.build();
}

From source file:com.haulmont.bali.util.ParamsMap.java

public static Map<String, Object> of(String paramName1, Object paramValue1, String paramName2,
        Object paramValue2, String paramName3, Object paramValue3) {
    ImmutableMap.Builder<String, Object> b = new ImmutableMap.Builder<>();
    put(b, paramName1, paramValue1);/* ww w  .j  a  v  a  2 s .  com*/
    put(b, paramName2, paramValue2);
    put(b, paramName3, paramValue3);
    return b.build();
}

From source file:com.palantir.common.collect.MapEntries.java

public static <K, V> ImmutableMap<K, V> toMap(Iterable<Entry<K, V>> it) {
    Builder<K, V> builder = ImmutableMap.builder();
    for (Entry<K, V> e : it) {
        builder.put(e.getKey(), e.getValue());
    }/* www .j a  va2s  .  c  o  m*/
    return builder.build();
}

From source file:com.logiux.review.configuration.HystrixTenacityBundleConfigurationFactory.java

@Override
public Map<TenacityPropertyKey, TenacityConfiguration> getTenacityConfigurations(
        ReviewServiceConfiguration configuration) {
    final ImmutableMap.Builder<TenacityPropertyKey, TenacityConfiguration> builder = ImmutableMap.builder();
    builder.put(HystrixDashboardKey.TRIPADVISOR_REVIEW_API, configuration.getTripadvisorTenacityConfig());
    new TenacityPropertyRegister(builder.build(), configuration.getBreakerbox()).register();
    return builder.build();
}