hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [3/4] hbase git commit: HBASE-12415 Add add(byte[][] arrays) to Bytes (Jean-Marc Spaggiari)
Date Sat, 02 May 2015 01:18:43 GMT
HBASE-12415 Add add(byte[][] arrays) to Bytes (Jean-Marc Spaggiari)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/de5b226b
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/de5b226b
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/de5b226b

Branch: refs/heads/branch-1.0
Commit: de5b226b07239c9ab4c622155fa17c80abef66ee
Parents: 7a2e772
Author: Andrew Purtell <apurtell@apache.org>
Authored: Fri May 1 18:12:36 2015 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri May 1 18:16:28 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hbase/util/Bytes.java  | 18 ++++++++++++++++++
 .../org/apache/hadoop/hbase/util/TestBytes.java   | 13 +++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/de5b226b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
index 05d5ad1..76012c9 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
@@ -1580,6 +1580,24 @@ public class Bytes {
   }
 
   /**
+   * @param arrays all the arrays to concatenate together.
+   * @return New array made from the concatenation of the given arrays.
+   */
+  public static byte [] add(final byte [][] arrays) {
+    int length = 0;
+    for (int i = 0; i < arrays.length; i++) {
+      length += arrays[i].length;
+    }
+    byte [] result = new byte[length];
+    int index = 0;
+    for (int i = 0; i < arrays.length; i++) {
+      System.arraycopy(arrays[i], 0, result, index, arrays[i].length);
+      index += arrays[i].length;
+    }
+    return result;
+  }
+
+  /**
    * @param a array
    * @param length amount of bytes to grab
    * @return First <code>length</code> bytes from <code>a</code>

http://git-wip-us.apache.org/repos/asf/hbase/blob/de5b226b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
index 1a76536..909294d 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java
@@ -47,6 +47,19 @@ public class TestBytes extends TestCase {
     assertNotNull(ee);
   }
 
+  public void testAdd () throws Exception {
+    byte[] a = {0,0,0,0,0,0,0,0,0,0};
+    byte[] b = {1,1,1,1,1,1,1,1,1,1,1};
+    byte[] c = {2,2,2,2,2,2,2,2,2,2,2,2};
+    byte[] d = {3,3,3,3,3,3,3,3,3,3,3,3,3};
+    byte[] result1 = Bytes.add (a, b, c);
+    byte[] result2 = Bytes.add (new byte[][] {a, b, c});
+    assertEquals(0, Bytes.compareTo(result1, result2));
+    byte[] result4 = Bytes.add (result1, d);
+    byte[] result5 = Bytes.add (new byte[][] {result1, d});
+    assertEquals(0, Bytes.compareTo(result1, result2));
+  }
+
   public void testSplit() throws Exception {
     byte [] lowest = Bytes.toBytes("AAA");
     byte [] middle = Bytes.toBytes("CCC");


Mime
View raw message