mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8263190: Update java.io, java.math, and java.text to use instanceof pattern variable
Reviewed-by: lancea, bpb, darcy, naoto, iris, dfuchs, smarks, redestad
This commit is contained in:
parent
4f0a12ec87
commit
0f2402d0a2
15 changed files with 32 additions and 59 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -595,8 +595,7 @@ loop: while (true) {
|
|||
int utflen = in.readUnsignedShort();
|
||||
byte[] bytearr = null;
|
||||
char[] chararr = null;
|
||||
if (in instanceof DataInputStream) {
|
||||
DataInputStream dis = (DataInputStream)in;
|
||||
if (in instanceof DataInputStream dis) {
|
||||
if (dis.bytearr.length < utflen){
|
||||
dis.bytearr = new byte[utflen*2];
|
||||
dis.chararr = new char[utflen*2];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -369,8 +369,7 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
|
|||
throw new UTFDataFormatException(tooLongMsg(str, utflen));
|
||||
|
||||
final byte[] bytearr;
|
||||
if (out instanceof DataOutputStream) {
|
||||
DataOutputStream dos = (DataOutputStream)out;
|
||||
if (out instanceof DataOutputStream dos) {
|
||||
if (dos.bytearr == null || (dos.bytearr.length < (utflen + 2)))
|
||||
dos.bytearr = new byte[(utflen*2) + 2];
|
||||
bytearr = dos.bytearr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -566,11 +566,9 @@ public final class FilePermission extends Permission implements Serializable {
|
|||
*/
|
||||
@Override
|
||||
public boolean implies(Permission p) {
|
||||
if (!(p instanceof FilePermission))
|
||||
if (!(p instanceof FilePermission that))
|
||||
return false;
|
||||
|
||||
FilePermission that = (FilePermission) 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.
|
||||
|
||||
|
@ -791,11 +789,9 @@ public final class FilePermission extends Permission implements Serializable {
|
|||
if (obj == this)
|
||||
return true;
|
||||
|
||||
if (! (obj instanceof FilePermission))
|
||||
if (! (obj instanceof FilePermission that))
|
||||
return false;
|
||||
|
||||
FilePermission that = (FilePermission) obj;
|
||||
|
||||
if (this.invalid || that.invalid) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1150,15 +1146,13 @@ final class FilePermissionCollection extends PermissionCollection
|
|||
*/
|
||||
@Override
|
||||
public void add(Permission permission) {
|
||||
if (! (permission instanceof FilePermission))
|
||||
if (! (permission instanceof FilePermission fp))
|
||||
throw new IllegalArgumentException("invalid permission: "+
|
||||
permission);
|
||||
if (isReadOnly())
|
||||
throw new SecurityException(
|
||||
"attempt to add a Permission to a readonly PermissionCollection");
|
||||
|
||||
FilePermission fp = (FilePermission)permission;
|
||||
|
||||
// Add permission to map if it is absent, or replace with new
|
||||
// permission if applicable.
|
||||
perms.merge(fp.getName(), fp,
|
||||
|
@ -1195,11 +1189,9 @@ final class FilePermissionCollection extends PermissionCollection
|
|||
*/
|
||||
@Override
|
||||
public boolean implies(Permission permission) {
|
||||
if (! (permission instanceof FilePermission))
|
||||
if (! (permission instanceof FilePermission fperm))
|
||||
return false;
|
||||
|
||||
FilePermission fperm = (FilePermission) permission;
|
||||
|
||||
int desired = fperm.getMask();
|
||||
int effective = 0;
|
||||
int needed = desired;
|
||||
|
|
|
@ -2400,8 +2400,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (obj instanceof FieldReflectorKey) {
|
||||
FieldReflectorKey other = (FieldReflectorKey) obj;
|
||||
if (obj instanceof FieldReflectorKey other) {
|
||||
Class<?> referent;
|
||||
return (nullClass ? other.nullClass
|
||||
: ((referent = get()) != null) &&
|
||||
|
@ -2597,8 +2596,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
if (!(obj instanceof Key)) return false;
|
||||
Key other = (Key) obj;
|
||||
if (!(obj instanceof Key other)) return false;
|
||||
int n = length();
|
||||
if (n != other.length()) return false;
|
||||
for (int i = 0; i < n; i++) if (fieldType(i) != other.fieldType(i)) return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -476,8 +476,7 @@ public class PrintStream extends FilterOutputStream
|
|||
public boolean checkError() {
|
||||
if (out != null)
|
||||
flush();
|
||||
if (out instanceof java.io.PrintStream) {
|
||||
PrintStream ps = (PrintStream) out;
|
||||
if (out instanceof PrintStream ps) {
|
||||
return ps.checkError();
|
||||
}
|
||||
return trouble;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -432,8 +432,7 @@ public class PrintWriter extends Writer {
|
|||
if (out != null) {
|
||||
flush();
|
||||
}
|
||||
if (out instanceof java.io.PrintWriter) {
|
||||
PrintWriter pw = (PrintWriter) out;
|
||||
if (out instanceof PrintWriter pw) {
|
||||
return pw.checkError();
|
||||
} else if (psOut != null) {
|
||||
return psOut.checkError();
|
||||
|
|
|
@ -3223,9 +3223,8 @@ public class BigDecimal extends Number implements Comparable<BigDecimal> {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object x) {
|
||||
if (!(x instanceof BigDecimal))
|
||||
if (!(x instanceof BigDecimal xDec))
|
||||
return false;
|
||||
BigDecimal xDec = (BigDecimal) x;
|
||||
if (x == this)
|
||||
return true;
|
||||
if (scale != xDec.scale)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -3868,10 +3868,9 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
|
|||
if (x == this)
|
||||
return true;
|
||||
|
||||
if (!(x instanceof BigInteger))
|
||||
if (!(x instanceof BigInteger xInt))
|
||||
return false;
|
||||
|
||||
BigInteger xInt = (BigInteger) x;
|
||||
if (xInt.signum != signum)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -248,10 +248,8 @@ public final class MathContext implements Serializable {
|
|||
* settings as this object
|
||||
*/
|
||||
public boolean equals(Object x){
|
||||
MathContext mc;
|
||||
if (!(x instanceof MathContext))
|
||||
if (!(x instanceof MathContext mc))
|
||||
return false;
|
||||
mc = (MathContext) x;
|
||||
return mc.precision == this.precision
|
||||
&& mc.roundingMode == this.roundingMode; // no need for .equals()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -776,12 +776,10 @@ public class AttributedString {
|
|||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof AttributedStringIterator)) {
|
||||
if (!(obj instanceof AttributedStringIterator that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AttributedStringIterator that = (AttributedStringIterator) obj;
|
||||
|
||||
if (AttributedString.this != that.getString())
|
||||
return false;
|
||||
if (currentIndex != that.currentIndex || beginIndex != that.beginIndex || endIndex != that.endIndex)
|
||||
|
@ -1096,10 +1094,9 @@ class AttributeEntry implements Map.Entry<Attribute,Object> {
|
|||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof AttributeEntry)) {
|
||||
if (!(o instanceof AttributeEntry other)) {
|
||||
return false;
|
||||
}
|
||||
AttributeEntry other = (AttributeEntry) o;
|
||||
return other.key.equals(key) && Objects.equals(other.value, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1122,8 +1122,7 @@ public final class CompactNumberFormat extends NumberFormat {
|
|||
}
|
||||
Number divisor = matchedValue;
|
||||
if (count > 0) {
|
||||
if (matchedValue instanceof BigInteger) {
|
||||
BigInteger bigValue = (BigInteger) matchedValue;
|
||||
if (matchedValue instanceof BigInteger bigValue) {
|
||||
if (bigValue.compareTo(BigInteger.valueOf((long) Math.pow(RANGE_MULTIPLIER, count - 1))) < 0) {
|
||||
throw new IllegalArgumentException("Invalid Pattern"
|
||||
+ " [" + compactPatterns[patternIndex]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -702,9 +702,8 @@ final class DigitList implements Cloneable {
|
|||
public boolean equals(Object obj) {
|
||||
if (this == obj) // quick check
|
||||
return true;
|
||||
if (!(obj instanceof DigitList)) // (1) same object?
|
||||
if (!(obj instanceof DigitList other)) // (1) same object?
|
||||
return false;
|
||||
DigitList other = (DigitList) obj;
|
||||
if (count != other.count ||
|
||||
decimalAt != other.decimalAt)
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -221,9 +221,8 @@ public class FieldPosition {
|
|||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
if (!(obj instanceof FieldPosition))
|
||||
if (!(obj instanceof FieldPosition other))
|
||||
return false;
|
||||
FieldPosition other = (FieldPosition) obj;
|
||||
if (attribute == null) {
|
||||
if (other.attribute != null) {
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -125,9 +125,8 @@ public class ParsePosition {
|
|||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
if (!(obj instanceof ParsePosition))
|
||||
if (!(obj instanceof ParsePosition other))
|
||||
return false;
|
||||
ParsePosition other = (ParsePosition) obj;
|
||||
return (index == other.index && errorIndex == other.errorIndex);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -240,11 +240,9 @@ public final class StringCharacterIterator implements CharacterIterator
|
|||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof StringCharacterIterator))
|
||||
if (!(obj instanceof StringCharacterIterator that))
|
||||
return false;
|
||||
|
||||
StringCharacterIterator that = (StringCharacterIterator) obj;
|
||||
|
||||
if (hashCode() != that.hashCode())
|
||||
return false;
|
||||
if (!text.equals(that.text))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue