AbstractMapWrapper 覆写 hashCode 和 equals

pull/1/head
ZhouXY108 2024-11-02 11:47:41 +08:00
parent 476d3c5ac9
commit 7951172d68
1 changed files with 19 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -166,6 +167,24 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
return this.map.toString();
}
@Override
public int hashCode() {
return Objects.hash(map);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
@SuppressWarnings("rawtypes")
AbstractMapWrapper other = (AbstractMapWrapper) obj;
return Objects.equals(map, other.map);
}
public abstract static class Builder<K, V, T extends AbstractMapWrapper<K, V, T>> {
protected final Map<K, V> map;
protected Consumer<K> keyChecker;