You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/09 21:50:37 UTC

(commons-lang) 11/16: Add Checkstyle MultipleVariableDeclarations

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 44dd43eb5c7a41350d0947080a9d16e65b7581d7
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 9 16:39:26 2025 -0500

    Add Checkstyle MultipleVariableDeclarations
---
 .../org/apache/commons/lang3/math/Fraction.java    |  3 +-
 src/site/resources/checkstyle/checkstyle.xml       |  3 +-
 .../lang3/StringUtilsEqualsIndexOfTest.java        |  4 +-
 .../commons/lang3/time/DateUtilsRoundingTest.java  | 55 +++++++++-------------
 .../commons/lang3/util/FluentBitSetTest.java       |  7 ++-
 5 files changed, 33 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/math/Fraction.java b/src/main/java/org/apache/commons/lang3/math/Fraction.java
index 414069e9e..0f608b59e 100644
--- a/src/main/java/org/apache/commons/lang3/math/Fraction.java
+++ b/src/main/java/org/apache/commons/lang3/math/Fraction.java
@@ -141,7 +141,8 @@ public static Fraction getFraction(double value) {
         double x2;
         double y1 = value - a1;
         double y2;
-        double delta1, delta2 = Double.MAX_VALUE;
+        double delta1;
+        double delta2 = Double.MAX_VALUE;
         double fraction;
         int i = 1;
         do {
diff --git a/src/site/resources/checkstyle/checkstyle.xml b/src/site/resources/checkstyle/checkstyle.xml
index 068e467aa..361f54832 100644
--- a/src/site/resources/checkstyle/checkstyle.xml
+++ b/src/site/resources/checkstyle/checkstyle.xml
@@ -65,8 +65,9 @@ limitations under the License.
       <property name="accessModifiers" value="public" />
     </module>
     <module name="LeftCurly"/>
-    <module name="ModifierOrder"/>
     <module name="MissingOverride"/>
+    <module name="ModifierOrder"/>
+    <module name="MultipleVariableDeclarations" />
     <module name="NeedBraces"/>
     <module name="NoWhitespaceBefore"/>
     <module name="ParenPad"/>
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index 583146af1..514deee94 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -195,7 +195,9 @@ public void testCustomCharSequence() {
 
     @Test
     public void testEquals() {
-        final CharSequence fooCs = new StringBuilder(FOO), barCs = new StringBuilder(BAR), foobarCs = new StringBuilder(FOOBAR);
+        final CharSequence fooCs = new StringBuilder(FOO);
+        final CharSequence barCs = new StringBuilder(BAR);
+        final CharSequence foobarCs = new StringBuilder(FOOBAR);
         assertTrue(StringUtils.equals(null, null));
         assertTrue(StringUtils.equals(fooCs, fooCs));
         assertTrue(StringUtils.equals(fooCs, new StringBuilder(FOO)));
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
index 750e409ed..dd838ebd0 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
@@ -46,8 +46,12 @@ public class DateUtilsRoundingTest extends AbstractLangTest {
     Date januaryOneDate;
     Date targetYearDate;
     //No targetMonths, these must be tested for every type of month(28-31 days)
-    Date targetDateDate, targetDayOfMonthDate, targetAmDate, targetPmDate;
-    Date targetHourOfDayDate, targetHourDate;
+    Date targetDateDate;
+    Date targetDayOfMonthDate;
+    Date targetAmDate;
+    Date targetPmDate;
+    Date targetHourOfDayDate;
+    Date targetHourDate;
     Date targetMinuteDate;
     Date targetSecondDate;
     Date targetMilliSecondDate;
@@ -229,14 +233,10 @@ public void setUp() throws Exception {
     @Test
     public void testRoundAmPm() throws Exception {
         final int calendarField = Calendar.AM_PM;
-        Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
-        final Date minDate;
-        final Date maxDate;
-
         // AM
-        roundedUpDate = dateTimeParser.parse("June 1, 2008 12:00:00.000");
-        roundedDownDate = targetAmDate;
-        lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 5:59:59.999");
+        Date roundedUpDate = dateTimeParser.parse("June 1, 2008 12:00:00.000");
+        Date roundedDownDate = targetAmDate;
+        Date lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 5:59:59.999");
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // PM
@@ -246,8 +246,8 @@ public void testRoundAmPm() throws Exception {
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // round to January 1
-        minDate = dateTimeParser.parse("December 31, 2007 18:00:00.000");
-        maxDate = dateTimeParser.parse("January 1, 2008 5:59:59.999");
+        final Date minDate = dateTimeParser.parse("December 31, 2007 18:00:00.000");
+        final Date maxDate = dateTimeParser.parse("January 1, 2008 5:59:59.999");
         roundToJanuaryFirst(minDate, maxDate, calendarField);
     }
 
@@ -421,14 +421,11 @@ public void testRoundMinute() throws Exception {
     @Test
     public void testRoundMonth() throws Exception {
         final int calendarField = Calendar.MONTH;
-        Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
-        final Date minDate;
-        final Date maxDate;
 
         // month with 28 days
-        roundedUpDate = dateTimeParser.parse("March 1, 2007 0:00:00.000");
-        roundedDownDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
-        lastRoundedDownDate = dateTimeParser.parse("February 14, 2007 23:59:59.999");
+        Date roundedUpDate = dateTimeParser.parse("March 1, 2007 0:00:00.000");
+        Date roundedDownDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
+        Date lastRoundedDownDate = dateTimeParser.parse("February 14, 2007 23:59:59.999");
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // month with 29 days
@@ -450,8 +447,8 @@ public void testRoundMonth() throws Exception {
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // round to January 1
-        minDate = dateTimeParser.parse("December 17, 2007 00:00:00.000");
-        maxDate = dateTimeParser.parse("January 16, 2008 23:59:59.999");
+        final Date minDate = dateTimeParser.parse("December 17, 2007 00:00:00.000");
+        final Date maxDate = dateTimeParser.parse("January 16, 2008 23:59:59.999");
         roundToJanuaryFirst(minDate, maxDate, calendarField);
     }
 
@@ -492,14 +489,10 @@ public void testRoundSecond() throws Exception {
     @Test
     public void testRoundSemiMonth() throws Exception {
         final int calendarField = DateUtils.SEMI_MONTH;
-        Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
-        final Date minDate;
-        final Date maxDate;
-
         // month with 28 days (1)
-        roundedUpDate = dateTimeParser.parse("February 16, 2007 0:00:00.000");
-        roundedDownDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
-        lastRoundedDownDate = dateTimeParser.parse("February 8, 2007 23:59:59.999");
+        Date roundedUpDate = dateTimeParser.parse("February 16, 2007 0:00:00.000");
+        Date roundedDownDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
+        Date lastRoundedDownDate = dateTimeParser.parse("February 8, 2007 23:59:59.999");
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // month with 28 days (2)
@@ -545,8 +538,8 @@ public void testRoundSemiMonth() throws Exception {
         baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate, calendarField);
 
         // round to January 1
-        minDate = dateTimeParser.parse("December 24, 2007 00:00:00.000");
-        maxDate = dateTimeParser.parse("January 8, 2008 23:59:59.999");
+        final Date minDate = dateTimeParser.parse("December 24, 2007 00:00:00.000");
+        final Date maxDate = dateTimeParser.parse("January 8, 2008 23:59:59.999");
         roundToJanuaryFirst(minDate, maxDate, calendarField);
     }
 
@@ -684,11 +677,9 @@ public void testTruncateSecond() throws Exception {
     @Test
     public void testTruncateSemiMonth() throws Exception {
         final int calendarField = DateUtils.SEMI_MONTH;
-        Date truncatedDate, lastTruncateDate;
-
         // month with 28 days (1)
-        truncatedDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
-        lastTruncateDate = dateTimeParser.parse("February 15, 2007 23:59:59.999");
+        Date truncatedDate = dateTimeParser.parse("February 1, 2007 0:00:00.000");
+        Date lastTruncateDate = dateTimeParser.parse("February 15, 2007 23:59:59.999");
         baseTruncateTest(truncatedDate, lastTruncateDate, calendarField);
 
         // month with 28 days (2)
diff --git a/src/test/java/org/apache/commons/lang3/util/FluentBitSetTest.java b/src/test/java/org/apache/commons/lang3/util/FluentBitSetTest.java
index 6f3699023..ef1c10983 100644
--- a/src/test/java/org/apache/commons/lang3/util/FluentBitSetTest.java
+++ b/src/test/java/org/apache/commons/lang3/util/FluentBitSetTest.java
@@ -801,8 +801,7 @@ public void test_getII() {
         bitset.get(3, 3);
 
         // Test for method boolean java.util.BitSet.get(int, int)
-        FluentBitSet bs, resultbs, correctbs;
-        bs = newInstance(512);
+        FluentBitSet bs = newInstance(512);
         bs.set(3, 9);
         bs.set(10, 20);
         bs.set(60, 75);
@@ -810,8 +809,8 @@ public void test_getII() {
         bs.set(130, 140);
 
         // pos1 and pos2 are in the same bitset element, at index0
-        resultbs = bs.get(3, 6);
-        correctbs = newInstance(3);
+        FluentBitSet resultbs = bs.get(3, 6);
+        FluentBitSet correctbs = newInstance(3);
         correctbs.set(0, 3);
         assertEquals(correctbs, resultbs, "Test1: Returned incorrect BitSet");