Author: bayard
Date: Sat Jan 16 08:04:40 2010
New Revision: 899897

URL: http://svn.apache.org/viewvc?rev=899897&view=rev
Log:
Adding hashCode caching in line with LANG-481

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Range.java

Modified: 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Range.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Range.java?rev=899897&r1=899896&r2=899897&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Range.java 
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/Range.java 
Sat Jan 16 08:04:40 2010
@@ -44,12 +44,18 @@
      * 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).
      */
     private transient String toString = null;
@@ -324,10 +330,14 @@
      */
     @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;
     }
 


Reply via email to