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 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
}
// 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 @@ private static String replaceEach(
// 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 static String[] stripAll(final String... strs) {
* @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 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
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 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
* @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 @@ static boolean failingBool() throws SomeException {
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 void test() throws Throwable {
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 long testAsLongPrimitive(final Throwable throwable) throws Throwable {
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 void testThrows_FailableBiConsumer_Object_Throwable() {
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 void testThrows_FailableBiConsumer_String_IOException() {
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 void testThrows_FailableBiFunction_Object_Throwable() {
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 void testThrows_FailableBiFunction_String_IOException() {
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 void testThrows_FailableBiPredicate_Object_Throwable() {
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 void testThrows_FailableBiPredicate_String_IOException() {
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 void testThrows_FailableConsumer_Object_Throwable() {
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 void testThrows_FailableConsumer_String_IOException() {
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 void testThrows_FailableFunction_Object_Throwable() {
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 void testThrows_FailableFunction_String_IOException() {
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 void testThrows_FailablePredicate_Object_Throwable() {
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 void testThrows_FailablePredicate_String_IOException() {
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 void testToRootUpperCase() {
@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 void testObject() {
@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 void testList() {
@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 void testArrayEnum() {
@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 List<Hobby> getHobbies() {
return hobbies;
}
public void setHobbies(List<Hobby> hobbies) {
public void setHobbies(final List<Hobby> hobbies) {
this.hobbies = hobbies;
}
@ -581,7 +581,7 @@ public Hobby[] getHobbies() {
return hobbies;
}
public void setHobbies(Hobby[] hobbies) {
public void setHobbies(final Hobby[] hobbies) {
this.hobbies = hobbies;
}
@ -595,11 +595,11 @@ static class AcademyClass {
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 void testWriteLock() throws Exception {
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 @@ private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeChec
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]) {