添加 MapWrapper 的注释

1.x.x
ZhouXY108 2024-12-04 19:37:26 +08:00
parent 9300f02a51
commit ebacc622da
2 changed files with 30 additions and 6 deletions

View File

@ -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
*
* <p>
* {@link Map}
* Key Key value {@link Optional}
* Key Value
* </p>
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @since 1.0
*/
@Beta
public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V, T>> {
@ -40,7 +54,9 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
private final Consumer<K> keyChecker;
private final Consumer<V> valueChecker;
protected AbstractMapWrapper(Map<K, V> map, @Nullable Consumer<K> keyChecker, @Nullable Consumer<V> valueChecker) {
protected AbstractMapWrapper(Map<K, V> map,
@Nullable Consumer<K> keyChecker,
@Nullable Consumer<V> valueChecker) {
this.map = map;
this.keyChecker = keyChecker;
this.valueChecker = valueChecker;
@ -71,10 +87,9 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
* @return
* @throws IllegalArgumentException key
*/
@Nonnull
public Optional<V> 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<K, V, T extends AbstractMapWrapper<K, V
return false;
if (getClass() != obj.getClass())
return false;
@SuppressWarnings("rawtypes")
AbstractMapWrapper other = (AbstractMapWrapper) obj;
AbstractMapWrapper<?, ?, ?> other = (AbstractMapWrapper<?, ?, ?>) obj;
return Objects.equals(map, other.map);
}

View File

@ -26,6 +26,16 @@ import java.util.function.Consumer;
import com.google.common.annotations.Beta;
/**
* MapWrapper
*
* <p>
* Map
* </p>
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @since 0.1.0
*/
@Beta
public final class MapWrapper<K, V> extends AbstractMapWrapper<K, V, MapWrapper<K, V>> {