You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2015/05/07 20:32:33 UTC

[2/5] [lang] new test case explanations about algorithm

new test case
explanations about algorithm


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

Branch: refs/heads/master
Commit: e79a590e0cdabd93883aca964db2a862ff3f8490
Parents: 5b7608d
Author: beradrian <be...@yahoo.com>
Authored: Thu May 7 11:31:28 2015 +0300
Committer: beradrian <be...@yahoo.com>
Committed: Thu May 7 11:31:28 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/commons/lang3/ArrayUtils.java | 18 ++++++++++++++++++
 .../org/apache/commons/lang3/ArrayUtilsTest.java  |  7 +++++++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e79a590e/src/main/java/org/apache/commons/lang3/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 177a0ba..20ff85d 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -2650,6 +2650,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2708,6 +2710,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2766,6 +2770,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2824,6 +2830,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2882,6 +2890,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2940,6 +2950,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -2997,6 +3009,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -3054,6 +3068,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             
@@ -3112,6 +3128,8 @@ public class ArrayUtils {
         if (offset < 0) {
             offset += n;
         }
+        // For algorithm explanations and proof of O(n) time complexity and O(1) space complexity
+        // see https://beradrian.wordpress.com/2015/04/07/shift-an-array-in-on-in-place/
         while (n > 1 && offset > 0) {
             int n_offset = n - offset;
             

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e79a590e/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index b021719..cdd21fd 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -2484,6 +2484,13 @@ public class ArrayUtilsTest  {
         assertEquals(4, array[1]);
         assertEquals(1, array[2]);
         assertEquals(2, array[3]);
+        array = new short[] {1, 2, 3, 4, 5};
+        ArrayUtils.shift(array, 2);
+        assertEquals(4, array[0]);
+        assertEquals(5, array[1]);
+        assertEquals(1, array[2]);
+        assertEquals(2, array[3]);
+        assertEquals(3, array[4]);
     }
 
     @Test