]> source.dussan.org Git - poi.git/commitdiff
Patch from Shaun Kalley from bug #56023 - On CellReference, implement hashCode, fix...
authorNick Burch <nick@apache.org>
Sun, 9 Mar 2014 09:49:06 +0000 (09:49 +0000)
committerNick Burch <nick@apache.org>
Sun, 9 Mar 2014 09:49:06 +0000 (09:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1575683 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/util/CellReference.java

index 0b063ec8b12d1e5dc6d6784759faef56c0a8fe02..63196ab3be6280751baf3680dc907ab91dfd5f13 100644 (file)
@@ -499,28 +499,35 @@ public class CellReference {
                }
        }
 
-       /**
-        * Checks whether this cell reference is equal to another object.
-        * <p>
-        *  Two cells references are assumed to be equal if their string representations
-        *  ({@link #formatAsString()}  are equal.
-        * </p>
-        */
-       @Override
-       public boolean equals(Object o){
-               if(!(o instanceof CellReference)) {
-                       return false;
-               }
-               CellReference cr = (CellReference) o;
-               return _rowIndex == cr._rowIndex
-                       && _colIndex == cr._colIndex
-                       && _isRowAbs == cr._isColAbs
-                       && _isColAbs == cr._isColAbs;
-       }
+   /**
+    * Checks whether this cell reference is equal to another object.
+    * <p>
+    *  Two cells references are assumed to be equal if their string representations
+    *  ({@link #formatAsString()}  are equal.
+    * </p>
+    */
+   @Override
+   public boolean equals(Object o){
+      if (this == o) {
+         return true;
+      }
+      if(!(o instanceof CellReference)) {
+         return false;
+      }
+      CellReference cr = (CellReference) o;
+      return _rowIndex == cr._rowIndex
+              && _colIndex == cr._colIndex
+              && _isRowAbs == cr._isRowAbs
+              && _isColAbs == cr._isColAbs;
+    }
 
-       @Override
-       public int hashCode() {
-           assert false : "hashCode not designed";
-           return 42; // any arbitrary constant will do
-       }
+    @Override
+    public int hashCode() {
+      int result = 17;
+      result = 31 * result + _rowIndex;
+      result = 31 * result + _colIndex;
+      result = 31 * result + (_isRowAbs ? 1 : 0);
+      result = 31 * result + (_isColAbs ? 1 : 0);
+      return result;
+   }
 }