8311188: Simplify and modernize equals and hashCode in java.text

Reviewed-by: lancea, naoto, rriggs
This commit is contained in:
Pavel Rappo 2023-07-18 15:12:09 +00:00
parent 1fc726a8b3
commit 1dfb0fb3e2
15 changed files with 72 additions and 98 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2023, 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
@ -91,12 +91,13 @@ public final class IntHashtable {
rehash();
}
@Override
public boolean equals (Object that) {
if (that.getClass() != this.getClass()) return false;
IntHashtable other = (IntHashtable) that;
if (!(that instanceof IntHashtable other)) {
return false;
}
if (other.size() != count || other.defaultValue != defaultValue) {
return false;
return false;
}
for (int i = 0; i < keyList.length; ++i) {
int key = keyList[i];
@ -106,6 +107,7 @@ public final class IntHashtable {
return true;
}
@Override
public int hashCode() {
// NOTE: This function isn't actually used anywhere in this package, but it's here
// in case this class is ever used to make sure we uphold the invariants about

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
@ -46,6 +46,8 @@ import java.text.BreakIterator;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.MissingResourceException;
import java.util.Objects;
import sun.text.CompactByteArray;
import sun.text.SupplementaryCharacterData;
@ -498,24 +500,9 @@ public class RuleBasedBreakIterator extends BreakIterator {
*/
@Override
public boolean equals(Object that) {
try {
if (that == null) {
return false;
}
RuleBasedBreakIterator other = (RuleBasedBreakIterator) that;
if (checksum != other.checksum) {
return false;
}
if (text == null) {
return other.text == null;
} else {
return text.equals(other.text);
}
}
catch(ClassCastException e) {
return false;
}
return that instanceof RuleBasedBreakIterator other
&& checksum == other.checksum
&& Objects.equals(text, other.text);
}
/**
@ -527,8 +514,7 @@ public class RuleBasedBreakIterator extends BreakIterator {
}
/**
* Compute a hashcode for this BreakIterator
* @return A hash code
* {@return hashcode for this BreakIterator}
*/
@Override
public int hashCode() {