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(): // The real same check as in String.regionMatches():
char u1 = Character.toUpperCase(c1); final char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2); final char u2 = Character.toUpperCase(c2);
if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) { if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) {
return false; return false;
} }

View File

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

View File

@ -627,7 +627,7 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
if (coll != null && !coll.isEmpty()) { if (coll != null && !coll.isEmpty()) {
buffer.append(arrayStart); buffer.append(arrayStart);
int i = 0; int i = 0;
for (Object item : coll) { for (final Object item : coll) {
appendDetail(buffer, fieldName, i++, item); appendDetail(buffer, fieldName, i++, item);
} }
buffer.append(arrayEnd); buffer.append(arrayEnd);
@ -944,7 +944,7 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
* @param item the array item to add * @param item the array item to add
* @since 3.11 * @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) { if (i > 0) {
buffer.append(arraySeparator); buffer.append(arraySeparator);
} }

View File

@ -76,17 +76,17 @@ static boolean failingBool() throws SomeException {
return true; return true;
} }
static boolean testDouble(double value) throws SomeException { static boolean testDouble(final double value) throws SomeException {
throwOnOdd(); throwOnOdd();
return true; return true;
} }
static boolean testInt(int value) throws SomeException { static boolean testInt(final int value) throws SomeException {
throwOnOdd(); throwOnOdd();
return true; return true;
} }
static boolean testLong(long value) throws SomeException { static boolean testLong(final long value) throws SomeException {
throwOnOdd(); throwOnOdd();
return true; return true;
} }
@ -159,7 +159,7 @@ public void test() throws Throwable {
test(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); test(throwable);
return acceptedObject; return acceptedObject;
} }
@ -225,41 +225,41 @@ public long testAsLongPrimitive(final Throwable throwable) throws Throwable {
return 0; return 0;
} }
public void testDouble(double i) throws Throwable { public void testDouble(final double i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i); 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); test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i); acceptedPrimitiveObject1 = (P) ((Double) i);
acceptedPrimitiveObject2 = (P) ((Double) j); acceptedPrimitiveObject2 = (P) ((Double) j);
return 3d; return 3d;
} }
public void testInt(int i) throws Throwable { public void testInt(final int i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Integer) i); acceptedPrimitiveObject1 = (P) ((Integer) i);
} }
public void testLong(long i) throws Throwable { public void testLong(final long i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Long) i); 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); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Double) i); 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); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Integer) i); 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); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Long) i); acceptedPrimitiveObject1 = (P) ((Long) i);
@ -800,7 +800,7 @@ public void testThrows_FailableBiConsumer_Object_Throwable() {
new Functions.FailableBiConsumer<Object, Object, Throwable>() { new Functions.FailableBiConsumer<Object, Object, Throwable>() {
@Override @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"); throw new IOException("test");
} }
}; };
@ -815,7 +815,7 @@ public void testThrows_FailableBiConsumer_String_IOException() {
new Functions.FailableBiConsumer<String, String, IOException>() { new Functions.FailableBiConsumer<String, String, IOException>() {
@Override @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"); throw new IOException("test");
} }
@ -831,7 +831,7 @@ public void testThrows_FailableBiFunction_Object_Throwable() {
new Functions.FailableBiFunction<Object, Object, Object, Throwable>() { new Functions.FailableBiFunction<Object, Object, Object, Throwable>() {
@Override @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"); throw new IOException("test");
} }
}; };
@ -846,7 +846,7 @@ public void testThrows_FailableBiFunction_String_IOException() {
new Functions.FailableBiFunction<String, String, String, IOException>() { new Functions.FailableBiFunction<String, String, String, IOException>() {
@Override @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"); throw new IOException("test");
} }
}; };
@ -861,7 +861,7 @@ public void testThrows_FailableBiPredicate_Object_Throwable() {
new Functions.FailableBiPredicate<Object, Object, Throwable>() { new Functions.FailableBiPredicate<Object, Object, Throwable>() {
@Override @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"); throw new IOException("test");
} }
}; };
@ -876,7 +876,7 @@ public void testThrows_FailableBiPredicate_String_IOException() {
new Functions.FailableBiPredicate<String, String, IOException>() { new Functions.FailableBiPredicate<String, String, IOException>() {
@Override @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"); throw new IOException("test");
} }
}; };
@ -921,7 +921,7 @@ public void testThrows_FailableConsumer_Object_Throwable() {
new Functions.FailableConsumer<Object, Throwable>() { new Functions.FailableConsumer<Object, Throwable>() {
@Override @Override
public void accept(Object object) throws Throwable { public void accept(final Object object) throws Throwable {
throw new IOException("test"); throw new IOException("test");
} }
@ -937,7 +937,7 @@ public void testThrows_FailableConsumer_String_IOException() {
new Functions.FailableConsumer<String, IOException>() { new Functions.FailableConsumer<String, IOException>() {
@Override @Override
public void accept(String object) throws IOException { public void accept(final String object) throws IOException {
throw new IOException("test"); throw new IOException("test");
} }
@ -953,7 +953,7 @@ public void testThrows_FailableFunction_Object_Throwable() {
new Functions.FailableFunction<Object, Object, Throwable>() { new Functions.FailableFunction<Object, Object, Throwable>() {
@Override @Override
public Object apply(Object input) throws Throwable { public Object apply(final Object input) throws Throwable {
throw new IOException("test"); throw new IOException("test");
} }
}; };
@ -968,7 +968,7 @@ public void testThrows_FailableFunction_String_IOException() {
new Functions.FailableFunction<String, String, IOException>() { new Functions.FailableFunction<String, String, IOException>() {
@Override @Override
public String apply(String input) throws IOException { public String apply(final String input) throws IOException {
throw new IOException("test"); throw new IOException("test");
} }
}; };
@ -983,7 +983,7 @@ public void testThrows_FailablePredicate_Object_Throwable() {
new Functions.FailablePredicate<Object, Throwable>() { new Functions.FailablePredicate<Object, Throwable>() {
@Override @Override
public boolean test(Object object) throws Throwable { public boolean test(final Object object) throws Throwable {
throw new IOException("test"); throw new IOException("test");
} }
}; };
@ -998,7 +998,7 @@ public void testThrows_FailablePredicate_String_IOException() {
new Functions.FailablePredicate<String, IOException>() { new Functions.FailablePredicate<String, IOException>() {
@Override @Override
public boolean test(String object) throws IOException { public boolean test(final String object) throws IOException {
throw new IOException("test"); throw new IOException("test");
} }
}; };

View File

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

View File

@ -186,8 +186,8 @@ public void testObject() {
@Test @Test
public void testList() { public void testList() {
Student student = new Student(); final Student student = new Student();
ArrayList<Hobby> objects = new ArrayList<>(); final ArrayList<Hobby> objects = new ArrayList<>();
objects.add(Hobby.BOOK); objects.add(Hobby.BOOK);
objects.add(Hobby.SPORT); objects.add(Hobby.SPORT);
@ -204,8 +204,8 @@ public void testList() {
@Test @Test
public void testArrayEnum() { public void testArrayEnum() {
Teacher teacher = new Teacher(); final Teacher teacher = new Teacher();
Hobby[] hobbies = new Hobby[3]; final Hobby[] hobbies = new Hobby[3];
hobbies[0] = Hobby.BOOK; hobbies[0] = Hobby.BOOK;
hobbies[1] = Hobby.SPORT; hobbies[1] = Hobby.SPORT;
hobbies[2] = Hobby.MUSIC; hobbies[2] = Hobby.MUSIC;
@ -221,30 +221,30 @@ public void testArrayEnum() {
@Test @Test
public void testCombineListAndEnum() { 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[0] = Hobby.BOOK;
teacherHobbies[1] = Hobby.SPORT; teacherHobbies[1] = Hobby.SPORT;
teacherHobbies[2] = Hobby.MUSIC; teacherHobbies[2] = Hobby.MUSIC;
teacher.setHobbies(teacherHobbies); teacher.setHobbies(teacherHobbies);
Student john = new Student(); final Student john = new Student();
john.setHobbies(Arrays.asList(Hobby.BOOK, Hobby.MUSIC)); john.setHobbies(Arrays.asList(Hobby.BOOK, Hobby.MUSIC));
Student alice = new Student(); final Student alice = new Student();
alice.setHobbies(new ArrayList<>()); alice.setHobbies(new ArrayList<>());
Student bob = new Student(); final Student bob = new Student();
bob.setHobbies(Collections.singletonList(Hobby.BOOK)); bob.setHobbies(Collections.singletonList(Hobby.BOOK));
ArrayList<Student> students = new ArrayList<>(); final ArrayList<Student> students = new ArrayList<>();
students.add(john); students.add(john);
students.add(alice); students.add(alice);
students.add(bob); students.add(bob);
AcademyClass academyClass = new AcademyClass(); final AcademyClass academyClass = new AcademyClass();
academyClass.setStudents(students); academyClass.setStudents(students);
academyClass.setTeacher(teacher); academyClass.setTeacher(teacher);
@ -564,7 +564,7 @@ public List<Hobby> getHobbies() {
return hobbies; return hobbies;
} }
public void setHobbies(List<Hobby> hobbies) { public void setHobbies(final List<Hobby> hobbies) {
this.hobbies = hobbies; this.hobbies = hobbies;
} }
@ -581,7 +581,7 @@ public Hobby[] getHobbies() {
return hobbies; return hobbies;
} }
public void setHobbies(Hobby[] hobbies) { public void setHobbies(final Hobby[] hobbies) {
this.hobbies = hobbies; this.hobbies = hobbies;
} }
@ -595,11 +595,11 @@ static class AcademyClass {
Teacher teacher; Teacher teacher;
List<Student> students; List<Student> students;
public void setTeacher(Teacher teacher) { public void setTeacher(final Teacher teacher) {
this.teacher = teacher; this.teacher = teacher;
} }
public void setStudents(List<Student> students) { public void setStudents(final List<Student> students) {
this.students = 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)); 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 boolean[] booleanValues = new boolean[10];
final Lock<boolean[]> lock = Locks.lock(booleanValues); final Lock<boolean[]> lock = Locks.lock(booleanValues);
final boolean[] runningValues = new boolean[10]; final boolean[] runningValues = new boolean[10];
@ -78,13 +78,13 @@ private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeChec
runTimeCheck.accept(endTime-startTime); 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) { synchronized(booleanArray) {
booleanArray[offset] = value; booleanArray[offset] = value;
} }
} }
protected boolean someValueIsTrue(boolean[] booleanArray) { protected boolean someValueIsTrue(final boolean[] booleanArray) {
synchronized(booleanArray) { synchronized(booleanArray) {
for (int i = 0; i < booleanArray.length; i++) { for (int i = 0; i < booleanArray.length; i++) {
if (booleanArray[i]) { if (booleanArray[i]) {