Add final modifier to local variables.
This commit is contained in:
parent
0f87dceb80
commit
c9a5e54a7c
|
@ -6632,7 +6632,7 @@ public class StringUtils {
|
|||
return str;
|
||||
}
|
||||
|
||||
int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
int outOffset = 0;
|
||||
newCodePoints[outOffset++] = newCodePoint; // copy the first codepoint
|
||||
for (int inOffset = Character.charCount(firstCodepoint); inOffset < strLen; ) {
|
||||
|
@ -6677,7 +6677,7 @@ public class StringUtils {
|
|||
return str;
|
||||
}
|
||||
|
||||
int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
int outOffset = 0;
|
||||
newCodePoints[outOffset++] = newCodePoint; // copy the first codepoint
|
||||
for (int inOffset = Character.charCount(firstCodepoint); inOffset < strLen; ) {
|
||||
|
@ -6721,7 +6721,7 @@ public class StringUtils {
|
|||
}
|
||||
|
||||
final int strLen = str.length();
|
||||
int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
final int newCodePoints[] = new int[strLen]; // cannot be longer than the char array
|
||||
int outOffset = 0;
|
||||
for (int i = 0; i < strLen; ) {
|
||||
final int oldCodepoint = str.codePointAt(i);
|
||||
|
@ -8171,13 +8171,13 @@ public class StringUtils {
|
|||
throw new IllegalArgumentException("Strings must not be null");
|
||||
}
|
||||
|
||||
int[] mtp = matches(first, second);
|
||||
double m = mtp[0];
|
||||
final int[] mtp = matches(first, second);
|
||||
final double m = mtp[0];
|
||||
if (m == 0) {
|
||||
return 0D;
|
||||
}
|
||||
double j = ((m / first.length() + m / second.length() + (m - mtp[1]) / m)) / 3;
|
||||
double jw = j < 0.7D ? j : j + Math.min(DEFAULT_SCALING_FACTOR, 1D / mtp[3]) * mtp[2] * (1D - j);
|
||||
final double j = ((m / first.length() + m / second.length() + (m - mtp[1]) / m)) / 3;
|
||||
final double jw = j < 0.7D ? j : j + Math.min(DEFAULT_SCALING_FACTOR, 1D / mtp[3]) * mtp[2] * (1D - j);
|
||||
return Math.round(jw * 100.0D) / 100.0D;
|
||||
}
|
||||
|
||||
|
@ -9033,9 +9033,9 @@ public class StringUtils {
|
|||
}
|
||||
|
||||
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
|
||||
int startIndex = str.indexOf(wrapToken);
|
||||
int endIndex = str.lastIndexOf(wrapToken);
|
||||
int wrapLength = wrapToken.length();
|
||||
final int startIndex = str.indexOf(wrapToken);
|
||||
final int endIndex = str.lastIndexOf(wrapToken);
|
||||
final int wrapLength = wrapToken.length();
|
||||
if (startIndex != -1 && endIndex != -1) {
|
||||
return str.substring(startIndex + wrapLength, endIndex);
|
||||
}
|
||||
|
@ -9074,8 +9074,8 @@ public class StringUtils {
|
|||
}
|
||||
|
||||
if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) {
|
||||
int startIndex = 0;
|
||||
int endIndex = str.length() - 1;
|
||||
final int startIndex = 0;
|
||||
final int endIndex = str.length() - 1;
|
||||
if (startIndex != -1 && endIndex != -1) {
|
||||
return str.substring(startIndex + 1, endIndex);
|
||||
}
|
||||
|
|
|
@ -115,14 +115,14 @@ public class Memoizer<I, O> implements Computable<I, O> {
|
|||
while (true) {
|
||||
Future<O> future = cache.get(arg);
|
||||
if (future == null) {
|
||||
Callable<O> eval = new Callable<O>() {
|
||||
final Callable<O> eval = new Callable<O>() {
|
||||
|
||||
@Override
|
||||
public O call() throws InterruptedException {
|
||||
return computable.compute(arg);
|
||||
}
|
||||
};
|
||||
FutureTask<O> futureTask = new FutureTask<>(eval);
|
||||
final FutureTask<O> futureTask = new FutureTask<>(eval);
|
||||
future = cache.putIfAbsent(arg, futureTask);
|
||||
if (future == null) {
|
||||
future = futureTask;
|
||||
|
@ -131,9 +131,9 @@ public class Memoizer<I, O> implements Computable<I, O> {
|
|||
}
|
||||
try {
|
||||
return future.get();
|
||||
} catch (CancellationException e) {
|
||||
} catch (final CancellationException e) {
|
||||
cache.remove(arg, future);
|
||||
} catch (ExecutionException e) {
|
||||
} catch (final ExecutionException e) {
|
||||
if (recalculate) {
|
||||
cache.remove(arg, future);
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public class MemoizerTest {
|
|||
|
||||
@Test
|
||||
public void testOnlyCallComputableOnceIfDoesNotThrowException() throws Exception {
|
||||
Integer input = 1;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
final Integer input = 1;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
expect(computable.compute(input)).andReturn(input);
|
||||
replay(computable);
|
||||
|
||||
|
@ -45,16 +45,16 @@ public class MemoizerTest {
|
|||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testDefaultBehaviourNotToRecalculateExecutionExceptions() throws Exception {
|
||||
Integer input = 1;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
InterruptedException interruptedException = new InterruptedException();
|
||||
final Integer input = 1;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
final InterruptedException interruptedException = new InterruptedException();
|
||||
expect(computable.compute(input)).andThrow(interruptedException);
|
||||
replay(computable);
|
||||
|
||||
try {
|
||||
memoizer.compute(input);
|
||||
fail("Expected Throwable to be thrown!");
|
||||
} catch (Throwable expected) {
|
||||
} catch (final Throwable expected) {
|
||||
// Should always be thrown the first time
|
||||
}
|
||||
|
||||
|
@ -63,16 +63,16 @@ public class MemoizerTest {
|
|||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testDoesNotRecalculateWhenSetToFalse() throws Exception {
|
||||
Integer input = 1;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable, false);
|
||||
InterruptedException interruptedException = new InterruptedException();
|
||||
final Integer input = 1;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable, false);
|
||||
final InterruptedException interruptedException = new InterruptedException();
|
||||
expect(computable.compute(input)).andThrow(interruptedException);
|
||||
replay(computable);
|
||||
|
||||
try {
|
||||
memoizer.compute(input);
|
||||
fail("Expected Throwable to be thrown!");
|
||||
} catch (Throwable expected) {
|
||||
} catch (final Throwable expected) {
|
||||
// Should always be thrown the first time
|
||||
}
|
||||
|
||||
|
@ -81,17 +81,17 @@ public class MemoizerTest {
|
|||
|
||||
@Test
|
||||
public void testDoesRecalculateWhenSetToTrue() throws Exception {
|
||||
Integer input = 1;
|
||||
Integer answer = 3;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable, true);
|
||||
InterruptedException interruptedException = new InterruptedException();
|
||||
final Integer input = 1;
|
||||
final Integer answer = 3;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable, true);
|
||||
final InterruptedException interruptedException = new InterruptedException();
|
||||
expect(computable.compute(input)).andThrow(interruptedException).andReturn(answer);
|
||||
replay(computable);
|
||||
|
||||
try {
|
||||
memoizer.compute(input);
|
||||
fail("Expected Throwable to be thrown!");
|
||||
} catch (Throwable expected) {
|
||||
} catch (final Throwable expected) {
|
||||
// Should always be thrown the first time
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,9 @@ public class MemoizerTest {
|
|||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testWhenComputableThrowsRuntimeException() throws Exception {
|
||||
Integer input = 1;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
RuntimeException runtimeException = new RuntimeException("Some runtime exception");
|
||||
final Integer input = 1;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
final RuntimeException runtimeException = new RuntimeException("Some runtime exception");
|
||||
expect(computable.compute(input)).andThrow(runtimeException);
|
||||
replay(computable);
|
||||
|
||||
|
@ -111,9 +111,9 @@ public class MemoizerTest {
|
|||
|
||||
@Test(expected = Error.class)
|
||||
public void testWhenComputableThrowsError() throws Exception {
|
||||
Integer input = 1;
|
||||
Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
Error error = new Error();
|
||||
final Integer input = 1;
|
||||
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
|
||||
final Error error = new Error();
|
||||
expect(computable.compute(input)).andThrow(error);
|
||||
replay(computable);
|
||||
|
||||
|
|
Loading…
Reference in New Issue