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

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

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

Map.remove介绍

[英]Removes the mapping for a key from this map if it is present.
[中]从该映射中删除密钥的映射(如果存在)。

代码示例

代码示例来源: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

@SuppressWarnings("unchecked")
@Override
public M remove(K key) {
  return (M) (back.containsKey(key) ? createFromMap(back.remove(key)) : this);
}

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

remappedConfig.remove(realtimeKey).remove(offlineKey).put(commonOfflineAndRealtimeKey, offlineValue);

代码示例来源: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

@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: 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: io.vavr/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: io.vavr/vavr

@SuppressWarnings("unchecked")
@Override
public M remove(K key) {
  return (M) (back.containsKey(key) ? createFromMap(back.remove(key)) : this);
}

代码示例来源:origin: io.vavr/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));
  }
}

相关文章