io.vavr.collection.Map.mapKeys()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中io.vavr.collection.Map.mapKeys()方法的一些代码示例,展示了Map.mapKeys()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.mapKeys()方法的具体详情如下:
包路径:io.vavr.collection.Map
类名称:Map
方法名:mapKeys

Map.mapKeys介绍

[英]Maps the keys of this Map while preserving the corresponding values.

The size of the result map may be smaller if keyMapper maps two or more distinct keys to the same new key. In this case the value at the latest of the original keys is retained. Order of keys is predictable in TreeMap (by comparator) and LinkedHashMap (insertion-order) and not predictable in HashMap.
[中]映射此映射的键,同时保留相应的值。
如果keyMapper将两个或多个不同的键映射到同一个新键,则结果映射的大小可能会更小。在这种情况下,保留最新原始关键点的值。键的顺序在TreeMap(通过comparator)和LinkedHashMap(插入顺序)中是可预测的,而在HashMap中是不可预测的。

代码示例

代码示例来源:origin: apache/incubator-pinot

@Override
 public Map<String, ?> unhandleChildKeys(java.util.List<T> values, String pathPrefix) {
  if (values == null) {
   return null;
  }

  return List.ofAll(values).flatMap(value -> {
   Map<String, ?> serializedValue = Serializer.serialize(value);
   final String name = (String) serializedValue.getOrElse("name", null);
   return serializedValue.remove("name").mapKeys(key -> name + "." + key);
  }).toMap(Function.identity());
 }
}

代码示例来源:origin: apache/incubator-pinot

Map<String, Object> remappedConfig = (Map<String, Object>) config.mapKeys(key -> {
 if (key.startsWith("schema.")) {

代码示例来源:origin: com.mercateo.eventstore/client-common

public EventStores(EventStoreFactory factory, EventStorePropertiesCollection properties) {
  this.factory = factory;
  eventstores = new ConcurrentHashMap<>();
  eventstreams = new ConcurrentHashMap<>();
  eventStoreProperties = List
    .ofAll(Option.of(properties.getEventstores()).getOrElse(Collections.emptyList()))
    .groupBy(EventStoreProperties::getName)
    .mapKeys(EventStoreName::of)
    .mapValues(List::head);
}

相关文章