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:org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
    checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
            "this binder is only valid for GeneratedHttpRequests!");
    GeneratedHttpRequest gRequest = GeneratedHttpRequest.class.cast(request);

    CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
    if (options != null) {
        postParams = ImmutableMap.<String, Object>builder().putAll(postParams).putAll(options.getOptions())
                .build();// www  . j  a v  a2s .co  m
    }

    request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines
            .apply(ImmutableSet.of(Maps.transformValues(postParams, new Function<Object, String>() {
                @Override
                public String apply(Object input) {
                    return input == null ? null : input.toString();
                }
            }))));
    request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
    return request;
}

From source file:org.apache.aurora.common.args.Parsers.java

static Parsers fromConfiguration(Configuration configuration) {
    Map<Class<?>, Parser<?>> parsers = Maps
            .transformValues(Maps.uniqueIndex(configuration.parserInfo(), INFO_TO_PARSED_TYPE), INFO_TO_PARSER);
    return new Parsers(parsers);
}

From source file:io.prestosql.sql.planner.assertions.ValuesMatcher.java

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata,
        SymbolAliases symbolAliases) {/*ww w.  j av  a2s .  c  o m*/
    checkState(shapeMatches(node),
            "Plan testing framework error: shapeMatches returned false in detailMatches in %s",
            this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;

    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows())).orElse(true)) {
        return NO_MATCH;
    }

    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases,
            index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())).build());
}

From source file:org.ambraproject.rhino.view.article.ArticleOverview.java

public static ArticleOverview build(ArticleIdentifier articleId, Collection<ArticleIngestion> ingestions,
        Collection<ArticleRevision> revisions) {
    // Initialize every ingestion number with an empty list of revisions, then fill in revisions.
    Map<Integer, Collection<Integer>> ingestionTable = ingestions.stream()
            .collect(Collectors.toMap(ArticleIngestion::getIngestionNumber, ingestion -> new ArrayList<>(1)));
    for (ArticleRevision revision : revisions) {
        int ingestionKey = revision.getIngestion().getIngestionNumber();
        ingestionTable.get(ingestionKey).add(revision.getRevisionNumber());
    }/*from w ww. j  ava2s . c  o  m*/

    Map<Integer, Integer> revisionTable = revisions.stream().collect(Collectors.toMap(
            ArticleRevision::getRevisionNumber, revision -> revision.getIngestion().getIngestionNumber()));

    return new ArticleOverview(articleId, Maps.transformValues(ingestionTable, ImmutableSortedSet::copyOf),
            revisionTable);
}

From source file:com.comphenix.protocol.injector.packet.PacketRegistry.java

/**
 * Retrieve a map of every packet class to every ID.
 * <p>/*from  w  w w  .  j a  v a 2s .  c om*/
 * Deprecated: Use {@link #getPacketToType()} instead.
 * @return A map of packet classes and their corresponding ID.
 */
@Deprecated
public static Map<Class, Integer> getPacketToID() {
    initialize();

    @SuppressWarnings("unchecked")
    Map<Class, Integer> result = (Map) Maps.transformValues(NETTY.getPacketClassLookup(),
            new Function<PacketType, Integer>() {
                @Override
                public Integer apply(PacketType type) {
                    return type.getLegacyId();
                };
            });
    return result;
}

From source file:com.facebook.presto.sql.planner.assertions.ValuesMatcher.java

@Override
public MatchResult detailMatches(PlanNode node, PlanNodeCost planNodeCost, Session session, Metadata metadata,
        SymbolAliases symbolAliases) {// w  w w. j a v a2 s .  com
    checkState(shapeMatches(node),
            "Plan testing framework error: shapeMatches returned false in detailMatches in %s",
            this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;

    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows())).orElse(true)) {
        return NO_MATCH;
    }

    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases,
            index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())).build());
}

From source file:org.elasticlib.common.model.RepositoryStats.java

@Override
public Map<String, Value> toMap() {
    Map<String, Value> metadata = Maps.transformValues(metadataCounts, input -> Value.of(input));
    Map<String, Value> operations = ImmutableMap.of(Operation.CREATE.toString(), Value.of(creations),
            Operation.UPDATE.toString(), Value.of(updates), Operation.DELETE.toString(), Value.of(deletions));

    return new MapBuilder().put(OPERATIONS, operations).put(METADATA, metadata).build();
}

From source file:alluxio.job.util.SerializationUtils.java

/**
 * @param <S> the key type for the Map
 * @param <T> the type of the values in the collections which are the values for the Map
 * @param map a map to make serializable
 * @return a copy of the map with serializable values
 *//*from  ww w. j a  v a2s. c o  m*/
public static <S, T extends Serializable> Map<S, ArrayList<T>> makeValuesSerializable(
        Map<S, Collection<T>> map) {
    return Maps.transformValues(map, new Function<Collection<T>, ArrayList<T>>() {
        @Override
        public ArrayList<T> apply(Collection<T> input) {
            return new ArrayList<>(input);
        }
    });
}

From source file:com.google.cloud.logging.Structs.java

/**
 * Creates a new {@link Struct} object given the content of the provided {@code map} parameter.
 *
 * <p>Notice that all numbers (int, long, float and double) are serialized as double values.
 * Enums are serialized as strings./*from ww  w.  j  a v a  2s.com*/
 */
static Struct newStruct(Map<String, ?> map) {
    Map<String, Value> valueMap = Maps.transformValues(checkNotNull(map), OBJECT_TO_VALUE);
    return Struct.newBuilder().putAllFields(valueMap).build();
}

From source file:com.google.gerrit.metrics.dropwizard.BucketedTimer.java

@Override
public Map<Object, Metric> getCells() {
    return Maps.transformValues(cells, t -> t.metric);
}