poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1575683 - /poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
Date Sun, 09 Mar 2014 09:49:06 GMT
Author: nick
Date: Sun Mar  9 09:49:06 2014
New Revision: 1575683

URL: http://svn.apache.org/r1575683
Log:
Patch from Shaun Kalley from bug #56023 - On CellReference, implement hashCode, fix the equals(Object)
logic, and fix inconsistent whitespace

Modified:
    poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java?rev=1575683&r1=1575682&r2=1575683&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java Sun Mar  9 09:49:06 2014
@@ -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;
+   }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message