hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-12415 Add add(byte[][] arrays) to Bytes (Jean-Marc Spaggiari)
Date Sat, 02 May 2015 01:19:36 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 d90523355 -> 30d1fe219


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/30d1fe21
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/30d1fe21
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/30d1fe21

Branch: refs/heads/branch-1
Commit: 30d1fe2195f4ed946287870e45449889f6cb5477
Parents: d905233
Author: Andrew Purtell <apurtell@apache.org>
Authored: Fri May 1 18:19:25 2015 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri May 1 18:19:25 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/30d1fe21/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 5695b94..c59071c 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
@@ -1617,6 +1617,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/30d1fe21/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 5c798ac..75baa03 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
@@ -48,6 +48,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