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:
Henri Yandell 2010-01-16 08:04:40 +00:00
parent 8860c37b9d
commit a5dc7f1e68
1 changed files with 14 additions and 4 deletions

View File

@ -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;
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;
}