Use final.

This commit is contained in:
Gary Gregory 2020-06-24 10:55:15 -04:00
parent c5c839ff82
commit cae8364d9e
7 changed files with 61 additions and 61 deletions

View File

@ -295,8 +295,8 @@ public class CharSequenceUtils {
}
// The real same check as in String.regionMatches():
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
final char u1 = Character.toUpperCase(c1);
final char u2 = Character.toUpperCase(c2);
if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) {
return false;
}

View File

@ -6693,8 +6693,8 @@ public class StringUtils {
// if recursing, this shouldn't be less than 0
if (timeToLive < 0) {
Set<String> searchSet = new HashSet<>(Arrays.asList(searchList));
Set<String> replacementSet = new HashSet<>(Arrays.asList(replacementList));
final Set<String> searchSet = new HashSet<>(Arrays.asList(searchList));
final Set<String> replacementSet = new HashSet<>(Arrays.asList(replacementList));
searchSet.retainAll(replacementSet);
if (searchSet.size() > 0) {
throw new IllegalStateException("Aborting to protect against StackOverflowError - " +
@ -8277,7 +8277,7 @@ public class StringUtils {
* @return the stripped Strings, {@code null} if null array input
*/
public static String[] stripAll(final String[] strs, final String stripChars) {
int strsLen = ArrayUtils.getLength(strs);
final int strsLen = ArrayUtils.getLength(strs);
if (strsLen == 0) {
return strs;
}

View File

@ -627,7 +627,7 @@ public abstract class ToStringStyle implements Serializable {
if (coll != null && !coll.isEmpty()) {
buffer.append(arrayStart);
int i = 0;
for (Object item : coll) {
for (final Object item : coll) {
appendDetail(buffer, fieldName, i++, item);
}
buffer.append(arrayEnd);
@ -944,7 +944,7 @@ public abstract class ToStringStyle implements Serializable {
* @param item the array item to add
* @since 3.11
*/
protected void appendDetail(final StringBuffer buffer, final String fieldName, int i, final Object item) {
protected void appendDetail(final StringBuffer buffer, final String fieldName, final int i, final Object item) {
if (i > 0) {
buffer.append(arraySeparator);
}

View File

@ -76,17 +76,17 @@ public class FunctionsTest {
return true;
}
static boolean testDouble(double value) throws SomeException {
static boolean testDouble(final double value) throws SomeException {
throwOnOdd();
return true;
}
static boolean testInt(int value) throws SomeException {
static boolean testInt(final int value) throws SomeException {
throwOnOdd();
return true;
}
static boolean testLong(long value) throws SomeException {
static boolean testLong(final long value) throws SomeException {
throwOnOdd();
return true;
}
@ -159,7 +159,7 @@ public class FunctionsTest {
test(throwable);
}
public Object test(Object input1, Object input2) throws Throwable {
public Object test(final Object input1, final Object input2) throws Throwable {
test(throwable);
return acceptedObject;
}
@ -225,41 +225,41 @@ public class FunctionsTest {
return 0;
}
public void testDouble(double i) throws Throwable {
public void testDouble(final double i) throws Throwable {
test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i);
}
public double testDoubleDouble(double i, double j) throws Throwable {
public double testDoubleDouble(final double i, final double j) throws Throwable {
test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i);
acceptedPrimitiveObject2 = (P) ((Double) j);
return 3d;
}
public void testInt(int i) throws Throwable {
public void testInt(final int i) throws Throwable {
test(throwable);
acceptedPrimitiveObject1 = (P) ((Integer) i);
}
public void testLong(long i) throws Throwable {
public void testLong(final long i) throws Throwable {
test(throwable);
acceptedPrimitiveObject1 = (P) ((Long) i);
}
public void testObjDouble(T object, double i) throws Throwable {
public void testObjDouble(final T object, final double i) throws Throwable {
test(throwable);
acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Double) i);
}
public void testObjInt(T object, int i) throws Throwable {
public void testObjInt(final T object, final int i) throws Throwable {
test(throwable);
acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Integer) i);
}
public void testObjLong(T object, long i) throws Throwable {
public void testObjLong(final T object, final long i) throws Throwable {
test(throwable);
acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Long) i);
@ -800,7 +800,7 @@ public class FunctionsTest {
new Functions.FailableBiConsumer<Object, Object, Throwable>() {
@Override
public void accept(Object object1, Object object2) throws Throwable {
public void accept(final Object object1, final Object object2) throws Throwable {
throw new IOException("test");
}
};
@ -815,7 +815,7 @@ public class FunctionsTest {
new Functions.FailableBiConsumer<String, String, IOException>() {
@Override
public void accept(String object1, String object2) throws IOException {
public void accept(final String object1, final String object2) throws IOException {
throw new IOException("test");
}
@ -831,7 +831,7 @@ public class FunctionsTest {
new Functions.FailableBiFunction<Object, Object, Object, Throwable>() {
@Override
public Object apply(Object input1, Object input2) throws Throwable {
public Object apply(final Object input1, final Object input2) throws Throwable {
throw new IOException("test");
}
};
@ -846,7 +846,7 @@ public class FunctionsTest {
new Functions.FailableBiFunction<String, String, String, IOException>() {
@Override
public String apply(String input1, String input2) throws IOException {
public String apply(final String input1, final String input2) throws IOException {
throw new IOException("test");
}
};
@ -861,7 +861,7 @@ public class FunctionsTest {
new Functions.FailableBiPredicate<Object, Object, Throwable>() {
@Override
public boolean test(Object object1, Object object2) throws Throwable {
public boolean test(final Object object1, final Object object2) throws Throwable {
throw new IOException("test");
}
};
@ -876,7 +876,7 @@ public class FunctionsTest {
new Functions.FailableBiPredicate<String, String, IOException>() {
@Override
public boolean test(String object1, String object2) throws IOException {
public boolean test(final String object1, final String object2) throws IOException {
throw new IOException("test");
}
};
@ -921,7 +921,7 @@ public class FunctionsTest {
new Functions.FailableConsumer<Object, Throwable>() {
@Override
public void accept(Object object) throws Throwable {
public void accept(final Object object) throws Throwable {
throw new IOException("test");
}
@ -937,7 +937,7 @@ public class FunctionsTest {
new Functions.FailableConsumer<String, IOException>() {
@Override
public void accept(String object) throws IOException {
public void accept(final String object) throws IOException {
throw new IOException("test");
}
@ -953,7 +953,7 @@ public class FunctionsTest {
new Functions.FailableFunction<Object, Object, Throwable>() {
@Override
public Object apply(Object input) throws Throwable {
public Object apply(final Object input) throws Throwable {
throw new IOException("test");
}
};
@ -968,7 +968,7 @@ public class FunctionsTest {
new Functions.FailableFunction<String, String, IOException>() {
@Override
public String apply(String input) throws IOException {
public String apply(final String input) throws IOException {
throw new IOException("test");
}
};
@ -983,7 +983,7 @@ public class FunctionsTest {
new Functions.FailablePredicate<Object, Throwable>() {
@Override
public boolean test(Object object) throws Throwable {
public boolean test(final Object object) throws Throwable {
throw new IOException("test");
}
};
@ -998,7 +998,7 @@ public class FunctionsTest {
new Functions.FailablePredicate<String, IOException>() {
@Override
public boolean test(String object) throws IOException {
public boolean test(final String object) throws IOException {
throw new IOException("test");
}
};

View File

@ -60,11 +60,11 @@ public class StringUtilsTest {
static final String NON_TRIMMABLE;
static {
StringBuilder ws = new StringBuilder();
StringBuilder nws = new StringBuilder();
final StringBuilder ws = new StringBuilder();
final StringBuilder nws = new StringBuilder();
final String hs = String.valueOf(((char) 160));
StringBuilder tr = new StringBuilder();
StringBuilder ntr = new StringBuilder();
final StringBuilder tr = new StringBuilder();
final StringBuilder ntr = new StringBuilder();
for (int i = 0; i < Character.MAX_VALUE; i++) {
if (Character.isWhitespace((char) i)) {
ws.append(String.valueOf((char) i));
@ -3310,25 +3310,25 @@ public class StringUtilsTest {
@Test
public void testGeorgianSample() {
char[] arrayI = new char[]{
final char[] arrayI = new char[]{
//Latin Small Letter dotless I
(char) 0x0131,
//Greek Capital Letter Theta
(char) 0x03F4
};
char[] arrayJ = new char[]{
final char[] arrayJ = new char[]{
//Latin Capital Letter I with dot above
(char) 0x0130,
//Greek Theta Symbol
(char) 0x03D1
};
for (char i : arrayI) {
for (char j : arrayJ) {
String si = String.valueOf(i);
String sj = String.valueOf(j);
boolean res1 = si.equalsIgnoreCase(sj);
CharSequence ci = new StringBuilder(si);
CharSequence cj = new StringBuilder(sj);
for (final char i : arrayI) {
for (final char j : arrayJ) {
final String si = String.valueOf(i);
final String sj = String.valueOf(j);
final boolean res1 = si.equalsIgnoreCase(sj);
final CharSequence ci = new StringBuilder(si);
final CharSequence cj = new StringBuilder(sj);
boolean res2 = StringUtils.startsWithIgnoreCase(ci, cj);
assertEquals(res1, res2, "si : " + si + " sj : " + sj);
res2 = StringUtils.endsWithIgnoreCase(ci, cj);

View File

@ -186,8 +186,8 @@ public class JsonToStringStyleTest {
@Test
public void testList() {
Student student = new Student();
ArrayList<Hobby> objects = new ArrayList<>();
final Student student = new Student();
final ArrayList<Hobby> objects = new ArrayList<>();
objects.add(Hobby.BOOK);
objects.add(Hobby.SPORT);
@ -204,8 +204,8 @@ public class JsonToStringStyleTest {
@Test
public void testArrayEnum() {
Teacher teacher = new Teacher();
Hobby[] hobbies = new Hobby[3];
final Teacher teacher = new Teacher();
final Hobby[] hobbies = new Hobby[3];
hobbies[0] = Hobby.BOOK;
hobbies[1] = Hobby.SPORT;
hobbies[2] = Hobby.MUSIC;
@ -221,30 +221,30 @@ public class JsonToStringStyleTest {
@Test
public void testCombineListAndEnum() {
Teacher teacher = new Teacher();
final Teacher teacher = new Teacher();
Hobby[] teacherHobbies = new Hobby[3];
final Hobby[] teacherHobbies = new Hobby[3];
teacherHobbies[0] = Hobby.BOOK;
teacherHobbies[1] = Hobby.SPORT;
teacherHobbies[2] = Hobby.MUSIC;
teacher.setHobbies(teacherHobbies);
Student john = new Student();
final Student john = new Student();
john.setHobbies(Arrays.asList(Hobby.BOOK, Hobby.MUSIC));
Student alice = new Student();
final Student alice = new Student();
alice.setHobbies(new ArrayList<>());
Student bob = new Student();
final Student bob = new Student();
bob.setHobbies(Collections.singletonList(Hobby.BOOK));
ArrayList<Student> students = new ArrayList<>();
final ArrayList<Student> students = new ArrayList<>();
students.add(john);
students.add(alice);
students.add(bob);
AcademyClass academyClass = new AcademyClass();
final AcademyClass academyClass = new AcademyClass();
academyClass.setStudents(students);
academyClass.setTeacher(teacher);
@ -564,7 +564,7 @@ public class JsonToStringStyleTest {
return hobbies;
}
public void setHobbies(List<Hobby> hobbies) {
public void setHobbies(final List<Hobby> hobbies) {
this.hobbies = hobbies;
}
@ -581,7 +581,7 @@ public class JsonToStringStyleTest {
return hobbies;
}
public void setHobbies(Hobby[] hobbies) {
public void setHobbies(final Hobby[] hobbies) {
this.hobbies = hobbies;
}
@ -595,11 +595,11 @@ public class JsonToStringStyleTest {
Teacher teacher;
List<Student> students;
public void setTeacher(Teacher teacher) {
public void setTeacher(final Teacher teacher) {
this.teacher = teacher;
}
public void setStudents(List<Student> students) {
public void setStudents(final List<Student> students) {
this.students = students;
}

View File

@ -44,7 +44,7 @@ public class LocksTest {
runTest(DELAY, true, l -> assertTrue(l >= NUMBER_OF_THREADS*DELAY));
}
private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeCheck) throws InterruptedException {
private void runTest(final long delay, final boolean exclusiveLock, final LongConsumer runTimeCheck) throws InterruptedException {
final boolean[] booleanValues = new boolean[10];
final Lock<boolean[]> lock = Locks.lock(booleanValues);
final boolean[] runningValues = new boolean[10];
@ -78,13 +78,13 @@ public class LocksTest {
runTimeCheck.accept(endTime-startTime);
}
protected void modify(boolean[] booleanArray, int offset, boolean value) {
protected void modify(final boolean[] booleanArray, final int offset, final boolean value) {
synchronized(booleanArray) {
booleanArray[offset] = value;
}
}
protected boolean someValueIsTrue(boolean[] booleanArray) {
protected boolean someValueIsTrue(final boolean[] booleanArray) {
synchronized(booleanArray) {
for (int i = 0; i < booleanArray.length; i++) {
if (booleanArray[i]) {