mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8312089: Simplify and modernize equals, hashCode, and compareTo in java.nio and implementation code
Reviewed-by: alanb, vtewari
This commit is contained in:
parent
6a09992dbd
commit
5cc71f817f
14 changed files with 62 additions and 123 deletions
|
@ -954,15 +954,15 @@ public abstract class Charset
|
|||
* @return A negative integer, zero, or a positive integer as this charset
|
||||
* is less than, equal to, or greater than the specified charset
|
||||
*/
|
||||
@Override
|
||||
public final int compareTo(Charset that) {
|
||||
return (name().compareToIgnoreCase(that.name()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a hashcode for this charset.
|
||||
*
|
||||
* @return An integer hashcode
|
||||
* {@return the hashcode for this charset}
|
||||
*/
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return name().hashCode();
|
||||
}
|
||||
|
@ -976,19 +976,17 @@ public abstract class Charset
|
|||
* @return {@code true} if, and only if, this charset is equal to the
|
||||
* given object
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object ob) {
|
||||
if (!(ob instanceof Charset))
|
||||
return false;
|
||||
if (this == ob)
|
||||
return true;
|
||||
return name.equals(((Charset)ob).name());
|
||||
return ob instanceof Charset other && name.equals(other.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing this charset.
|
||||
*
|
||||
* @return A string describing this charset
|
||||
* {@return a string describing this charset}
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return name();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue