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

@ -476,9 +476,8 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
if (o == this)
return true;
if (!(o instanceof Map))
if (!(o instanceof Map<?, ?> m))
return false;
Map<?,?> m = (Map<?,?>) o;
if (m.size() != size())
return false;
@ -688,10 +687,9 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
* @see #hashCode
*/
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return eq(key, e.getKey()) && eq(value, e.getValue());
return o instanceof Map.Entry<?, ?> e
&& eq(key, e.getKey())
&& eq(value, e.getValue());
}
/**
@ -822,10 +820,9 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
* @see #hashCode
*/
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return eq(key, e.getKey()) && eq(value, e.getValue());
return o instanceof Map.Entry<?, ?> e
&& eq(key, e.getKey())
&& eq(value, e.getValue());
}
/**

View File

@ -1066,13 +1066,11 @@ public class BitSet implements Cloneable, java.io.Serializable {
* @see #size()
*/
public boolean equals(Object obj) {
if (!(obj instanceof BitSet))
if (!(obj instanceof BitSet set))
return false;
if (this == obj)
return true;
BitSet set = (BitSet) obj;
checkInvariants();
set.checkInvariants();

View File

@ -1775,12 +1775,9 @@ public class Collections {
if (o == this)
return true;
if (!(o instanceof Set))
return false;
Set<?> s = (Set<?>) o;
if (s.size() != c.size())
return false;
return containsAll(s); // Invokes safe containsAll() above
return o instanceof Set<?> s
&& s.size() == c.size()
&& containsAll(s); // Invokes safe containsAll() above
}
/**
@ -1805,11 +1802,9 @@ public class Collections {
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> t = (Map.Entry<?,?>)o;
return eq(e.getKey(), t.getKey()) &&
eq(e.getValue(), t.getValue());
return o instanceof Map.Entry<?, ?> t
&& eq(e.getKey(), t.getKey())
&& eq(e.getValue(), t.getValue());
}
public String toString() {return e.toString();}
}
@ -3933,11 +3928,8 @@ public class Collections {
* setValue method.
*/
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
return s.contains(
(e instanceof CheckedEntry) ? e : checkedEntry(e, valueType));
return o instanceof Map.Entry<?, ?> e
&& s.contains((e instanceof CheckedEntry) ? e : checkedEntry(e, valueType));
}
/**
@ -3981,11 +3973,9 @@ public class Collections {
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Set))
return false;
Set<?> that = (Set<?>) o;
return that.size() == s.size()
&& containsAll(that); // Invokes safe containsAll() above
return o instanceof Set<?> that
&& that.size() == s.size()
&& containsAll(that); // Invokes safe containsAll() above
}
static <K,V,T> CheckedEntry<K,V,T> checkedEntry(Map.Entry<K,V> e,
@ -5251,8 +5241,7 @@ public class Collections {
public boolean equals(Object o) {
if (o == this)
return true;
if (o instanceof CopiesList) {
CopiesList<?> other = (CopiesList<?>) o;
if (o instanceof CopiesList<?> other) {
return n == other.n && (n == 0 || eq(element, other.element));
}
if (!(o instanceof List))

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;

View File

@ -307,13 +307,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
public final boolean equals(Object o) {
if (o == this)
return true;
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
if (Objects.equals(key, e.getKey()) &&
Objects.equals(value, e.getValue()))
return true;
}
return false;
return o instanceof Map.Entry<?, ?> e
&& Objects.equals(key, e.getKey())
&& Objects.equals(value, e.getValue());
}
}
@ -1100,16 +1097,14 @@ public class HashMap<K,V> extends AbstractMap<K,V>
return new EntryIterator();
}
public final boolean contains(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> e))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Object key = e.getKey();
Node<K,V> candidate = getNode(key);
return candidate != null && candidate.equals(e);
}
public final boolean remove(Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
if (o instanceof Map.Entry<?, ?> e) {
Object key = e.getKey();
Object value = e.getValue();
return removeNode(hash(key), key, value, true, true) != null;

View File

@ -714,9 +714,8 @@ public class Hashtable<K,V>
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
Object key = entry.getKey();
Entry<?,?>[] tab = table;
int hash = key.hashCode();
@ -729,9 +728,8 @@ public class Hashtable<K,V>
}
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object key = entry.getKey();
Entry<?,?>[] tab = table;
int hash = key.hashCode();
@ -816,9 +814,8 @@ public class Hashtable<K,V>
if (o == this)
return true;
if (!(o instanceof Map))
if (!(o instanceof Map<?, ?> t))
return false;
Map<?,?> t = (Map<?,?>) o;
if (t.size() != size())
return false;
@ -1393,9 +1390,8 @@ public class Hashtable<K,V>
}
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> e))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
(value==null ? e.getValue()==null : value.equals(e.getValue()));

View File

@ -642,8 +642,7 @@ public class IdentityHashMap<K,V>
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o instanceof IdentityHashMap) {
IdentityHashMap<?,?> m = (IdentityHashMap<?,?>) o;
} else if (o instanceof IdentityHashMap<?, ?> m) {
if (m.size() != size)
return false;
@ -654,8 +653,7 @@ public class IdentityHashMap<K,V>
return false;
}
return true;
} else if (o instanceof Map) {
Map<?,?> m = (Map<?,?>)o;
} else if (o instanceof Map<?, ?> m) {
return entrySet().equals(m.entrySet());
} else {
return false; // o is not a Map
@ -888,11 +886,9 @@ public class IdentityHashMap<K,V>
if (index < 0)
return super.equals(o);
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return (e.getKey() == unmaskNull(traversalTable[index]) &&
e.getValue() == traversalTable[index+1]);
return o instanceof Map.Entry<?, ?> e
&& e.getKey() == unmaskNull(traversalTable[index])
&& e.getValue() == traversalTable[index+1];
}
public int hashCode() {
@ -1189,16 +1185,12 @@ public class IdentityHashMap<K,V>
return new EntryIterator();
}
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 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 Entry<?, ?> entry
&& removeMapping(entry.getKey(), entry.getValue());
}
public int size() {
return size;

View File

@ -248,10 +248,9 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean containsAll(Collection<?> c) {
if (!(c instanceof JumboEnumSet))
if (!(c instanceof JumboEnumSet<?> es))
return super.containsAll(c);
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType)
return es.isEmpty();
@ -270,10 +269,9 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
* its elements are null
*/
public boolean addAll(Collection<? extends E> c) {
if (!(c instanceof JumboEnumSet))
if (!(c instanceof JumboEnumSet<?> es))
return super.addAll(c);
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) {
if (es.isEmpty())
return false;
@ -296,10 +294,9 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean removeAll(Collection<?> c) {
if (!(c instanceof JumboEnumSet))
if (!(c instanceof JumboEnumSet<?> es))
return super.removeAll(c);
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType)
return false;
@ -317,10 +314,9 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean retainAll(Collection<?> c) {
if (!(c instanceof JumboEnumSet))
if (!(c instanceof JumboEnumSet<?> es))
return super.retainAll(c);
JumboEnumSet<?> es = (JumboEnumSet<?>)c;
if (es.elementType != elementType) {
boolean changed = (size != 0);
clear();
@ -350,10 +346,9 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @return {@code true} if the specified object is equal to this set
*/
public boolean equals(Object o) {
if (!(o instanceof JumboEnumSet))
if (!(o instanceof JumboEnumSet<?> es))
return super.equals(o);
JumboEnumSet<?> es = (JumboEnumSet<?>)o;
if (es.elementType != elementType)
return size == 0 && es.size == 0;

View File

@ -101,10 +101,9 @@ final class KeyValueHolder<K,V> implements Map.Entry<K,V> {
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return key.equals(e.getKey()) && value.equals(e.getValue());
return o instanceof Map.Entry<?, ?> e
&& key.equals(e.getKey())
&& value.equals(e.getValue());
}
/**

View File

@ -681,16 +681,14 @@ public class LinkedHashMap<K,V>
return new LinkedEntryIterator();
}
public final boolean contains(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> e))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
Object key = e.getKey();
Node<K,V> candidate = getNode(key);
return candidate != null && candidate.equals(e);
}
public final boolean remove(Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
if (o instanceof Map.Entry<?, ?> e) {
Object key = e.getKey();
Object value = e.getValue();
return removeNode(hash(key), key, value, true, true) != null;

View File

@ -885,10 +885,9 @@ public final class Locale implements Cloneable, Serializable {
if (this == obj) {
return true;
}
if (!(obj instanceof LocaleKey)) {
if (!(obj instanceof LocaleKey other)) {
return false;
}
LocaleKey other = (LocaleKey)obj;
if (hash != other.hash || !base.equals(other.base)) {
return false;
}
@ -3341,12 +3340,9 @@ public final class Locale implements Cloneable, Serializable {
if (this == obj) {
return true;
}
if (!(obj instanceof LanguageRange)) {
return false;
}
LanguageRange other = (LanguageRange)obj;
return range.equals(other.range)
&& weight == other.weight;
return obj instanceof LanguageRange other
&& range.equals(other.range)
&& weight == other.weight;
}
/**

View File

@ -423,12 +423,8 @@ public final class Optional<T> {
return true;
}
if (!(obj instanceof Optional)) {
return false;
}
Optional<?> other = (Optional<?>) obj;
return Objects.equals(value, other.value);
return obj instanceof Optional<?> other
&& Objects.equals(value, other.value);
}
/**

View File

@ -295,14 +295,10 @@ public final class OptionalDouble {
return true;
}
if (!(obj instanceof OptionalDouble)) {
return false;
}
OptionalDouble other = (OptionalDouble) obj;
return (isPresent && other.isPresent)
? Double.compare(value, other.value) == 0
: isPresent == other.isPresent;
return obj instanceof OptionalDouble other
&& (isPresent && other.isPresent
? Double.compare(value, other.value) == 0
: isPresent == other.isPresent);
}
/**

View File

@ -293,14 +293,10 @@ public final class OptionalInt {
return true;
}
if (!(obj instanceof OptionalInt)) {
return false;
}
OptionalInt other = (OptionalInt) obj;
return (isPresent && other.isPresent)
return obj instanceof OptionalInt other
&& (isPresent && other.isPresent
? value == other.value
: isPresent == other.isPresent;
: isPresent == other.isPresent);
}
/**

View File

@ -293,14 +293,10 @@ public final class OptionalLong {
return true;
}
if (!(obj instanceof OptionalLong)) {
return false;
}
OptionalLong other = (OptionalLong) obj;
return (isPresent && other.isPresent)
return obj instanceof OptionalLong other
&& (isPresent && other.isPresent
? value == other.value
: isPresent == other.isPresent;
: isPresent == other.isPresent);
}
/**

View File

@ -187,15 +187,11 @@ public final class PropertyPermission extends BasicPermission {
*/
@Override
public boolean implies(Permission p) {
if (!(p instanceof PropertyPermission))
return false;
PropertyPermission that = (PropertyPermission) p;
// we get the effective mask. i.e., the "and" of this and that.
// They must be equal to that.mask for implies to return true.
return ((this.mask & that.mask) == that.mask) && super.implies(that);
return p instanceof PropertyPermission that
&& ((this.mask & that.mask) == that.mask)
&& super.implies(that);
}
/**
@ -211,13 +207,9 @@ public final class PropertyPermission extends BasicPermission {
if (obj == this)
return true;
if (! (obj instanceof PropertyPermission))
return false;
PropertyPermission that = (PropertyPermission) obj;
return (this.mask == that.mask) &&
(this.getName().equals(that.getName()));
return obj instanceof PropertyPermission that
&& this.mask == that.mask
&& this.getName().equals(that.getName());
}
/**
@ -471,14 +463,13 @@ final class PropertyPermissionCollection extends PermissionCollection
*/
@Override
public void add(Permission permission) {
if (! (permission instanceof PropertyPermission))
if (! (permission instanceof PropertyPermission pp))
throw new IllegalArgumentException("invalid permission: "+
permission);
if (isReadOnly())
throw new SecurityException(
"attempt to add a Permission to a readonly PermissionCollection");
PropertyPermission pp = (PropertyPermission) permission;
String propName = pp.getName();
// Add permission to map if it is absent, or replace with new
@ -523,10 +514,9 @@ final class PropertyPermissionCollection extends PermissionCollection
*/
@Override
public boolean implies(Permission permission) {
if (! (permission instanceof PropertyPermission))
if (! (permission instanceof PropertyPermission pp))
return false;
PropertyPermission pp = (PropertyPermission) permission;
PropertyPermission x;
int desired = pp.getMask();

View File

@ -196,10 +196,9 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean containsAll(Collection<?> c) {
if (!(c instanceof RegularEnumSet))
if (!(c instanceof RegularEnumSet<?> es))
return super.containsAll(c);
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType)
return es.isEmpty();
@ -215,10 +214,9 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
* of its elements are null
*/
public boolean addAll(Collection<? extends E> c) {
if (!(c instanceof RegularEnumSet))
if (!(c instanceof RegularEnumSet<?> es))
return super.addAll(c);
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType) {
if (es.isEmpty())
return false;
@ -241,10 +239,9 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean removeAll(Collection<?> c) {
if (!(c instanceof RegularEnumSet))
if (!(c instanceof RegularEnumSet<?> es))
return super.removeAll(c);
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType)
return false;
@ -262,10 +259,9 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @throws NullPointerException if the specified collection is null
*/
public boolean retainAll(Collection<?> c) {
if (!(c instanceof RegularEnumSet))
if (!(c instanceof RegularEnumSet<?> es))
return super.retainAll(c);
RegularEnumSet<?> es = (RegularEnumSet<?>)c;
if (es.elementType != elementType) {
boolean changed = (elements != 0);
elements = 0;
@ -294,10 +290,9 @@ class RegularEnumSet<E extends Enum<E>> extends EnumSet<E> {
* @return {@code true} if the specified object is equal to this set
*/
public boolean equals(Object o) {
if (!(o instanceof RegularEnumSet))
if (!(o instanceof RegularEnumSet<?> es))
return super.equals(o);
RegularEnumSet<?> es = (RegularEnumSet<?>)o;
if (es.elementType != elementType)
return elements == 0 && es.elements == 0;
return es.elements == elements;

View File

@ -2664,9 +2664,8 @@ public final class Scanner implements Iterator<String>, Closeable {
*/
public BigInteger nextBigInteger(int radix) {
// Check cached result
if ((typeCache != null) && (typeCache instanceof BigInteger)
if ((typeCache != null) && (typeCache instanceof BigInteger val)
&& this.radix == radix) {
BigInteger val = (BigInteger)typeCache;
useTypeCache();
return val;
}
@ -2730,8 +2729,7 @@ public final class Scanner implements Iterator<String>, Closeable {
*/
public BigDecimal nextBigDecimal() {
// Check cached result
if ((typeCache != null) && (typeCache instanceof BigDecimal)) {
BigDecimal val = (BigDecimal)typeCache;
if ((typeCache != null) && (typeCache instanceof BigDecimal val)) {
useTypeCache();
return val;
}

View File

@ -818,11 +818,8 @@ public final class ServiceLoader<S>
@Override
public boolean equals(Object ob) {
if (!(ob instanceof ProviderImpl))
return false;
@SuppressWarnings("unchecked")
ProviderImpl<?> that = (ProviderImpl<?>)ob;
return this.service == that.service
return ob instanceof @SuppressWarnings("unchecked")ProviderImpl<?> that
&& this.service == that.service
&& this.type == that.type
&& Objects.equals(this.acc, that.acc);
}

View File

@ -878,19 +878,14 @@ public class SimpleTimeZone extends TimeZone {
* @return True if the given {@code obj} is the same as this
* {@code SimpleTimeZone} object; false otherwise.
*/
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) obj;
return getID().equals(that.getID()) &&
hasSameRules(that);
return obj instanceof SimpleTimeZone that
&& getID().equals(that.getID())
&& hasSameRules(that);
}
/**
@ -904,28 +899,26 @@ public class SimpleTimeZone extends TimeZone {
if (this == other) {
return true;
}
if (!(other instanceof SimpleTimeZone)) {
return false;
}
SimpleTimeZone that = (SimpleTimeZone) other;
return rawOffset == that.rawOffset &&
useDaylight == that.useDaylight &&
(!useDaylight
// Only check rules if using DST
|| (dstSavings == that.dstSavings &&
startMode == that.startMode &&
startMonth == that.startMonth &&
startDay == that.startDay &&
startDayOfWeek == that.startDayOfWeek &&
startTime == that.startTime &&
startTimeMode == that.startTimeMode &&
endMode == that.endMode &&
endMonth == that.endMonth &&
endDay == that.endDay &&
endDayOfWeek == that.endDayOfWeek &&
endTime == that.endTime &&
endTimeMode == that.endTimeMode &&
startYear == that.startYear));
return other instanceof SimpleTimeZone that
&& rawOffset == that.rawOffset
&& useDaylight == that.useDaylight
&& (!useDaylight ||
// Only check rules if using DST
(dstSavings == that.dstSavings
&& startMode == that.startMode
&& startMonth == that.startMonth
&& startDay == that.startDay
&& startDayOfWeek == that.startDayOfWeek
&& startTime == that.startTime
&& startTimeMode == that.startTimeMode
&& endMode == that.endMode
&& endMonth == that.endMonth
&& endDay == that.endDay
&& endDayOfWeek == that.endDayOfWeek
&& endTime == that.endTime
&& endTimeMode == that.endTimeMode
&& startYear == that.startYear)
);
}
/**

View File

@ -1341,18 +1341,16 @@ public class TreeMap<K,V>
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey());
return p != null && valEquals(p.getValue(), value);
}
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object value = entry.getValue();
Entry<K,V> p = getEntry(entry.getKey());
if (p != null && valEquals(p.getValue(), value)) {
@ -1963,9 +1961,8 @@ public class TreeMap<K,V>
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object key = entry.getKey();
if (!inRange(key))
return false;
@ -1975,9 +1972,8 @@ public class TreeMap<K,V>
}
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Entry<?, ?> entry))
return false;
Map.Entry<?,?> entry = (Map.Entry<?,?>) o;
Object key = entry.getKey();
if (!inRange(key))
return false;
@ -2425,11 +2421,9 @@ public class TreeMap<K,V>
}
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return valEquals(key,e.getKey()) && valEquals(value,e.getValue());
return o instanceof Map.Entry<?, ?> e
&& valEquals(key,e.getKey())
&& valEquals(value,e.getValue());
}
public int hashCode() {

View File

@ -299,9 +299,8 @@ public class TreeSet<E> extends AbstractSet<E>
// Use linear-time version if applicable
if (m.size()==0 && c.size() > 0 &&
c instanceof SortedSet &&
m instanceof TreeMap) {
m instanceof TreeMap<E, Object> map) {
SortedSet<? extends E> set = (SortedSet<? extends E>) c;
TreeMap<E,Object> map = (TreeMap<E, Object>) m;
if (Objects.equals(set.comparator(), map.comparator())) {
map.addAllForTreeSet(set, PRESENT);
return true;

View File

@ -619,10 +619,9 @@ public class WeakHashMap<K,V>
/** Special version of remove needed by Entry set */
boolean removeMapping(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> entry))
return false;
Entry<K,V>[] tab = getTable();
Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
Object k = maskNull(entry.getKey());
int h = hash(k);
int i = indexFor(h, tab.length);
@ -737,9 +736,8 @@ public class WeakHashMap<K,V>
}
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
if (!(o instanceof Map.Entry<?, ?> e))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
K k1 = getKey();
Object k2 = e.getKey();
if (k1 == k2 || (k1 != null && k1.equals(k2))) {
@ -977,11 +975,9 @@ public class WeakHashMap<K,V>
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<?,?> e = (Map.Entry<?,?>)o;
Entry<K,V> candidate = getEntry(e.getKey());
return candidate != null && candidate.equals(e);
return o instanceof Map.Entry<?, ?> e
&& getEntry(e.getKey()) != null
&& getEntry(e.getKey()).equals(e);
}
public boolean remove(Object o) {

View File

@ -514,12 +514,8 @@ public class Attributes implements Map<Object,Object>, Cloneable {
if (this == o) {
return true;
}
if (o instanceof Name) {
Name other = (Name)o;
return other.name.equalsIgnoreCase(name);
} else {
return false;
}
return o instanceof Name other
&& other.name.equalsIgnoreCase(name);
}
/**

View File

@ -551,10 +551,9 @@ class JarVerifier {
* Match CodeSource to a CodeSigner[] in the signer cache.
*/
private CodeSigner[] findMatchingSigners(CodeSource cs) {
if (cs instanceof VerifierCodeSource) {
VerifierCodeSource vcs = (VerifierCodeSource) cs;
if (cs instanceof VerifierCodeSource vcs) {
if (vcs.isSameDomain(csdomain)) {
return ((VerifierCodeSource) cs).getPrivateSigners();
return vcs.getPrivateSigners();
}
}
@ -617,8 +616,7 @@ class JarVerifier {
if (obj == this) {
return true;
}
if (obj instanceof VerifierCodeSource) {
VerifierCodeSource that = (VerifierCodeSource) obj;
if (obj instanceof VerifierCodeSource that) {
/*
* Only compare against other per-signer singletons constructed

View File

@ -379,13 +379,9 @@ public class Manifest implements Cloneable {
* the same main Attributes and entries
*/
public boolean equals(Object o) {
if (o instanceof Manifest) {
Manifest m = (Manifest)o;
return attr.equals(m.getMainAttributes()) &&
entries.equals(m.getEntries());
} else {
return false;
}
return o instanceof Manifest m
&& attr.equals(m.getMainAttributes())
&& entries.equals(m.getEntries());
}
/**

View File

@ -3083,8 +3083,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
if (saveTCNCount < topClosureNodes.size())
topClosureNodes.subList(saveTCNCount, topClosureNodes.size()).clear();
if (node instanceof Ques) {
Ques ques = (Ques) node;
if (node instanceof Ques ques) {
if (ques.type == Qtype.POSSESSIVE) {
root = node;
return node;
@ -3098,8 +3097,7 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) {
}
root = tail;
return head;
} else if (node instanceof Curly) {
Curly curly = (Curly) node;
} else if (node instanceof Curly curly) {
if (curly.type == Qtype.POSSESSIVE) {
root = node;
return node;

View File

@ -131,21 +131,18 @@ class PrintPattern {
node = loop;
} else if (node instanceof Pattern.Loop) {
return; // stop here, body.next -> loop
} else if (node instanceof Pattern.Curly) {
Pattern.Curly c = (Pattern.Curly)node;
} else if (node instanceof Pattern.Curly c) {
str = "Curly " + c.type + " " + toStringRange(c.cmin, c.cmax);
print(node, str, depth);
walk(c.atom, depth);
print("/Curly", depth);
} else if (node instanceof Pattern.GroupCurly) {
Pattern.GroupCurly gc = (Pattern.GroupCurly)node;
} else if (node instanceof Pattern.GroupCurly gc) {
str = "GroupCurly " + gc.groupIndex / 2 +
", " + gc.type + " " + toStringRange(gc.cmin, gc.cmax);
print(node, str, depth);
walk(gc.atom, depth);
print("/GroupCurly", depth);
} else if (node instanceof Pattern.GroupHead) {
Pattern.GroupHead head = (Pattern.GroupHead)node;
} else if (node instanceof Pattern.GroupHead head) {
Pattern.GroupTail tail = head.tail;
print(head, "Group.head " + (tail.groupIndex / 2), depth);
walk(head.next, depth);
@ -157,8 +154,7 @@ class PrintPattern {
print(node, "Ques " + ((Pattern.Ques)node).type, depth);
walk(((Pattern.Ques)node).atom, depth);
print("/Ques", depth);
} else if (node instanceof Pattern.Branch) {
Pattern.Branch b = (Pattern.Branch)node;
} else if (node instanceof Pattern.Branch b) {
print(b, name, depth);
int i = 0;
while (true) {
@ -186,8 +182,7 @@ class PrintPattern {
str = name + " \"" +
toStringCPS(((Pattern.SliceNode)node).buffer) + "\"";
print(node, str, depth);
} else if (node instanceof Pattern.CharPropertyGreedy) {
Pattern.CharPropertyGreedy gcp = (Pattern.CharPropertyGreedy)node;
} else if (node instanceof Pattern.CharPropertyGreedy gcp) {
String pstr = pmap.get(gcp.predicate);
if (pstr == null)
pstr = gcp.predicate.toString();

View File

@ -1218,8 +1218,7 @@ public class ZipFile implements ZipConstants, Closeable {
}
public boolean equals(Object obj) {
if (obj instanceof Key) {
Key key = (Key)obj;
if (obj instanceof Key key) {
if (key.utf8 != utf8) {
return false;
}