docs: 补充 MapModifier 的 javadoc

This commit is contained in:
2025-10-21 14:39:46 +08:00
parent 3155964b7c
commit ddaacf1576

View File

@@ -87,45 +87,65 @@ public class MapModifier<K, V> {
} }
/** /**
* 添加一个键值对 * 添加一个键值对
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param key 要添加的 {@code key} * @param key 要添加的 {@code key}
* @param value 要添加的 {@code value} * @param value 要添加的 {@code value}
* @return MapModifier * @return MapModifier
*/ */
public MapModifier<K, V> put(K key, V value) { public MapModifier<K, V> put(@Nullable K key, @Nullable V value) {
return addOperationInternal(map -> map.put(key, value)); return addOperationInternal(map -> map.put(key, value));
} }
/** /**
* 添加一个键值对,如果 key 已经存在,则不添加 * 添加一个键值对,如果 key 已经存在,则不添加
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param key 要添加的 {@code key} * @param key 要添加的 {@code key}
* @param value 要添加的 {@code value} * @param value 要添加的 {@code value}
* @return MapModifier * @return MapModifier
*/ */
public MapModifier<K, V> putIfAbsent(K key, V value) { public MapModifier<K, V> putIfAbsent(@Nullable K key, @Nullable V value) {
return addOperationInternal(map -> map.putIfAbsent(key, value)); return addOperationInternal(map -> map.putIfAbsent(key, value));
} }
/** /**
* 添加多个键值对 * 添加多个键值对
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
*
* @param otherMap 要添加的键值对集合。
* 如果为 {@code null},则什么都不做。
* *
* @param otherMap 要添加的键值对集合
* @return MapModifier * @return MapModifier
*/ */
public MapModifier<K, V> putAll(Map<? extends K, ? extends V> otherMap) { public MapModifier<K, V> putAll(@Nullable Map<? extends K, ? extends V> otherMap) {
if (otherMap == null || otherMap.isEmpty()) {
return this;
}
return addOperationInternal(map -> map.putAll(otherMap)); return addOperationInternal(map -> map.putAll(otherMap));
} }
/** /**
* 添加多个键值对 * 添加多个键值对
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param entries 要添加的键值对集合 * @param entries 要添加的键值对集合
* @return MapModifier * @return MapModifier
*/ */
@SafeVarargs @SafeVarargs
public final MapModifier<K, V> putAll(Map.Entry<? extends K, ? extends V>... entries) { public final MapModifier<K, V> putAll(Map.Entry<? extends K, ? extends V>... entries) {
if (entries.length == 0) {
return this;
}
return addOperationInternal(map -> { return addOperationInternal(map -> {
for (Map.Entry<? extends K, ? extends V> entry : entries) { for (Map.Entry<? extends K, ? extends V> entry : entries) {
map.put(entry.getKey(), entry.getValue()); map.put(entry.getKey(), entry.getValue());
@@ -134,8 +154,13 @@ public class MapModifier<K, V> {
} }
/** /**
* 当 {@code key} 不存在时,计算对应的值,并添加到 {@code map} 中 * 当 {@code key} 不存在时,计算对应的值,并添加到 {@code map} 中
* 调用 {@link Map#computeIfAbsent(Object, Function)} *
* <p>
* 调用 {@link Map#computeIfAbsent(Object, Function)}。
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param key 要添加的 {@code key} * @param key 要添加的 {@code key}
* @param mappingFunction 计算 {@code key} 对应的值 * @param mappingFunction 计算 {@code key} 对应的值
@@ -147,8 +172,13 @@ public class MapModifier<K, V> {
} }
/** /**
* 当 {@code key} 存在时,计算对应的值,并添加到 {@code map} 中 * 当 {@code key} 存在时,计算对应的值,并添加到 {@code map} 中
* 调用 {@link Map#computeIfPresent(Object, BiFunction)} *
* <p>
* 调用 {@link Map#computeIfPresent(Object, BiFunction)}。
*
* <p>
* <b>注意:键值对是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param key 要添加的 {@code key} * @param key 要添加的 {@code key}
* @param remappingFunction 计算 {@code key} 对应的值 * @param remappingFunction 计算 {@code key} 对应的值
@@ -160,7 +190,10 @@ public class MapModifier<K, V> {
} }
/** /**
* 删除 {@code key} * 删除 {@code key}
*
* <p>
* <b>注意key 是否允许为 {@code null},由最终作用的 {@link Map} 类型决定。</b>
* *
* @param key 要删除的 {@code key} * @param key 要删除的 {@code key}
* @return MapModifier * @return MapModifier