Adding hashCode caching in line with LANG-481
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@899897 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8860c37b9d
commit
a5dc7f1e68
|
@ -44,11 +44,17 @@ public final class Range<T> implements Serializable {
|
|||
* The minimum value in this range (inclusive).
|
||||
*/
|
||||
private final T minimum;
|
||||
|
||||
/**
|
||||
* The maximum value in this range (inclusive).
|
||||
*/
|
||||
private final T maximum;
|
||||
|
||||
/**
|
||||
* Cached output hashCode (class is immutable).
|
||||
*/
|
||||
private transient int hashCode = 0;
|
||||
|
||||
/**
|
||||
* Cached output toString (class is immutable).
|
||||
*/
|
||||
|
@ -324,10 +330,14 @@ public boolean equals(Object obj) {
|
|||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
result = 37 * result + getClass().hashCode();
|
||||
result = 37 * result + this.minimum.hashCode();
|
||||
result = 37 * result + this.maximum.hashCode();
|
||||
int result = hashCode;
|
||||
if (hashCode == 0) {
|
||||
result = 17;
|
||||
result = 37 * result + getClass().hashCode();
|
||||
result = 37 * result + this.minimum.hashCode();
|
||||
result = 37 * result + this.maximum.hashCode();
|
||||
hashCode = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue