Make final var when is possible. (#816)

This commit is contained in:
Arturo Bernal 2021-11-17 14:31:50 +01:00 committed by GitHub
parent f75f5b9373
commit e299a185d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 72 additions and 40 deletions

View File

@ -517,6 +517,9 @@
<contributor> <contributor>
<name>Jin Xu</name> <name>Jin Xu</name>
</contributor> </contributor>
<contributor>
<name>Arturo Bernal</name>
</contributor>
</contributors> </contributors>
<dependencyManagement> <dependencyManagement>

View File

@ -764,7 +764,7 @@ public class ArrayUtils {
*/ */
@Deprecated @Deprecated
public static <T> T[] add(final T[] array, final int index, final T element) { public static <T> T[] add(final T[] array, final int index, final T element) {
Class<T> clss; final Class<T> clss;
if (array != null) { if (array != null) {
clss = getComponentType(array); clss = getComponentType(array);
} else if (element != null) { } else if (element != null) {

View File

@ -208,7 +208,7 @@ public class MethodUtils {
args = ArrayUtils.nullToEmpty(args); args = ArrayUtils.nullToEmpty(args);
final String messagePrefix; final String messagePrefix;
Method method; final Method method;
if (forceAccess) { if (forceAccess) {
messagePrefix = "No such method: "; messagePrefix = "No such method: ";

View File

@ -630,7 +630,7 @@ public class TypeUtils {
// find the interface closest to the super class // find the interface closest to the super class
for (final Type midType : interfaceTypes) { for (final Type midType : interfaceTypes) {
Class<?> midClass; final Class<?> midClass;
if (midType instanceof ParameterizedType) { if (midType instanceof ParameterizedType) {
midClass = getRawType((ParameterizedType) midType); midClass = getRawType((ParameterizedType) midType);

View File

@ -1129,8 +1129,8 @@ public class DateUtils {
if (focus == null) { if (focus == null) {
throw nullDateIllegalArgumentException(); throw nullDateIllegalArgumentException();
} }
Calendar start; final Calendar start;
Calendar end; final Calendar end;
int startCutoff = Calendar.SUNDAY; int startCutoff = Calendar.SUNDAY;
int endCutoff = Calendar.SATURDAY; int endCutoff = Calendar.SATURDAY;
switch (rangeStyle) { switch (rangeStyle) {

View File

@ -653,7 +653,7 @@ public class ArrayUtilsAddTest {
@Test @Test
public void testJira567() { public void testJira567() {
Number[] n; final Number[] n;
// Valid array construction // Valid array construction
n = ArrayUtils.addAll(new Number[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)}); n = ArrayUtils.addAll(new Number[]{Integer.valueOf(1)}, new Long[]{Long.valueOf(2)});
assertEquals(2, n.length); assertEquals(2, n.length);

View File

@ -2760,7 +2760,7 @@ public class StringUtilsTest {
// Match example in javadoc // Match example in javadoc
{ {
String[] results; final String[] results;
final String[] expectedResults = {"a", "", "b", "c"}; final String[] expectedResults = {"a", "", "b", "c"};
results = StringUtils.splitPreserveAllTokens("a..b.c", '.'); results = StringUtils.splitPreserveAllTokens("a..b.c", '.');
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2789,7 +2789,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "de fg"}; final String[] expectedResults = {"ab", "de fg"};
results = StringUtils.splitPreserveAllTokens("ab de fg", null, 2); results = StringUtils.splitPreserveAllTokens("ab de fg", null, 2);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2799,7 +2799,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", " de fg"}; final String[] expectedResults = {"ab", " de fg"};
results = StringUtils.splitPreserveAllTokens("ab de fg", null, 2); results = StringUtils.splitPreserveAllTokens("ab de fg", null, 2);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2809,7 +2809,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "::de:fg"}; final String[] expectedResults = {"ab", "::de:fg"};
results = StringUtils.splitPreserveAllTokens("ab:::de:fg", ":", 2); results = StringUtils.splitPreserveAllTokens("ab:::de:fg", ":", 2);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2819,7 +2819,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "", " de fg"}; final String[] expectedResults = {"ab", "", " de fg"};
results = StringUtils.splitPreserveAllTokens("ab de fg", null, 3); results = StringUtils.splitPreserveAllTokens("ab de fg", null, 3);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2829,7 +2829,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "", "", "de fg"}; final String[] expectedResults = {"ab", "", "", "de fg"};
results = StringUtils.splitPreserveAllTokens("ab de fg", null, 4); results = StringUtils.splitPreserveAllTokens("ab de fg", null, 4);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2840,7 +2840,7 @@ public class StringUtilsTest {
{ {
final String[] expectedResults = {"ab", "cd:ef"}; final String[] expectedResults = {"ab", "cd:ef"};
String[] results; final String[] results;
results = StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2); results = StringUtils.splitPreserveAllTokens("ab:cd:ef", ":", 2);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
for (int i = 0; i < expectedResults.length; i++) { for (int i = 0; i < expectedResults.length; i++) {
@ -2849,7 +2849,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", ":cd:ef"}; final String[] expectedResults = {"ab", ":cd:ef"};
results = StringUtils.splitPreserveAllTokens("ab::cd:ef", ":", 2); results = StringUtils.splitPreserveAllTokens("ab::cd:ef", ":", 2);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2859,7 +2859,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "", ":cd:ef"}; final String[] expectedResults = {"ab", "", ":cd:ef"};
results = StringUtils.splitPreserveAllTokens("ab:::cd:ef", ":", 3); results = StringUtils.splitPreserveAllTokens("ab:::cd:ef", ":", 3);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2869,7 +2869,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"ab", "", "", "cd:ef"}; final String[] expectedResults = {"ab", "", "", "cd:ef"};
results = StringUtils.splitPreserveAllTokens("ab:::cd:ef", ":", 4); results = StringUtils.splitPreserveAllTokens("ab:::cd:ef", ":", 4);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2879,7 +2879,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"", "ab", "", "", "cd:ef"}; final String[] expectedResults = {"", "ab", "", "", "cd:ef"};
results = StringUtils.splitPreserveAllTokens(":ab:::cd:ef", ":", 5); results = StringUtils.splitPreserveAllTokens(":ab:::cd:ef", ":", 5);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);
@ -2889,7 +2889,7 @@ public class StringUtilsTest {
} }
{ {
String[] results; final String[] results;
final String[] expectedResults = {"", "", "ab", "", "", "cd:ef"}; final String[] expectedResults = {"", "", "ab", "", "", "cd:ef"};
results = StringUtils.splitPreserveAllTokens("::ab:::cd:ef", ":", 6); results = StringUtils.splitPreserveAllTokens("::ab:::cd:ef", ":", 6);
assertEquals(expectedResults.length, results.length); assertEquals(expectedResults.length, results.length);

View File

@ -164,7 +164,7 @@ public class FractionTest {
@Test @Test
public void testCompareTo() { public void testCompareTo() {
Fraction f1; final Fraction f1;
Fraction f2; Fraction f2;
f1 = Fraction.getFraction(3, 5); f1 = Fraction.getFraction(3, 5);
@ -237,7 +237,7 @@ public class FractionTest {
@Test @Test
public void testConversions() { public void testConversions() {
Fraction f; final Fraction f;
f = Fraction.getFraction(3, 7, 8); f = Fraction.getFraction(3, 7, 8);
assertEquals(3, f.intValue()); assertEquals(3, f.intValue());

View File

@ -750,7 +750,7 @@ public class TypeUtilsTest<B> {
// int[] ina = ia; // int[] ina = ia;
assertFalse(TypeUtils.isAssignable(Integer[].class, int[].class)); assertFalse(TypeUtils.isAssignable(Integer[].class, int[].class));
final int[] ina = null; final int[] ina = null;
Object[] oa; final Object[] oa;
// oa = ina; // oa = ina;
assertFalse(TypeUtils.isAssignable(int[].class, Object[].class)); assertFalse(TypeUtils.isAssignable(int[].class, Object[].class));
oa = new Integer[0]; oa = new Integer[0];

View File

@ -80,7 +80,10 @@ public class DateUtilsRoundingTest {
assertEquals(roundedUpDate, DateUtils.round(firstRoundUpDate, calendarField)); assertEquals(roundedUpDate, DateUtils.round(firstRoundUpDate, calendarField));
//Calendar-initiations //Calendar-initiations
Calendar roundedUpCalendar, roundedDownCalendar, lastRoundDownCalendar, firstRoundUpCalendar; final Calendar roundedUpCalendar;
Calendar roundedDownCalendar;
Calendar lastRoundDownCalendar;
final Calendar firstRoundUpCalendar;
roundedDownCalendar = Calendar.getInstance(); roundedDownCalendar = Calendar.getInstance();
roundedUpCalendar = Calendar.getInstance(); roundedUpCalendar = Calendar.getInstance();
lastRoundDownCalendar = Calendar.getInstance(); lastRoundDownCalendar = Calendar.getInstance();
@ -127,7 +130,9 @@ public class DateUtilsRoundingTest {
assertNotEquals(truncatedDate, DateUtils.truncate(nextTruncateDate, calendarField), fdf.format(lastTruncateDate) + " is not an extreme when truncating as Date with CalendarField-value " + calendarField); assertNotEquals(truncatedDate, DateUtils.truncate(nextTruncateDate, calendarField), fdf.format(lastTruncateDate) + " is not an extreme when truncating as Date with CalendarField-value " + calendarField);
//Calendar-initiations //Calendar-initiations
Calendar truncatedCalendar, lastTruncateCalendar, nextTruncateCalendar; final Calendar truncatedCalendar;
Calendar lastTruncateCalendar;
final Calendar nextTruncateCalendar;
truncatedCalendar = Calendar.getInstance(); truncatedCalendar = Calendar.getInstance();
lastTruncateCalendar = Calendar.getInstance(); lastTruncateCalendar = Calendar.getInstance();
nextTruncateCalendar = Calendar.getInstance(); nextTruncateCalendar = Calendar.getInstance();
@ -217,7 +222,8 @@ public class DateUtilsRoundingTest {
public void testRoundAmPm() throws Exception { public void testRoundAmPm() throws Exception {
final int calendarField = Calendar.AM_PM; final int calendarField = Calendar.AM_PM;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
Date minDate, maxDate; final Date minDate;
final Date maxDate;
//AM //AM
roundedUpDate = dateTimeParser.parse("June 1, 2008 12:00:00.000"); roundedUpDate = dateTimeParser.parse("June 1, 2008 12:00:00.000");
@ -248,8 +254,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundDate() throws Exception { public void testRoundDate() throws Exception {
final int calendarField = Calendar.DATE; final int calendarField = Calendar.DATE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000"); roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000");
roundedDownDate = targetDateDate; roundedDownDate = targetDateDate;
@ -273,8 +282,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundDayOfMonth() throws Exception { public void testRoundDayOfMonth() throws Exception {
final int calendarField = Calendar.DAY_OF_MONTH; final int calendarField = Calendar.DAY_OF_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000"); roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000");
roundedDownDate = targetDayOfMonthDate; roundedDownDate = targetDayOfMonthDate;
@ -298,8 +310,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundHour() throws Exception { public void testRoundHour() throws Exception {
final int calendarField = Calendar.HOUR; final int calendarField = Calendar.HOUR;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 1, 2008 9:00:00.000"); roundedUpDate = dateTimeParser.parse("June 1, 2008 9:00:00.000");
roundedDownDate = targetHourDate; roundedDownDate = targetHourDate;
@ -323,8 +338,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundHourOfDay() throws Exception { public void testRoundHourOfDay() throws Exception {
final int calendarField = Calendar.HOUR_OF_DAY; final int calendarField = Calendar.HOUR_OF_DAY;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 1, 2008 9:00:00.000"); roundedUpDate = dateTimeParser.parse("June 1, 2008 9:00:00.000");
roundedDownDate = targetHourOfDayDate; roundedDownDate = targetHourOfDayDate;
@ -348,8 +366,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundMilliSecond() throws Exception { public void testRoundMilliSecond() throws Exception {
final int calendarField = Calendar.MILLISECOND; final int calendarField = Calendar.MILLISECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedDownDate = lastRoundedDownDate = targetMilliSecondDate; roundedDownDate = lastRoundedDownDate = targetMilliSecondDate;
roundedUpDate = dateTimeParser.parse("June 1, 2008 8:15:14.232"); roundedUpDate = dateTimeParser.parse("June 1, 2008 8:15:14.232");
@ -371,8 +392,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundMinute() throws Exception { public void testRoundMinute() throws Exception {
final int calendarField = Calendar.MINUTE; final int calendarField = Calendar.MINUTE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 1, 2008 8:16:00.000"); roundedUpDate = dateTimeParser.parse("June 1, 2008 8:16:00.000");
roundedDownDate = targetMinuteDate; roundedDownDate = targetMinuteDate;
@ -397,7 +421,8 @@ public class DateUtilsRoundingTest {
public void testRoundMonth() throws Exception { public void testRoundMonth() throws Exception {
final int calendarField = Calendar.MONTH; final int calendarField = Calendar.MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
Date minDate, maxDate; final Date minDate;
final Date maxDate;
//month with 28 days //month with 28 days
roundedUpDate = dateTimeParser.parse("March 1, 2007 0:00:00.000"); roundedUpDate = dateTimeParser.parse("March 1, 2007 0:00:00.000");
@ -440,8 +465,11 @@ public class DateUtilsRoundingTest {
@Test @Test
public void testRoundSecond() throws Exception { public void testRoundSecond() throws Exception {
final int calendarField = Calendar.SECOND; final int calendarField = Calendar.SECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; final Date roundedUpDate;
Date minDate, maxDate; final Date roundedDownDate;
final Date lastRoundedDownDate;
final Date minDate;
final Date maxDate;
roundedUpDate = dateTimeParser.parse("June 1, 2008 8:15:15.000"); roundedUpDate = dateTimeParser.parse("June 1, 2008 8:15:15.000");
roundedDownDate = targetSecondDate; roundedDownDate = targetSecondDate;
@ -466,7 +494,8 @@ public class DateUtilsRoundingTest {
public void testRoundSemiMonth() throws Exception { public void testRoundSemiMonth() throws Exception {
final int calendarField = DateUtils.SEMI_MONTH; final int calendarField = DateUtils.SEMI_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate; Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
Date minDate, maxDate; final Date minDate;
final Date maxDate;
//month with 28 days (1) //month with 28 days (1)
roundedUpDate = dateTimeParser.parse("February 16, 2007 0:00:00.000"); roundedUpDate = dateTimeParser.parse("February 16, 2007 0:00:00.000");