8170945: Collectors$Partition should override more Map methods

Reviewed-by: smarks
This commit is contained in:
Viktor Klang 2023-04-14 09:16:16 +00:00 committed by Tagir F. Valeev
parent 0826ceee65
commit 54bf370079

View File

@ -1972,6 +1972,35 @@ public final class Collectors {
this.forFalse = forFalse;
}
@Override
public int size() {
return 2;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public T get(Object key) {
if (key instanceof Boolean b) {
return b ? forTrue : forFalse;
} else {
return null;
}
}
@Override
public boolean containsKey(Object key) {
return key instanceof Boolean;
}
@Override
public boolean containsValue(Object value) {
return Objects.equals(value, forTrue) || Objects.equals(value, forFalse);
}
@Override
public Set<Map.Entry<Boolean, T>> entrySet() {
return new AbstractSet<>() {