diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 177a0ba2c..20ff85dc9 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; diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index b0217193b..cdd21fd13 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