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:com.facebook.presto.benchmark.AverageBenchmarkResults.java

public Map<String, Double> getAverageResultsValues() {
    return Maps.transformValues(resultsSum, input -> 1.0 * input / resultsCount);
}

From source file:com.etsy.arbiter.util.NamedArgumentInterpolator.java

/**
 * Performs variable interpolation using the named arguments from an Action
 * This will create a new map if any interpolation is performed
 *
 * @param input The positional arguments possibly containing keys to be interpolated
 * @param namedArgs The key/value pairs used for interpolation
 * @param defaultArgs Default values for the named args, used if an interpolation key has no value given
 * @param listArgs The key/value list pairs used for list interpolation. List interpolation allows for interpolating a list of values in place of a single key
 *                 If any interpolation is performed this map is modified to remove the key that was interpolated
 *
 * @return A copy of input with variable interpolation performed
 *//* w  ww .jav a 2s  .  c  o  m*/
public static Map<String, List<String>> interpolate(Map<String, List<String>> input,
        final Map<String, String> namedArgs, final Map<String, String> defaultArgs,
        final Map<String, List<String>> listArgs) {
    if (namedArgs == null || input == null) {
        return input;
    }

    final Map<String, String> interpolationArgs = createFinalInterpolationMap(namedArgs, defaultArgs);

    return Maps.transformValues(input, new Function<List<String>, List<String>>() {
        @Override
        public List<String> apply(List<String> input) {
            List<String> result = new ArrayList<>(input.size());
            for (String s : input) {
                String interpolated = StrSubstitutor.replace(s, interpolationArgs, PREFIX, SUFFIX);
                String listInterpolationKey = interpolated.replace(PREFIX, "").replace(SUFFIX, ""); // Strip out the prefix/suffix to get the actual key

                // If we have a standalone key we can use it for list interpolation
                // We only support standalone entries as it does not make sense to interpolate a list as part of a string
                if (listArgs != null && listArgs.containsKey(listInterpolationKey)) {
                    result.addAll(listArgs.get(listInterpolationKey));
                    listArgs.remove(listInterpolationKey);
                } else {
                    result.add(interpolated);
                }
            }

            return result;
        }
    });
}

From source file:org.apache.fluo.core.impl.TxStringUtil.java

public static Map<Column, String> gets(SnapshotBase snapshot, String row, Set<Column> columns) {
    Map<Column, Bytes> values = snapshot.get(Bytes.of(row), columns);
    return Maps.transformValues(values, B2S);
}

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

private static ImmutableMap<String, Path> getCellPathsFromConfigRepositoriesSection(Path root,
        ImmutableMap<String, String> repositoriesSection) {
    return ImmutableMap.copyOf(Maps.transformValues(repositoriesSection,
            input -> root.resolve(MorePaths.expandHomeDir(root.getFileSystem().getPath(input))).normalize()));
}

From source file:io.druid.java.util.common.collect.CountingMap.java

public Set<Entry<K, Long>> entrySet() {
    return Maps.transformValues(counts, new Function<AtomicLong, Long>() {
        @Override/*from ww w .  j av a 2 s .com*/
        public Long apply(AtomicLong n) {
            return n.get();
        }
    }).entrySet();
}

From source file:uk.ac.open.kmi.iserve.discovery.ranking.impl.CommunityVitalityScorer.java

@Override
public Map<URI, Double> apply(Set<URI> resources) {
    Map<URI, Object> forumObjectMap = getNfpManager().getPropertyValueOfResources(resources,
            URI.create(MSM_NFP.hasForum.getURI()), URI.class);
    Map<URI, URI> forumMap = Maps.transformValues(forumObjectMap, new Function<Object, URI>() {
        @Override/* w w w. jav a  2  s .c  om*/
        public URI apply(Object input) {
            if (input instanceof Set) {
                if (!((Set) input).isEmpty()) {
                    return null;
                } else {
                    return (URI) ((Set) input).iterator().next();
                }
            } else {
                return (URI) input;
            }
        }
    });

    Map<URI, Object> forumVitalityObjectsMap = getNfpManager().getPropertyValueOfResources(
            new HashSet<URI>(forumMap.values()), URI.create(MSM_NFP.hasVitality.getURI()), Double.class);
    Map<URI, Double> forumVitalityMap = Maps.transformValues(forumVitalityObjectsMap,
            new Function<Object, Double>() {
                @Override
                public Double apply(Object input) {
                    Double r;
                    if (input instanceof Set) {
                        if (((Set) input).isEmpty()) {
                            return new Double(0);
                        } else {
                            r = (Double) ((Set) input).iterator().next();
                        }
                    } else {
                        r = (Double) input;
                    }
                    if (r != null && r > 0) {
                        return r / 100;
                    }
                    return Double.valueOf(0);
                }
            });
    Map<URI, Double> result = Maps.newHashMap();
    for (URI resource : resources) {
        if (forumMap.get(resource) == null) {
            result.put(resource, new Double(0));
        } else {
            result.put(resource, forumVitalityMap.get(forumMap.get(resource)));
        }
    }

    return result;
}

From source file:org.apache.metron.stellar.common.utils.ConversionUtils.java

/**
 * Performs naive Map type conversion on values. Key types remain unchanged.
 *
 * @param from Source map/*from ww w.  ja  v  a  2s.  c  o m*/
 * @param clazz Class type to cast the Map values to
 * @param <K> Map key type
 * @param <V1> Source value type
 * @param <V2> Desired value type
 * @return New Map with the values cast to the desired type
 */
public static <K, V1, V2> Map<K, V2> convertMap(Map<K, V1> from, Class<V2> clazz) {
    return Maps.transformValues(from, s -> convert(s, clazz));
}

From source file:org.jclouds.elasticstack.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines.java

@Override
public String apply(Iterable<Map<String, String>> from) {
    return Joiner.on("\n\n").join(Iterables.transform(from, new Function<Map<String, String>, String>() {

        @Override//  w  ww . j ava  2 s.c  om
        public String apply(Map<String, String> from) {
            return Joiner.on('\n').withKeyValueSeparator(" ")
                    .join(Maps.transformValues(from, new Function<String, String>() {

                        @Override
                        public String apply(String from) {
                            return from.replace("\n", "\\n");
                        }

                    }));
        }

    }));
}

From source file:org.apache.aurora.scheduler.testing.FakeStatsProvider.java

/**
 * Gets the current values of all exported stats.
 *
 * @return All exported stat names and their associated values.
 *///  w ww  .ja  va2  s . co m
public Map<String, ? extends Number> getAllValues() {
    return ImmutableMap.copyOf(Maps.transformValues(stats, Supplier::get));
}

From source file:com.threerings.tools.gxlate.spreadsheet.Row.java

Row(int num, List<String> headers, List<CellEntry> cells) {
    _num = num;//from www. j av  a  2  s.  c o m
    _values = Maps.newHashMapWithExpectedSize(cells.size());
    for (CellEntry cell : cells) {
        String header = headers.get(cell.getCell().getCol() - 1);
        _values.put(header, cell);
    }

    _stringValues = Maps.transformValues(_values, new Function<CellEntry, String>() {
        @Override
        public String apply(CellEntry entry) {
            return entry != null ? entry.getCell().getValue() : null;
        }
    });
}