From 8e292eb96275560219f435bffcad107e96ba8603 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:01:15 +0800 Subject: [PATCH 01/17] Fix Booleans rotation for minimum integer distance --- guava/src/com/google/common/primitives/Booleans.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 86748dc6fdd2b78311406ff695e6ffd8651e2eb0 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:03:29 +0800 Subject: [PATCH 02/17] Fix modulus operation for negative distance --- guava/src/com/google/common/primitives/Bytes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From d85e249aa73db9895da3841aa8895c37a10c4f83 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:04:01 +0800 Subject: [PATCH 03/17] Fix calculation of rotation distance in Chars.java --- guava/src/com/google/common/primitives/Chars.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From a4ec047b35460798843836b1fb3854018b08be1b Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:04:18 +0800 Subject: [PATCH 04/17] Fix modulus operation for negative distance --- guava/src/com/google/common/primitives/Doubles.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From d9a87f7be0db6ed3b4a7a47ae4ca077138ae7638 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:04:35 +0800 Subject: [PATCH 05/17] Fix calculation of m for rotation distance --- guava/src/com/google/common/primitives/Floats.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 6cb36f689788fd11028032f778eae90aeef6d9cf Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:08:33 +0800 Subject: [PATCH 06/17] Fix modulus operation for negative distance --- guava/src/com/google/common/primitives/Ints.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From ad27b07500c57acb14eeff5b0ca4e64284cf35bb Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:08:59 +0800 Subject: [PATCH 07/17] Fix calculation of m for negative distance --- guava/src/com/google/common/primitives/Longs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 3c80c7e0a6ea2074a3dd078df7ae4d007922f985 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:09:20 +0800 Subject: [PATCH 08/17] Fix Shorts rotation for minimum integer distance --- guava/src/com/google/common/primitives/Shorts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From eb58d0b837eaee4eee561bac82bba1adc3c84612 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:09:54 +0800 Subject: [PATCH 09/17] Add test for rotate with minimum value distance --- .../com/google/common/primitives/BooleansTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guava-tests/test/com/google/common/primitives/BooleansTest.java b/guava-tests/test/com/google/common/primitives/BooleansTest.java index ac0f08979966..2f26c5cc935c 100644 --- a/guava-tests/test/com/google/common/primitives/BooleansTest.java +++ b/guava-tests/test/com/google/common/primitives/BooleansTest.java @@ -342,6 +342,16 @@ 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 = {}; From 5b42642ed17d3aa5ed131ea65212c6dd2faac07d Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:10:13 +0800 Subject: [PATCH 10/17] Add test for rotate with minimum value distance --- .../test/com/google/common/primitives/BytesTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From 6af7896b8a8249c89e2a578cf695de14b145b0e7 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:10:32 +0800 Subject: [PATCH 11/17] Add test for rotate with minimum value distance --- .../test/com/google/common/primitives/CharsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From b89b82410894703b81054269f4bd6ac583322892 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:12:47 +0800 Subject: [PATCH 12/17] Add test for rotate with minimum value distance --- .../test/com/google/common/primitives/DoublesTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From 1011215aa727079a5bf9cfdd5367fecc627638e7 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:13:09 +0800 Subject: [PATCH 13/17] Add testRotate_minValueDistance method Add test for rotating with minimum integer value distance. --- .../test/com/google/common/primitives/FloatsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From 14de0b005b9380ca8d63a7f0c7ca43208005474f Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:13:30 +0800 Subject: [PATCH 14/17] Add testRotate_minValueDistance method Add test for rotating array with minimum value distance. --- .../test/com/google/common/primitives/IntsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From 229bdb21871ff9213f165bcd44a0d21c3a0cea22 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:13:50 +0800 Subject: [PATCH 15/17] Add testRotate_minValueDistance method Add test for rotating with minimum integer value distance. --- .../test/com/google/common/primitives/LongsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From ce403f45805fe875a9feff5cb8ad5e80f502be24 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:14:13 +0800 Subject: [PATCH 16/17] Add testRotate_minValueDistance test case --- .../test/com/google/common/primitives/ShortsTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 = {}; From 5d12123691575b9129e8a9a5603144c1703e34f6 Mon Sep 17 00:00:00 2001 From: Kayokoi <113896798+wozhenbang2004@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:17:39 +0800 Subject: [PATCH 17/17] Fix formatting in testRotate_minValueDistance test --- .../test/com/google/common/primitives/BooleansTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guava-tests/test/com/google/common/primitives/BooleansTest.java b/guava-tests/test/com/google/common/primitives/BooleansTest.java index 2f26c5cc935c..3b561aae00c3 100644 --- a/guava-tests/test/com/google/common/primitives/BooleansTest.java +++ b/guava-tests/test/com/google/common/primitives/BooleansTest.java @@ -343,7 +343,10 @@ public void testRotate_multiElementArray() { } public void testRotate_minValueDistance() { - testRotate(new boolean[] {true, false, false}, Integer.MIN_VALUE, new boolean[] {false, true, false}); + 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,