Author: jbellis
Date: Tue Jul 21 03:01:42 2009
New Revision: 796131

URL: http://svn.apache.org/viewvc?rev=796131&view=rev
Log:
add BytesType comparator (like AsciiType but doesn't require that the bytes 
mean anything)
patch by jbellis; reviewed by Eric Evans for CASSANDRA-304

Added:
    
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java
      - copied, changed from r796130, 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
Modified:
    incubator/cassandra/trunk/conf/storage-conf.xml
    
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java

Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=796131&r1=796130&r2=796131&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Tue Jul 21 03:01:42 2009
@@ -53,7 +53,7 @@
                  The CompareWith attribute tells Cassandra how to sort the 
columns
                  for slicing operations.  For backwards compatibility, the 
default 
                  is to use AsciiType, which is probably NOT what you want.
-                 Other options are UTF8Type, UUIDType, and LongType.
+                 Other options are BytesType, UTF8Type, UUIDType, and LongType.
                  You can also specify the fully-qualified class name to a class
                  of your choice implementing 
org.apache.cassandra.db.marshal.IType.
 

Modified: 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java?rev=796131&r1=796130&r2=796131&view=diff
==============================================================================
--- 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
 (original)
+++ 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
 Tue Jul 21 03:01:42 2009
@@ -2,32 +2,9 @@
 
 import java.io.UnsupportedEncodingException;
 
-public class AsciiType extends AbstractType
+public class AsciiType extends BytesType
 {
-    public int compare(byte[] o1, byte[] o2)
-    {
-        int length = Math.max(o1.length, o2.length);
-        for (int i = 0; i < length; i++)
-        {
-            int index = i + 1;
-            if (index > o1.length && index <= o2.length)
-            {
-                return -1;
-            }
-            if (index > o2.length && index <= o1.length)
-            {
-                return 1;
-            }
-
-            int delta = o1[i] - o2[i];
-            if (delta != 0)
-            {
-                return delta;
-            }
-        }
-        return 0;
-    }
-
+    @Override
     public String getString(byte[] bytes)
     {
         try

Copied: 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java
 (from r796130, 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java)
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java?p2=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java&p1=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java&r1=796130&r2=796131&rev=796131&view=diff
==============================================================================
--- 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
 (original)
+++ 
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java
 Tue Jul 21 03:01:42 2009
@@ -1,8 +1,6 @@
 package org.apache.cassandra.db.marshal;
 
-import java.io.UnsupportedEncodingException;
-
-public class AsciiType extends AbstractType
+public class BytesType extends AbstractType
 {
     public int compare(byte[] o1, byte[] o2)
     {
@@ -30,13 +28,6 @@
 
     public String getString(byte[] bytes)
     {
-        try
-        {
-            return new String(bytes, "US-ASCII");
-        }
-        catch (UnsupportedEncodingException e)
-        {
-            throw new RuntimeException(e);
-        }
+        return bytes.toString();
     }
 }


Reply via email to