diff --git a/guava-tests/test/com/google/common/primitives/BooleansTest.java b/guava-tests/test/com/google/common/primitives/BooleansTest.java index ac0f08979966..3b561aae00c3 100644 --- a/guava-tests/test/com/google/common/primitives/BooleansTest.java +++ b/guava-tests/test/com/google/common/primitives/BooleansTest.java @@ -342,6 +342,19 @@ public void testRotate_multiElementArray() { new boolean[] {true, true, false, true, false}); } + public void testRotate_minValueDistance() { + testRotate( + new boolean[] {true, false, false}, + Integer.MIN_VALUE, + new boolean[] {false, true, false}); + testRotate( + new boolean[] {false, true, false, false, true}, + Integer.MIN_VALUE, + 1, + 4, + new boolean[] {false, false, true, false, true}); + } + public void testRotateIndexed_emptyRange() { boolean[] empty = {}; boolean[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/BytesTest.java b/guava-tests/test/com/google/common/primitives/BytesTest.java index c2dbb9924dc7..d7b425cf1acd 100644 --- a/guava-tests/test/com/google/common/primitives/BytesTest.java +++ b/guava-tests/test/com/google/common/primitives/BytesTest.java @@ -367,6 +367,16 @@ public void testRotate_multiElementArray() { testRotate(new byte[] {1, 2, 3, 4, 5}, 6, new byte[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new byte[] {1, 2, 3}, Integer.MIN_VALUE, new byte[] {3, 1, 2}); + testRotate( + new byte[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new byte[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { byte[] empty = {}; byte[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/CharsTest.java b/guava-tests/test/com/google/common/primitives/CharsTest.java index a83c11b6de06..4195aa01c733 100644 --- a/guava-tests/test/com/google/common/primitives/CharsTest.java +++ b/guava-tests/test/com/google/common/primitives/CharsTest.java @@ -435,6 +435,16 @@ public void testRotate_multiElementArray() { testRotate(new char[] {'1', '2', '3', '4', '5'}, 6, new char[] {'5', '1', '2', '3', '4'}); } + public void testRotate_minValueDistance() { + testRotate(new char[] {'1', '2', '3'}, Integer.MIN_VALUE, new char[] {'3', '1', '2'}); + testRotate( + new char[] {'0', '1', '2', '3', '4'}, + Integer.MIN_VALUE, + 1, + 4, + new char[] {'0', '3', '1', '2', '4'}); + } + public void testRotateIndexed_emptyRange() { char[] empty = {}; char[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/DoublesTest.java b/guava-tests/test/com/google/common/primitives/DoublesTest.java index d8879c2f8462..563f840e8bec 100644 --- a/guava-tests/test/com/google/common/primitives/DoublesTest.java +++ b/guava-tests/test/com/google/common/primitives/DoublesTest.java @@ -432,6 +432,16 @@ public void testRotate_multiElementArray() { testRotate(new double[] {1, 2, 3, 4, 5}, 6, new double[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new double[] {1, 2, 3}, Integer.MIN_VALUE, new double[] {3, 1, 2}); + testRotate( + new double[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new double[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { double[] empty = {}; double[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/FloatsTest.java b/guava-tests/test/com/google/common/primitives/FloatsTest.java index c9f8d858a2c5..2b637e862fab 100644 --- a/guava-tests/test/com/google/common/primitives/FloatsTest.java +++ b/guava-tests/test/com/google/common/primitives/FloatsTest.java @@ -425,6 +425,16 @@ public void testRotate_multiElementArray() { testRotate(new float[] {1, 2, 3, 4, 5}, 6, new float[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new float[] {1, 2, 3}, Integer.MIN_VALUE, new float[] {3, 1, 2}); + testRotate( + new float[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new float[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { float[] empty = {}; float[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/IntsTest.java b/guava-tests/test/com/google/common/primitives/IntsTest.java index 7a5b560e8053..5dfa8ebf8434 100644 --- a/guava-tests/test/com/google/common/primitives/IntsTest.java +++ b/guava-tests/test/com/google/common/primitives/IntsTest.java @@ -425,6 +425,16 @@ public void testRotate_multiElementArray() { testRotate(new int[] {1, 2, 3, 4, 5}, 6, new int[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new int[] {1, 2, 3}, Integer.MIN_VALUE, new int[] {3, 1, 2}); + testRotate( + new int[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new int[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { int[] empty = {}; int[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/LongsTest.java b/guava-tests/test/com/google/common/primitives/LongsTest.java index e05ae8b09338..0256196c72cd 100644 --- a/guava-tests/test/com/google/common/primitives/LongsTest.java +++ b/guava-tests/test/com/google/common/primitives/LongsTest.java @@ -418,6 +418,16 @@ public void testRotate_multiElementArray() { testRotate(new long[] {1, 2, 3, 4, 5}, 6, new long[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new long[] {1, 2, 3}, Integer.MIN_VALUE, new long[] {3, 1, 2}); + testRotate( + new long[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new long[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { long[] empty = {}; long[] expectedEmpty = {}; diff --git a/guava-tests/test/com/google/common/primitives/ShortsTest.java b/guava-tests/test/com/google/common/primitives/ShortsTest.java index 5d90d5323077..8fb7ece0da9b 100644 --- a/guava-tests/test/com/google/common/primitives/ShortsTest.java +++ b/guava-tests/test/com/google/common/primitives/ShortsTest.java @@ -448,6 +448,16 @@ public void testRotate_multiElementArray() { testRotate(new short[] {1, 2, 3, 4, 5}, 6, new short[] {5, 1, 2, 3, 4}); } + public void testRotate_minValueDistance() { + testRotate(new short[] {1, 2, 3}, Integer.MIN_VALUE, new short[] {3, 1, 2}); + testRotate( + new short[] {0, 1, 2, 3, 4}, + Integer.MIN_VALUE, + 1, + 4, + new short[] {0, 3, 1, 2, 4}); + } + public void testRotateIndexed_emptyRange() { short[] empty = {}; short[] expectedEmpty = {}; diff --git a/guava/src/com/google/common/primitives/Booleans.java b/guava/src/com/google/common/primitives/Booleans.java index 93d48c5b5be5..34c60caf117c 100644 --- a/guava/src/com/google/common/primitives/Booleans.java +++ b/guava/src/com/google/common/primitives/Booleans.java @@ -600,7 +600,7 @@ public static void rotate(boolean[] array, int distance, int fromIndex, int toIn // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Bytes.java b/guava/src/com/google/common/primitives/Bytes.java index c59e02a952a9..871bf8c03cc1 100644 --- a/guava/src/com/google/common/primitives/Bytes.java +++ b/guava/src/com/google/common/primitives/Bytes.java @@ -450,7 +450,7 @@ public static void rotate(byte[] array, int distance, int fromIndex, int toIndex // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Chars.java b/guava/src/com/google/common/primitives/Chars.java index 725789b787f8..7d3d05c08b86 100644 --- a/guava/src/com/google/common/primitives/Chars.java +++ b/guava/src/com/google/common/primitives/Chars.java @@ -541,7 +541,7 @@ public static void rotate(char[] array, int distance, int fromIndex, int toIndex // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Doubles.java b/guava/src/com/google/common/primitives/Doubles.java index b8376a520353..e4c25a643d52 100644 --- a/guava/src/com/google/common/primitives/Doubles.java +++ b/guava/src/com/google/common/primitives/Doubles.java @@ -524,7 +524,7 @@ public static void rotate(double[] array, int distance, int fromIndex, int toInd // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Floats.java b/guava/src/com/google/common/primitives/Floats.java index 1cfc20caf7e7..b50b4cabb229 100644 --- a/guava/src/com/google/common/primitives/Floats.java +++ b/guava/src/com/google/common/primitives/Floats.java @@ -521,7 +521,7 @@ public static void rotate(float[] array, int distance, int fromIndex, int toInde // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Ints.java b/guava/src/com/google/common/primitives/Ints.java index 45f3c93ebd17..fe3dbb90dd70 100644 --- a/guava/src/com/google/common/primitives/Ints.java +++ b/guava/src/com/google/common/primitives/Ints.java @@ -594,7 +594,7 @@ public static void rotate(int[] array, int distance, int fromIndex, int toIndex) // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Longs.java b/guava/src/com/google/common/primitives/Longs.java index 947a846f04fc..2ebe9ceecf05 100644 --- a/guava/src/com/google/common/primitives/Longs.java +++ b/guava/src/com/google/common/primitives/Longs.java @@ -652,7 +652,7 @@ public static void rotate(long[] array, int distance, int fromIndex, int toIndex // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex; diff --git a/guava/src/com/google/common/primitives/Shorts.java b/guava/src/com/google/common/primitives/Shorts.java index 751db46616e9..8cc3671eda52 100644 --- a/guava/src/com/google/common/primitives/Shorts.java +++ b/guava/src/com/google/common/primitives/Shorts.java @@ -562,7 +562,7 @@ public static void rotate(short[] array, int distance, int fromIndex, int toInde // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many // places left to rotate. - int m = -distance % length; + int m = -(distance % length); m = (m < 0) ? m + length : m; // The current index of what will become the first element of the rotated section. int newFirstIndex = m + fromIndex;