incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1208493 - in /incubator/accumulo/branches/1.4/src/core/src: main/java/org/apache/accumulo/core/data/Key.java test/java/org/apache/accumulo/core/data/KeyTest.java
Date Wed, 30 Nov 2011 16:30:22 GMT
Author: billie
Date: Wed Nov 30 16:30:21 2011
New Revision: 1208493

URL: http://svn.apache.org/viewvc?rev=1208493&view=rev
Log:
ACCUMULO-193 changed toString methods of Key and created test for toString on a Key created
with followingKey(...COLVIS)

Modified:
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/data/Key.java
    incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/data/Key.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/data/Key.java?rev=1208493&r1=1208492&r2=1208493&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/data/Key.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/data/Key.java
Wed Nov 30 16:30:21 2011
@@ -22,6 +22,8 @@ package org.apache.accumulo.core.data;
  * 
  */
 
+import static org.apache.accumulo.core.util.ByteBufferUtil.toBytes;
+
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
@@ -38,8 +40,6 @@ import org.apache.hadoop.io.WritableComp
 import org.apache.hadoop.io.WritableComparator;
 import org.apache.hadoop.io.WritableUtils;
 
-import static org.apache.accumulo.core.util.ByteBufferUtil.toBytes;
-
 public class Key implements WritableComparable<Key>, Cloneable {
   
   protected byte[] row;
@@ -444,8 +444,10 @@ public class Key implements WritableComp
   }
   
   public static String toPrintableString(byte ba[], int offset, int len, int maxLen) {
-    StringBuilder sb = new StringBuilder();
-    
+    return appendPrintableString(ba, offset, len, maxLen, new StringBuilder()).toString();
+  }
+  
+  public static StringBuilder appendPrintableString(byte ba[], int offset, int len, int maxLen,
StringBuilder sb) {
     int plen = Math.min(len, maxLen);
     
     for (int i = 0; i < plen; i++) {
@@ -460,26 +462,33 @@ public class Key implements WritableComp
       sb.append("... TRUNCATED");
     }
     
-    return sb.toString();
+    return sb;
+  }
+  
+  private StringBuilder rowColumnStringBuilder() {
+    StringBuilder sb = new StringBuilder();
+    appendPrintableString(row, 0, row.length, Constants.MAX_DATA_TO_PRINT, sb);
+    sb.append(" ");
+    appendPrintableString(colFamily, 0, colFamily.length, Constants.MAX_DATA_TO_PRINT, sb);
+    sb.append(":");
+    appendPrintableString(colQualifier, 0, colQualifier.length, Constants.MAX_DATA_TO_PRINT,
sb);
+    sb.append(" [");
+    appendPrintableString(colVisibility, 0, colVisibility.length, Constants.MAX_DATA_TO_PRINT,
sb);
+    sb.append("]");
+    return sb;
   }
   
   public String toString() {
-    String labelString = new ColumnVisibility(colVisibility).toString();
-    
-    String s = toPrintableString(row, 0, row.length, Constants.MAX_DATA_TO_PRINT) + " "
-        + toPrintableString(colFamily, 0, colFamily.length, Constants.MAX_DATA_TO_PRINT)
+ ":"
-        + toPrintableString(colQualifier, 0, colQualifier.length, Constants.MAX_DATA_TO_PRINT)
+ " " + labelString + " " + Long.toString(timestamp) + " "
-        + deleted;
-    return s;
+    StringBuilder sb = rowColumnStringBuilder();
+    sb.append(" ");
+    sb.append(Long.toString(timestamp));
+    sb.append(" ");
+    sb.append(deleted);
+    return sb.toString();
   }
   
   public String toStringNoTime() {
-    
-    String labelString = new ColumnVisibility(colVisibility).toString();
-    
-    String s = new String(row, 0, row.length) + " " + new String(colFamily, 0, colFamily.length)
+ ":" + new String(colQualifier, 0, colQualifier.length) + " "
-        + labelString;
-    return s;
+    return rowColumnStringBuilder().toString();
   }
   
   public int getLength() {

Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java?rev=1208493&r1=1208492&r2=1208493&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/data/KeyTest.java
Wed Nov 30 16:30:21 2011
@@ -16,11 +16,10 @@
  */
 package org.apache.accumulo.core.data;
 
-import org.apache.accumulo.core.data.Key;
-import org.apache.hadoop.io.Text;
-
 import junit.framework.TestCase;
 
+import org.apache.hadoop.io.Text;
+
 public class KeyTest extends TestCase {
   public void testDeletedCompare() {
     Key k1 = new Key("r1".getBytes(), "cf".getBytes(), "cq".getBytes(), new byte[0], 0, false);
@@ -93,4 +92,9 @@ public class KeyTest extends TestCase {
     assertEquals(k2, k1);
     
   }
+  
+  public void testVisibilityFollowingKey() {
+    Key k = new Key("r", "f", "q", "v");
+    assertEquals(k.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS).toString(), "r f:q
[v%00;] " + Long.MAX_VALUE + " false");
+  }
 }



Mime
View raw message