本文整理了Java中io.vavr.collection.Map.get()
方法的一些代码示例,展示了Map.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.get()
方法的具体详情如下:
包路径:io.vavr.collection.Map
类名称:Map
方法名:get
[英]Returns the Some of value to which the specified key is mapped, or None if this map contains no mapping for the key.
[中]返回指定键映射到的某个值,如果此映射不包含该键的映射,则返回None。
代码示例来源:origin: vavr-io/vavr
@Override
public Option<Traversable<V>> get(K key) {
return back.get(key);
}
代码示例来源:origin: vavr-io/vavr
@Deprecated
@Override
default V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
代码示例来源:origin: vavr-io/vavr
@Override
public V apply(K key) {
return get(key).getOrElseThrow(() -> new NoSuchElementException(String.valueOf(key)));
}
@Override
代码示例来源:origin: vavr-io/vavr
/**
* Turns this map from a partial function into a total function that
* returns defaultValue for all keys absent from the map.
*
* @param defaultValue default value to return for all keys not present in the map
* @return a total function from K to T
* @deprecated Will be removed
*/
@Deprecated
default Function1<K, V> withDefaultValue(V defaultValue) {
return k -> get(k).getOrElse(defaultValue);
}
代码示例来源:origin: vavr-io/vavr
/**
* Turns this map from a partial function into a total function that
* returns a value computed by defaultFunction for all keys
* absent from the map.
*
* @param defaultFunction function to evaluate for all keys not present in the map
* @return a total function from K to T
* @deprecated Will be removed
*/
@Deprecated
default Function1<K, V> withDefault(Function<? super K, ? extends V> defaultFunction) {
return k -> get(k).getOrElse(() -> defaultFunction.apply(k));
}
代码示例来源:origin: jdbi/jdbi
private Option<Collector<?, ?, ?>> resolveDefaultCollector(Class<?> erasedType) {
return defaultImplementations.get(erasedType).flatMap(collectors::get);
}
代码示例来源:origin: vavr-io/vavr
@Override
default boolean contains(Tuple2<K, V> element) {
return get(element._1).map(v -> Objects.equals(v, element._2)).getOrElse(false);
}
代码示例来源: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: 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")
static <K, V, M extends Map<K, V>> Tuple2<V, M> computeIfAbsent(M map, K key, Function<? super K, ? extends V> mappingFunction) {
Objects.requireNonNull(mappingFunction, "mappingFunction is null");
final Option<V> value = map.get(key);
if (value.isDefined()) {
return Tuple.of(value.get(), map);
} else {
final V newValue = mappingFunction.apply(key);
final M newMap = (M) map.put(key, newValue);
return Tuple.of(newValue, newMap);
}
}
代码示例来源:origin: vavr-io/vavr
static <K, V, U extends V, M extends Map<K, V>> M put(M map, Tuple2<? extends K, U> entry,
BiFunction<? super V, ? super U, ? extends V> merge) {
Objects.requireNonNull(merge, "the merge function is null");
final Option<V> currentValue = map.get(entry._1);
if (currentValue.isEmpty()) {
return put(map, entry);
} else {
return put(map, entry.map2(value -> merge.apply(currentValue.get(), value)));
}
}
代码示例来源: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: vavr-io/vavr
@SuppressWarnings("unchecked")
@Override
public M put(K key, V value) {
final Traversable<V> values = back.get(key).getOrElse((Traversable<V>) emptyContainer.get());
final Traversable<V> newValues = containerType.add(values, value);
return (M) (newValues == values ? this : createFromMap(back.put(key, newValues)));
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
static <K, V, M extends Map<K, V>> Tuple2<Option<V>, M> computeIfPresent(M map, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
final Option<V> value = map.get(key);
if (value.isDefined()) {
final V newValue = remappingFunction.apply(key, value.get());
final M newMap = (M) map.put(key, newValue);
return Tuple.of(Option.of(newValue), newMap);
} else {
return Tuple.of(Option.none(), map);
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public Map<String, ?> apply(Map<String, ?> childKeys, String pathPrefix) {
// Adjust the name to add the table suffix to table.name.realtime/table.name.offline
List<String> tableTypes = childKeys.get("table.types").map(tableTypesListOrString -> {
if (tableTypesListOrString instanceof String) {
return List.of((String) tableTypesListOrString);
} else if (tableTypesListOrString instanceof Collection) {
return List.ofAll((Collection<String>) tableTypesListOrString);
} else {
return List.empty();
}
}).getOrElse(List.empty()).map(Object::toString);
String tableName = childKeys.get("table.name").map(Object::toString).getOrElse(
() -> childKeys.get("table.name.realtime").map(Object::toString)
.getOrElse(() -> childKeys.get("table.name.offline").map(Object::toString).getOrNull()));
Map<String, Object> remappedConfig = (Map<String, Object>) childKeys;
for (String tableType : tableTypes) {
String tableNameKey = "table.name." + tableType.toLowerCase();
CommonConstants.Helix.TableType type = CommonConstants.Helix.TableType.valueOf(tableType.toUpperCase());
remappedConfig = remappedConfig.put(tableNameKey, TableNameBuilder.forType(type).tableNameWithType(tableName));
}
remappedConfig = remappedConfig.remove("table.name");
return remappedConfig;
}
代码示例来源:origin: vavr-io/vavr
@SuppressWarnings("unchecked")
@Override
public <K2 extends K, V2 extends V> M merge(Multimap<K2, V2> that, BiFunction<Traversable<V>, Traversable<V2>, Traversable<V>> collisionResolution) {
Objects.requireNonNull(that, "that is null");
Objects.requireNonNull(collisionResolution, "collisionResolution is null");
if (isEmpty()) {
return (M) createFromEntries(that);
} else if (that.isEmpty()) {
return (M) this;
} else {
final Map<K, Traversable<V>> result = that.keySet().foldLeft(this.back, (map, key) -> {
final Traversable<V> thisValues = map.get(key).getOrElse((Traversable<V>) emptyContainer.get());
final Traversable<V2> thatValues = that.get(key).get();
final Traversable<V> newValues = collisionResolution.apply(thisValues, thatValues);
return map.put(key, newValues);
});
return (M) createFromMap(result);
}
}
代码示例来源: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: 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")
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: Swagger2Markup/swagger2markup
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
DataFrame dataFrame = params.dataFrame;
java.util.List<MarkupTableColumn> columnSpecs = dataFrame.getColumns().map(column -> {
Integer widthRatio = Integer.valueOf(column.getMetaData().get(WIDTH_RATIO).getOrElse("0"));
return new MarkupTableColumn(column.getId().getName())
.withWidthRatio(widthRatio)
.withHeaderColumn(Boolean.parseBoolean(column.getMetaData().get(HEADER_COLUMN).getOrElse("false")))
.withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^" + widthRatio + "a");
}
).toJavaList();
IndexedSeq<IndexedSeq<String>> columnValues = dataFrame.getColumns()
.map(column -> ((StringColumn) column).getValues());
java.util.List<java.util.List<String>> cells = Array.range(0, dataFrame.getRowCount())
.map(rowNumber -> columnValues.map(values -> values.get(rowNumber)).toJavaList()).toJavaList();
return markupDocBuilder.tableWithColumnSpecs(columnSpecs, cells);
}
内容来源于网络,如有侵权,请联系作者删除!