diff --git a/src/main/java/xyz/zhouxy/plusone/commons/collection/AbstractMapWrapper.java b/src/main/java/xyz/zhouxy/plusone/commons/collection/AbstractMapWrapper.java
index bd9c967..93b4242 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/collection/AbstractMapWrapper.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/collection/AbstractMapWrapper.java
@@ -27,12 +27,26 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.annotations.Beta;
+import xyz.zhouxy.plusone.commons.util.AssertTools;
import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapTools;
+/**
+ * AbstractMapWrapper
+ *
+ *
+ * 包装了一个 {@link Map}。
+ * 主要在于获取值时,如果 Key 不存在,是抛出异常;如果 Key 存在,则将 value 包装在 {@link Optional} 中 返回。
+ * 此外可以定义 Key 和 Value 的检查规则。
+ *
+ *
+ * @author ZhouXY
+ * @since 1.0
+ */
@Beta
public abstract class AbstractMapWrapper> {
@@ -40,7 +54,9 @@ public abstract class AbstractMapWrapper keyChecker;
private final Consumer valueChecker;
- protected AbstractMapWrapper(Map map, @Nullable Consumer keyChecker, @Nullable Consumer valueChecker) {
+ protected AbstractMapWrapper(Map map,
+ @Nullable Consumer keyChecker,
+ @Nullable Consumer valueChecker) {
this.map = map;
this.keyChecker = keyChecker;
this.valueChecker = valueChecker;
@@ -71,10 +87,9 @@ public abstract class AbstractMapWrapper get(K key) {
- if (!this.map.containsKey(key)) {
- throw new IllegalArgumentException("Key does not exist");
- }
+ AssertTools.checkArgument(this.map.containsKey(key), "Key does not exist");
return Optional.ofNullable(this.map.get(key));
}
@@ -180,8 +195,7 @@ public abstract class AbstractMapWrapper other = (AbstractMapWrapper, ?, ?>) obj;
return Objects.equals(map, other.map);
}
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/collection/MapWrapper.java b/src/main/java/xyz/zhouxy/plusone/commons/collection/MapWrapper.java
index c928ae6..026bd9c 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/collection/MapWrapper.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/collection/MapWrapper.java
@@ -26,6 +26,16 @@ import java.util.function.Consumer;
import com.google.common.annotations.Beta;
+/**
+ * MapWrapper
+ *
+ *
+ * Map 包装器的默认实现
+ *
+ *
+ * @author ZhouXY
+ * @since 0.1.0
+ */
@Beta
public final class MapWrapper extends AbstractMapWrapper> {