cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1033806 - /cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java
Date Thu, 11 Nov 2010 02:51:36 GMT
Author: jbellis
Date: Thu Nov 11 02:51:36 2010
New Revision: 1033806

URL: http://svn.apache.org/viewvc?rev=1033806&view=rev
Log:
include key in DecoratedKey equals, compareTo, and hashcode methods
patch by tjake; reviewed by Stu Hood for CASSANDRA-1720

Modified:
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java?rev=1033806&r1=1033805&r2=1033806&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/DecoratedKey.java Thu
Nov 11 02:51:36 2010
@@ -61,7 +61,7 @@ public class DecoratedKey<T extends Toke
     @Override
     public int hashCode()
     {
-        return token.hashCode();
+        return token.hashCode() + (key == null ? 0 : key.hashCode());
     }
 
     @Override
@@ -75,12 +75,40 @@ public class DecoratedKey<T extends Toke
             return false;
 
         DecoratedKey other = (DecoratedKey) obj;
-        return token.equals(other.token);
+
+        if (token.equals(other.token))
+        {
+            if (key == null && other.key == null)
+                return true;
+
+            if (key == null || other.key == null)
+                return false;
+
+            return key.equals(other.key);
+        }
+
+        return false;
     }
 
     public int compareTo(DecoratedKey other)
     {
-        return token.compareTo(other.token);
+        int cmp = token.compareTo(other.token);
+
+        if (cmp == 0)
+        {
+            if (key == null && other.key == null)
+                return 0;
+
+            if (key == null)
+                return 1;
+
+            if (other.key == null)
+                return -1;
+
+            return key.compareTo(other.key);
+        }
+
+        return cmp;
     }
 
     public boolean isEmpty()



Mime
View raw message