Repository: commons-lang Updated Branches: refs/heads/master 0f87dceb8 -> c9a5e54a7
Add final modifier to local variables. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c9a5e54a Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c9a5e54a Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c9a5e54a Branch: refs/heads/master Commit: c9a5e54a7c0b4c0be46940d136677a2c9f052ed7 Parents: 0f87dce Author: Gary Gregory <ggreg...@apache.org> Authored: Wed Nov 16 16:46:23 2016 -0800 Committer: Gary Gregory <ggreg...@apache.org> Committed: Wed Nov 16 16:46:23 2016 -0800 ---------------------------------------------------------------------- .../org/apache/commons/lang3/StringUtils.java | 24 +++++------ .../commons/lang3/concurrent/Memoizer.java | 8 ++-- .../commons/lang3/concurrent/MemoizerTest.java | 42 ++++++++++---------- 3 files changed, 37 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c9a5e54a/src/main/java/org/apache/commons/lang3/StringUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 00035b3..c134e7b 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -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); } http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c9a5e54a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java index d0fe406..fb2c154 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java @@ -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); } http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c9a5e54a/src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java index ae511c9..7f1958a 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/MemoizerTest.java @@ -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);