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