本文整理了Java中io.vavr.collection.Map
类的一些代码示例,展示了Map
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map
类的具体详情如下:
包路径:io.vavr.collection.Map
类名称:Map
[英]An immutable Map interface.
Basic operations:
#containsKey(Object)
#containsValue(Object)
#get(Object)
#keySet()
#merge(Map)
#merge(Map,BiFunction)
#put(Object,Object)
#put(Tuple2)
#put(Object,Object,BiFunction)
#put(Tuple2,BiFunction)
#values()
Conversion:
#toJavaMap()
Filtering:
#filter(BiPredicate)
#filterKeys(Predicate)
#filterValues(Predicate)
#reject(BiPredicate)
#rejectKeys(Predicate)
#rejectValues(Predicate)
#remove(Object)
#removeAll(Iterable)
Iteration:
#forEach(BiConsumer)
#iterator(BiFunction)
#keysIterator()
#valuesIterator()
Transformation:
#bimap(Function,Function)
#flatMap(BiFunction)
#lift()
#map(BiFunction)
#mapKeys(Function)
#mapKeys(Function,BiFunction)
#mapValues(Function)
#transform(Function)
#unzip(BiFunction)
#unzip3(BiFunction)
#withDefault(Function)
#withDefaultValue(Object)
[中]一个不变的映射接口。
基本操作:
*#containsKey(对象)
*#包含值(对象)
*#获取(对象)
*#键集()
*#合并(地图)
*#合并(映射、双功能)
*#放置(对象,对象)
*#put(Tuple2)
*#put(对象、对象、双功能)
*#put(Tuple2,双功能)
*#价值观()
转换:
*#toJavaMap()
过滤:
*#过滤器(双预测)
*#过滤器键(谓词)
*#filterValues(谓词)
*#拒绝(双预测)
*#拒绝键(谓词)
*#拒绝值(谓词)
*#移除(对象)
*#移除所有(可移除)
迭代:
*#forEach(双消费者)
*#迭代器(双函数)
*#Key迭代器()
*#估值器()
转变:
*#bimap(功能,功能)
*#平面地图(双功能)
*#lift()
*#地图(双功能)
*#映射键(功能)
*#映射键(功能,双功能)
*#映射值(函数)
*#转换(功能)
*#解压(双功能)
*#unzip3(双功能)
*#带默认值(函数)
*#withDefaultValue(对象)
代码示例来源:origin: vavr-io/vavr
@Override
public Option<Traversable<V>> get(K key) {
return back.get(key);
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
private <K2, V2> Multimap<K2, V2> createFromEntries(Iterable<? extends Tuple2<? extends K2, ? extends V2>> entries) {
Map<K2, Traversable<V2>> back = emptyMapSupplier();
for (Tuple2<? extends K2, ? extends V2> entry : entries) {
if (back.containsKey(entry._1)) {
back = back.put(entry._1, containerType.add(back.get(entry._1).get(), entry._2));
} else {
back = back.put(entry._1, containerType.add(emptyContainer.get(), entry._2));
}
}
return createFromMap(back);
}
代码示例来源:origin: apache/incubator-pinot
@Override
public java.util.Map<String, T> handleChildKeys(Map<String, ?> childKeys, String pathPrefix) {
java.util.Map<String, T> returnedMap = new HashMap<>();
childKeys.groupBy(tuple2 -> tuple2._1.split("\\.", 2)[0]).map((key, values) -> {
// Drop the prefix
Map<String, ?> valuesWithoutPrefix =
values.map((configKey, configValue) -> Tuple.of(configKey.substring(key.length() + 1), configValue));
T value;
try {
value = Deserializer.deserialize(_type, valuesWithoutPrefix, "");
} catch (Exception e) {
value = null;
e.printStackTrace();
}
return Tuple.of(key, value);
}).forEach(returnedMap::put);
if (returnedMap.isEmpty()) {
return null;
} else {
return returnedMap;
}
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, M extends Map<K, V>> M replaceValue(M map, K key, V value) {
return map.containsKey(key) ? (M) map.put(key, value) : map;
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, M extends Map<K, V>> M replace(M map, Tuple2<K, V> currentElement, Tuple2<K, V> newElement) {
Objects.requireNonNull(currentElement, "currentElement is null");
Objects.requireNonNull(newElement, "newElement is null");
return (M) (map.containsKey(currentElement._1) ? map.remove(currentElement._1).put(newElement) : map);
}
代码示例来源:origin: vavr-io/vavr
static <K, V, M extends Map<K, V>> M peek(M map, Consumer<? super Tuple2<K, V>> action) {
Objects.requireNonNull(action, "action is null");
if (!map.isEmpty()) {
action.accept(map.head());
}
return map;
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, U extends V, M extends Map<K, V>> M put(M map, K key, U value,
BiFunction<? super V, ? super U, ? extends V> merge) {
Objects.requireNonNull(merge, "the merge function is null");
final Option<V> currentValue = map.get(key);
if (currentValue.isEmpty()) {
return (M) map.put(key, value);
} else {
return (M) map.put(key, merge.apply(currentValue.get(), value));
}
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
@Override
public M remove(K key, V value) {
final Traversable<V> values = back.get(key).getOrElse((Traversable<V>) emptyContainer.get());
final Traversable<V> newValues = containerType.remove(values, value);
if (newValues == values) {
return (M) this;
} else if (newValues.isEmpty()) {
return (M) createFromMap(back.remove(key));
} else {
return (M) createFromMap(back.put(key, newValues));
}
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, U extends V, M extends Map<K, V>> M merge(
M map, OfEntries<K, V, M> ofEntries,
Map<? extends K, U> that, BiFunction<? super V, ? super U, ? extends V> collisionResolution) {
Objects.requireNonNull(that, "that is null");
Objects.requireNonNull(collisionResolution, "collisionResolution is null");
if (map.isEmpty()) {
return ofEntries.apply(Map.narrow(that));
} else if (that.isEmpty()) {
return map;
} else {
return that.foldLeft(map, (result, entry) -> {
final K key = entry._1;
final U value = entry._2;
final V newValue = result.get(key).map(v -> (V) collisionResolution.apply(v, value)).getOrElse(value);
return (M) result.put(key, newValue);
});
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public Map<String, ?> apply(Map<String, ?> config, String keyPrefix) {
Option<String> tableName = config.get("table.name").map(Object::toString);
if (tableName.isDefined() && config.getOrElse("table.schemaName", null) == null) {
config = ((Map<String, Object>) config).put("table.schemaName", tableName.get());
final boolean hasRealtime = config.containsKey("table.type.realtime");
final boolean hasOffline = config.containsKey("table.type.offline");
Map<String, Object> remappedConfig = config.flatMap((k, v) -> {
if (k.startsWith("table.schema.")) {
代码示例来源:origin: apache/incubator-pinot
Set<String> profileKeys = configMap.keySet().filter(key -> key.contains(PROFILE_SEPARATOR)).toSet();
String destinationKey = enabledProfileKey.substring(0, lastUnderscoreIndex);
if (!overrideConfigMap.containsKey(destinationKey)) {
overrideConfigMap = overrideConfigMap.put(Tuple.of(destinationKey, config.getValue(enabledProfileKey)));
} else {
ConfigValue previousOverrideValue = overrideConfigMap.get(destinationKey).get();
ConfigValue newConfigValue = config.getValue(enabledProfileKey);
if (!EqualityUtils.isEqual(previousOverrideValue.unwrapped(), newConfigValue.unwrapped())) {
config = ConfigFactory.parseMap(overrideConfigMap.toJavaMap()).withFallback(config);
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, K2, U extends Map<K2, V>> U mapKeys(Map<K, V> source, U zero, Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) {
Objects.requireNonNull(zero, "zero is null");
Objects.requireNonNull(keyMapper, "keyMapper is null");
Objects.requireNonNull(valueMerge, "valueMerge is null");
return source.foldLeft(zero, (acc, entry) -> {
final K2 k2 = keyMapper.apply(entry._1);
final V v2 = entry._2;
final Option<V> v1 = acc.get(k2);
final V v = v1.isDefined() ? valueMerge.apply(v1.get(), v2) : v2;
return (U) acc.put(k2, v);
});
}
代码示例来源:origin: HalBuilder/halbuilder-core
private void renderJsonLinks(
ObjectNode objectNode, ResourceRepresentation<?> representation, boolean embedded) {
if (!representation.getLinks().isEmpty()
|| (!embedded && !representation.getNamespaces().isEmpty())) {
representation
.getNamespaces()
.map(ns -> Links.create(CURIES, ns._2, "name", ns._1)));
objectNode.set(LINKS, linksNode);
for (Tuple2<String, List<Link>> linkEntry : links.groupBy(Links::getRel).toList()) {
Rel rel = representation.getRels().get(linkEntry._1).get();
boolean coalesce = !isCollection(rel) && (isSingleton(rel) || linkEntry._2.size() == 1);
代码示例来源:origin: apache/incubator-pinot
@Override
public Map<String, ?> apply(Map<String, ?> config, String keyPrefix) {
// Generate keys for table types based on table.types
// eg. table.types=[offline,realtime] -> table.type.realtime=realtime, table.type.offline=offline
config = ((Map<String, Object>) config).merge(config.get("table.types").map(typeList -> {
if (typeList instanceof String) {
return List.of((String) typeList);
} else if (typeList instanceof Collection) {
return List.ofAll((Collection<String>) typeList);
} else {
return List.empty();
}
}).map(typeList -> typeList.map(type -> Tuple.of("table.type." + type.toString().toLowerCase(), type))
.toMap(Function.identity())).getOrElse(HashMap::empty));
config = config.remove("table.types");
return config;
}
代码示例来源:origin: netzwerg/paleo
private static void assertMetaDataParsedCorrectly(DataFrame df) {
Map<String, String> dataFrameMetaData = df.getMetaData();
assertEquals(1, dataFrameMetaData.size());
assertEquals(Option.of("netzwerg"), dataFrameMetaData.get("author"));
Map<String, String> columnMetaData = df.getColumn(df.getColumnId(2, ColumnType.DOUBLE)).getMetaData();
assertEquals(1, columnMetaData.size());
assertEquals(Option.of("m"), columnMetaData.get("unit"));
}
代码示例来源:origin: apache/incubator-pinot
Map<String, Object> remappedConfig = (Map<String, Object>) config.mapKeys(key -> {
if (key.startsWith("schema.")) {
remappedConfig.keySet().filter(key -> key.startsWith("table.") && key.endsWith(".realtime"))
.map(key -> key.substring(0, key.lastIndexOf(".realtime")));
remappedConfig.keySet().filter(key -> key.startsWith("table.") && key.endsWith(".offline"))
.map(key -> key.substring(0, key.lastIndexOf(".offline")));
String offlineKey = commonOfflineAndRealtimeKey + ".offline";
Object realtimeValue = remappedConfig.getOrElse(realtimeKey, null);
Object offlineValue = remappedConfig.getOrElse(offlineKey, null);
remappedConfig.remove(realtimeKey).remove(offlineKey).put(commonOfflineAndRealtimeKey, offlineValue);
代码示例来源:origin: apache/incubator-pinot
@Override
public Map<String, ?> unapply(Map<String, ?> config, String keyPrefix) {
Map<String, ?> tableTypeMap = config.filterKeys(key -> key.startsWith("table.type."));
java.util.List<String> tableTypes = tableTypeMap.values().map(Object::toString).toSet().toJavaList();
Map<String, Object> remappedConfig =
((Map<String, Object>) config).removeAll(tableTypeMap.keySet()).put("table.types", tableTypes);
return remappedConfig;
}
}
代码示例来源:origin: apache/incubator-pinot
Map<String, Object> dslValue = dslValues.getOrElse(keyName, HashMap.empty());
dslValue = dslValue.put(useDsl.value(), field.get(object));
dslValues = dslValues.put(keyName, dslValue);
dslClasses = dslClasses.put(keyName, useDsl.dsl());
} else if (useChildKeyHandler != null) {
ChildKeyHandler childKeyHandler = useChildKeyHandler.value().newInstance();
Map serializedChildMap = childKeyHandler.unhandleChildKeys(field.get(object), keyName);
if (serializedChildMap != null) {
serializedChildMap = serializedChildMap.map((key, value) -> Tuple.of(keyName + "." + key, value));
values = values.merge(serializedChildMap);
values = values.merge(serialize(field.get(object), field.getType(), keyName));
values = values.merge(serialize(field.get(object), field.getType(), pathContext));
final Map<String, String> dslUnparsedValues = dslValues.flatMap((configKey, dslValueData) -> {
try {
Class<? extends SingleKeyDsl> dslClass = finalDslClasses.getOrElse(configKey, null);
SingleKeyDsl dslInstance = dslClass.newInstance();
Class<?> dslValueType = dslClass.getMethod("parse", String.class).getReturnType();
values = values.merge(dslUnparsedValues);
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, M extends Map<K, V>> M put(M map, Tuple2<? extends K, ? extends V> entry) {
Objects.requireNonNull(entry, "entry is null");
return (M) map.put(entry._1, entry._2);
}
代码示例来源:origin: vavr-io/vavr
static <K, V, M extends Map<K, V>> M merge(M map, OfEntries<K, V, M> ofEntries,
Map<? extends K, ? extends V> that) {
Objects.requireNonNull(that, "that is null");
if (map.isEmpty()) {
return ofEntries.apply(Map.narrow(that));
} else if (that.isEmpty()) {
return map;
} else {
return that.foldLeft(map, (result, entry) -> !result.containsKey(entry._1) ? put(result, entry) : result);
}
}
内容来源于网络,如有侵权,请联系作者删除!