Example usage for com.google.common.collect Maps transformValues

List of usage examples for com.google.common.collect Maps transformValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps transformValues.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap,
        Function<? super V1, V2> function) 

Source Link

Document

Returns a view of a navigable map where each value is transformed by a function.

Usage

From source file:gobblin.metrics.RecursiveScheduledReporter.java

/**
 * Report a {@link com.codahale.metrics.MetricRegistry}. If the input is a {@link gobblin.metrics.MetricContext}
 * it will also report all of its children recursively.
 * @param registry MetricRegistry to report.
 *//* www  .j a va2 s.  c  o  m*/
public void report(MetricRegistry registry) {

    Map<String, String> tags = Maps.newHashMap();
    if (registry instanceof MetricContext) {
        tags = Maps.transformValues(((MetricContext) registry).getTagMap(), new Function<Object, String>() {
            @Override
            public String apply(Object input) {
                return input.toString();
            }
        });
    }

    report(registry.getGauges(), registry.getCounters(), registry.getHistograms(), registry.getMeters(),
            registry.getTimers(), tags);

    if (registry instanceof MetricContext) {
        for (MetricContext context : ((MetricContext) registry).getChildContexts().values()) {
            report(context);
        }
    }

}

From source file:org.jboss.capedwarf.shared.config.BackendsXml.java

@SuppressWarnings("unchecked")
public synchronized Map<String, String> getAddresses(Function<Backend, String> fn) {
    if (addresses == null) {
        Map<String, String> map = Maps.transformValues(backends, fn);
        addresses = Collections.unmodifiableMap(Maps.newHashMap(map));
    }//from   ww w.ja v a 2 s  . c  om
    return addresses;
}

From source file:org.jclouds.suppliers.SupplyKeyMatchingValueOrNull.java

@Override
public K get() {/*from  w w w . j  a v  a2s  .c  om*/
    V uri = valueSupplier.get();
    // eagerly get all the values, so we can see which is default
    Map<K, V> map = Maps.transformValues(supplier.get(), Suppliers.<V>supplierFunction());
    K region = ImmutableBiMap.copyOf(map).inverse().get(uri);
    if (region == null && map.size() > 0) {
        region = Iterables.get(map.keySet(), 0);
        logger.warn("failed to find key for value %s in %s; choosing first: %s", uri, map, region);
    }
    return region;
}

From source file:org.apache.aurora.scheduler.http.LeaderHealth.java

private static String generateHelpText() {
    Map<Integer, String> details = Maps
            .transformValues(Maps.uniqueIndex(RESPONSE_CODES.values(), Pair::getFirst), Pair::getSecond);

    return "This endpoint can indicate to a load balancer which among a group of schedulers "
            + "is leading.\n\nThe response codes are:\n"
            + Joiner.on("\n").withKeyValueSeparator(": ").join(details);
}

From source file:org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions.java

@Singleton
@Region//from  www. jav a  2s .c  o m
@Override
public Map<String, Supplier<URI>> get() {
    Set<String> regionWhiteList = regions.get();
    Map<String, URI> regionToUris = client.describeRegions();
    if (regionWhiteList.size() > 0)
        regionToUris = Maps.filterKeys(regionToUris, Predicates.in(regionWhiteList));
    return Maps.transformValues(regionToUris, Suppliers2.<URI>ofInstanceFunction());
}

From source file:org.trancecode.collection.TcMaps.java

public static <K, V> Map<K, V> fromEntries(final Iterable<Entry<K, V>> entries) {
    final Function<Entry<K, V>, K> keyFunction = MapFunctions.getKey();
    final Function<Entry<K, V>, V> valueFunction = MapFunctions.getValue();
    final Map<K, Entry<K, V>> intermediate = Maps.uniqueIndex(entries, keyFunction);
    return Maps.transformValues(intermediate, valueFunction);
}

From source file:org.apache.fluo.recipes.core.map.it.DocumentObserver.java

private static Map<String, Long> calculateChanges(Map<String, Long> newCounts, Map<String, Long> currCounts) {
    Map<String, Long> changes = new HashMap<>();

    // guava Maps class
    MapDifference<String, Long> diffs = Maps.difference(currCounts, newCounts);

    // compute the diffs for words that changed
    changes.putAll(/* www.jav a 2 s.  c o  m*/
            Maps.transformValues(diffs.entriesDiffering(), vDiff -> vDiff.rightValue() - vDiff.leftValue()));

    // add all new words
    changes.putAll(diffs.entriesOnlyOnRight());

    // subtract all words no longer present
    changes.putAll(Maps.transformValues(diffs.entriesOnlyOnLeft(), l -> l * -1));

    return changes;
}

From source file:org.apache.log4j.DTLoggerFactory.java

public ImmutableMap<String, String> getPatternLevels() {
    return ImmutableMap.copyOf(Maps.transformValues(patternLevel, new Function<Level, String>() {
        @Override// w  w w . ja v a2  s.co m
        public String apply(Level input) {
            return input == null ? "" : input.toString();
        }
    }));
}

From source file:org.jclouds.json.internal.ParseObjectFromElement.java

public Object apply(JsonElement input) {
    Object value = null;// w  w  w .ja  v a 2 s. co m
    if (input == null || input.isJsonNull()) {
        value = null;
    } else if (input.isJsonPrimitive()) {
        JsonPrimitive primitive = input.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            value = primitive.getAsNumber();
        } else if (primitive.isBoolean()) {
            value = primitive.getAsBoolean();
        } else {
            value = primitive.getAsString();
        }
    } else if (input.isJsonArray()) {
        value = Lists.newArrayList(Iterables.transform(input.getAsJsonArray(), this));
    } else if (input.isJsonObject()) {
        value = Maps.<String, Object>newLinkedHashMap(
                Maps.transformValues(JsonObjectAsMap.INSTANCE.apply(input.getAsJsonObject()), this));
    }
    return value;
}

From source file:solutions.tal.tools.maven.plugins.exec.ProcessExecutor.java

ProcessExecutor withEnvironmentVariables(Map<String, String> environmentVariables) {
    this.environmentVariables.putAll(Maps.transformValues(environmentVariables, new Function<String, String>() {
        @Override//from  w  w w .java2 s. c om
        public String apply(String input) {
            return input != null ? input : "";
        }
    }));
    return this;
}