8267110: Update java.util to use instanceof pattern variable

Reviewed-by: lancea, naoto
This commit is contained in:
Patrick Concannon 2021-05-25 08:24:49 +00:00
parent 0a03fc84b3
commit a52c4ede2f
29 changed files with 142 additions and 266 deletions

View file

@ -328,8 +328,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* one or more keys in the specified map are null
*/
public void putAll(Map<? extends K, ? extends V> m) {
if (m instanceof EnumMap) {
EnumMap<?, ?> em = (EnumMap<?, ?>)m;
if (m instanceof EnumMap<?, ?> em) {
if (em.keyType != keyType) {
if (em.isEmpty())
return;
@ -473,16 +472,12 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return containsMapping(entry.getKey(), entry.getValue());
return o instanceof Map.Entry<?, ?> entry
&& containsMapping(entry.getKey(), entry.getValue());
}
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
return removeMapping(entry.getKey(), entry.getValue());
return o instanceof Map.Entry<?, ?> entry
&& removeMapping(entry.getKey(), entry.getValue());
}
public int size() {
return size;
@ -606,10 +601,9 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
if (index < 0)
return o == this;
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> e))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
V ourValue = unmaskNull(vals[index]);
Object hisValue = e.getValue();
return (e.getKey() == keyUniverse[index] &&
@ -655,10 +649,9 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return true;
if (o instanceof EnumMap)
return equals((EnumMap<?,?>)o);
if (!(o instanceof Map))
if (!(o instanceof Map<?, ?> m))
return false;
Map<?,?> m = (Map<?,?>)o;
if (size != m.size())
return false;