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>
<name>Jin Xu</name>
</contributor>
<contributor>
<name>Arturo Bernal</name>
</contributor>
</contributors>
<dependencyManagement>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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