commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [3/6] [text] Add final modifier to local variables.
Date Sat, 19 Nov 2016 18:36:07 GMT
Add final modifier to local variables.

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/aca047e2
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/aca047e2
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/aca047e2

Branch: refs/heads/master
Commit: aca047e2ddbfed2208fd64d9429e3487c9b2c955
Parents: f6214db
Author: Gary Gregory <ggregory@apache.org>
Authored: Sat Nov 19 10:32:46 2016 -0800
Committer: Gary Gregory <ggregory@apache.org>
Committed: Sat Nov 19 10:32:46 2016 -0800

----------------------------------------------------------------------
 .../apache/commons/text/AlphabetConverter.java  | 54 ++++++++++----------
 .../commons/text/names/HumanNameParser.java     | 28 +++++-----
 .../org/apache/commons/text/names/Name.java     |  2 +-
 .../apache/commons/text/names/NameString.java   |  6 +--
 .../commons/text/similarity/CosineDistance.java | 10 ++--
 .../text/similarity/CosineSimilarity.java       | 12 ++---
 .../apache/commons/text/similarity/Counter.java |  2 +-
 .../similarity/LevenshteinDetailedDistance.java |  4 +-
 .../text/similarity/LevenshteinResults.java     |  2 +-
 .../commons/text/similarity/RegexTokenizer.java |  6 +--
 .../text/translate/CharSequenceTranslator.java  |  4 +-
 .../commons/text/AlphabetConverterTest.java     | 40 +++++++--------
 .../commons/text/names/HumanNameParserTest.java |  6 +--
 .../LevenshteinDetailedDistanceTest.java        |  6 +--
 .../ParameterizedEditDistanceFromTest.java      |  2 +-
 .../ParameterizedLevenshteinDistanceTest.java   |  2 +-
 .../ParameterizedSimilarityScoreFromTest.java   |  2 +-
 .../text/similarity/StringMetricFromTest.java   | 20 ++++----
 .../text/translate/AggregateTranslatorTest.java | 10 ++--
 .../text/translate/EntityArraysTest.java        |  4 +-
 .../text/translate/JavaUnicodeEscaperTest.java  |  2 +-
 21 files changed, 112 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/AlphabetConverter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/AlphabetConverter.java b/src/main/java/org/apache/commons/text/AlphabetConverter.java
index d77a204..c5dcf69 100644
--- a/src/main/java/org/apache/commons/text/AlphabetConverter.java
+++ b/src/main/java/org/apache/commons/text/AlphabetConverter.java
@@ -114,12 +114,12 @@ public final class AlphabetConverter {
             return null;
         }
 
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
         for (int i = 0; i < original.length();) {
-            int codepoint = original.codePointAt(i);
+            final int codepoint = original.codePointAt(i);
 
-            String nextLetter = originalToEncoded.get(codepoint);
+            final String nextLetter = originalToEncoded.get(codepoint);
 
             if (nextLetter == null) {
                 throw new UnsupportedEncodingException(
@@ -146,11 +146,11 @@ public final class AlphabetConverter {
             return null;
         }
 
-        StringBuilder result = new StringBuilder();
+        final StringBuilder result = new StringBuilder();
 
         for (int j = 0; j < encoded.length();) {
-            Integer i = encoded.codePointAt(j);
-            String s = codePointToString(i);
+            final Integer i = encoded.codePointAt(j);
+            final String s = codePointToString(i);
 
             if (s.equals(originalToEncoded.get(i))) {
                 result.append(s);
@@ -159,8 +159,8 @@ public final class AlphabetConverter {
                 if (j + encodedLetterLength > encoded.length()) {
                     throw new UnsupportedEncodingException("Unexpected end of string while
decoding " + encoded);
                 } else {
-                    String nextGroup = encoded.substring(j, j + encodedLetterLength);
-                    String next = encodedToOriginal.get(nextGroup);
+                    final String nextGroup = encoded.substring(j, j + encodedLetterLength);
+                    final String next = encodedToOriginal.get(nextGroup);
                     if (next == null) {
                         throw new UnsupportedEncodingException(
                                 "Unexpected string without decoding (" + nextGroup + ") in
" + encoded);
@@ -209,7 +209,7 @@ public final class AlphabetConverter {
             final Iterator<Integer> originals, final Map<Integer, String> doNotEncodeMap)
{
 
         if (level > 0) {
-            for (int encodingLetter : encoding) {
+            for (final int encodingLetter : encoding) {
                 if (originals.hasNext()) {
 
                     // this skips the doNotEncode chars if they are in the
@@ -226,7 +226,7 @@ public final class AlphabetConverter {
             Integer next = originals.next();
 
             while (doNotEncodeMap.containsKey(next)) {
-                String originalLetterAsString = codePointToString(next);
+                final String originalLetterAsString = codePointToString(next);
 
                 originalToEncoded.put(next, originalLetterAsString);
                 encodedToOriginal.put(originalLetterAsString, originalLetterAsString);
@@ -238,7 +238,7 @@ public final class AlphabetConverter {
                 next = originals.next();
             }
 
-            String originalLetterAsString = codePointToString(next);
+            final String originalLetterAsString = codePointToString(next);
 
             originalToEncoded.put(next, currentEncoding);
             encodedToOriginal.put(currentEncoding, originalLetterAsString);
@@ -247,9 +247,9 @@ public final class AlphabetConverter {
 
     @Override
     public String toString() {
-        StringBuilder sb = new StringBuilder();
+        final StringBuilder sb = new StringBuilder();
 
-        for (Entry<Integer, String> entry : originalToEncoded.entrySet()) {
+        for (final Entry<Integer, String> entry : originalToEncoded.entrySet()) {
             sb.append(codePointToString(entry.getKey())).append(ARROW).append(entry.getValue()).append(LINE_SEPARATOR);
         }
 
@@ -288,13 +288,13 @@ public final class AlphabetConverter {
      */
     public static AlphabetConverter createConverterFromMap(final Map<Integer, String>
originalToEncoded) {
         final Map<Integer, String> unmodifiableOriginalToEncoded = Collections.unmodifiableMap(originalToEncoded);
-        Map<String, String> encodedToOriginal = new LinkedHashMap<>();
-        Map<Integer, String> doNotEncodeMap = new HashMap<>();
+        final Map<String, String> encodedToOriginal = new LinkedHashMap<>();
+        final Map<Integer, String> doNotEncodeMap = new HashMap<>();
 
         int encodedLetterLength = 1;
 
-        for (Entry<Integer, String> e : unmodifiableOriginalToEncoded.entrySet()) {
-            String originalAsString = codePointToString(e.getKey());
+        for (final Entry<Integer, String> e : unmodifiableOriginalToEncoded.entrySet())
{
+            final String originalAsString = codePointToString(e.getKey());
             encodedToOriginal.put(e.getValue(), originalAsString);
 
             if (e.getValue().equals(originalAsString)) {
@@ -338,7 +338,7 @@ public final class AlphabetConverter {
         if (chars == null || chars.length == 0) {
             return new Integer[0];
         }
-        Integer[] integers = new Integer[chars.length];
+        final Integer[] integers = new Integer[chars.length];
         for (int i = 0; i < chars.length; i++) {
             integers[i] = (int) chars[i];
         }
@@ -360,9 +360,9 @@ public final class AlphabetConverter {
      */
     public static AlphabetConverter createConverter(final Integer[] original, final Integer[]
encoding, final Integer[] doNotEncode) {
 
-        Set<Integer> originalCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(original));
-        Set<Integer> encodingCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(encoding));
-        Set<Integer> doNotEncodeCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(doNotEncode));
+        final Set<Integer> originalCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(original));
+        final Set<Integer> encodingCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(encoding));
+        final Set<Integer> doNotEncodeCopy = new LinkedHashSet<>(Arrays.<Integer>
asList(doNotEncode));
 
         final Map<Integer, String> originalToEncoded = new LinkedHashMap<>();
         final Map<String, String> encodedToOriginal = new LinkedHashMap<>();
@@ -370,7 +370,7 @@ public final class AlphabetConverter {
 
         int encodedLetterLength;
 
-        for (int i : doNotEncodeCopy) {
+        for (final int i : doNotEncodeCopy) {
             if (!originalCopy.contains(i)) {
                 throw new IllegalArgumentException(
                         "Can not use 'do not encode' list because original alphabet does
not contain '"
@@ -389,10 +389,10 @@ public final class AlphabetConverter {
         if (encodingCopy.size() >= originalCopy.size()) {
             encodedLetterLength = 1;
 
-            Iterator<Integer> it = encodingCopy.iterator();
+            final Iterator<Integer> it = encodingCopy.iterator();
 
-            for (int originalLetter : originalCopy) {
-                String originalLetterAsString = codePointToString(originalLetter);
+            for (final int originalLetter : originalCopy) {
+                final String originalLetterAsString = codePointToString(originalLetter);
 
                 if (doNotEncodeMap.containsKey(originalLetter)) {
                     originalToEncoded.put(originalLetter, originalLetterAsString);
@@ -404,7 +404,7 @@ public final class AlphabetConverter {
                         next = it.next();
                     }
 
-                    String encodedLetter = codePointToString(next);
+                    final String encodedLetter = codePointToString(next);
 
                     originalToEncoded.put(originalLetter, encodedLetter);
                     encodedToOriginal.put(encodedLetter, originalLetterAsString);
@@ -434,7 +434,7 @@ public final class AlphabetConverter {
 
             encodedLetterLength = lettersSoFar + 1;
 
-            AlphabetConverter ac = new AlphabetConverter(originalToEncoded, encodedToOriginal,
encodedLetterLength);
+            final AlphabetConverter ac = new AlphabetConverter(originalToEncoded, encodedToOriginal,
encodedLetterLength);
 
             ac.addSingleEncoding(encodedLetterLength, "", encodingCopy, originalCopy.iterator(),
doNotEncodeMap);
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/names/HumanNameParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java
index d9822a2..5718ba9 100644
--- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java
+++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java
@@ -135,45 +135,45 @@ public final class HumanNameParser {
     public Name parse(final String name) {
         Objects.requireNonNull(name, "Parameter 'name' must not be null.");
 
-        NameString nameString = new NameString(name);
+        final NameString nameString = new NameString(name);
         // TODO compile regexes only once when the parser is created
-        String suffixes = StringUtils.join(this.suffixes, "\\.*|") + "\\.*";
-        String prefixes = StringUtils.join(this.prefixes, " |") + " ";
+        final String suffixes = StringUtils.join(this.suffixes, "\\.*|") + "\\.*";
+        final String prefixes = StringUtils.join(this.prefixes, " |") + " ";
 
         // The regex use is a bit tricky.  *Everything* matched by the regex will be replaced,
         // but you can select a particular parenthesized submatch to be returned.
         // Also, note that each regex requres that the preceding ones have been run, and
matches chopped out.
         // names that starts or end w/ an apostrophe break this
-        String nicknamesRegex = "(?i) ('|\\\"|\\(\\\"*'*)(.+?)('|\\\"|\\\"*'*\\)) ";
-        String suffixRegex = "(?i),* *((" + suffixes + ")$)";
-        String lastRegex = "(?i)(?!^)\\b([^ ]+ y |" + prefixes + ")*[^ ]+$";
+        final String nicknamesRegex = "(?i) ('|\\\"|\\(\\\"*'*)(.+?)('|\\\"|\\\"*'*\\)) ";
+        final String suffixRegex = "(?i),* *((" + suffixes + ")$)";
+        final String lastRegex = "(?i)(?!^)\\b([^ ]+ y |" + prefixes + ")*[^ ]+$";
         // note the lookahead, which isn't returned or replaced
-        String leadingInitRegex = "(?i)(^(.\\.*)(?= \\p{L}{2}))";
-        String firstRegex = "(?i)^([^ ]+)";
+        final String leadingInitRegex = "(?i)(^(.\\.*)(?= \\p{L}{2}))";
+        final String firstRegex = "(?i)^([^ ]+)";
 
         // get nickname, if there is one
-        String nickname = nameString.chopWithRegex(nicknamesRegex, 2);
+        final String nickname = nameString.chopWithRegex(nicknamesRegex, 2);
 
         // get suffix, if there is one
-        String suffix = nameString.chopWithRegex(suffixRegex, 1);
+        final String suffix = nameString.chopWithRegex(suffixRegex, 1);
 
         // flip the before-comma and after-comma parts of the name
         nameString.flip(",");
 
         // get the last name
-        String last = nameString.chopWithRegex(lastRegex, 0);
+        final String last = nameString.chopWithRegex(lastRegex, 0);
 
         // get the first initial, if there is one
-        String leadingInit = nameString.chopWithRegex(leadingInitRegex, 1);
+        final String leadingInit = nameString.chopWithRegex(leadingInitRegex, 1);
 
         // get the first name
-        String first = nameString.chopWithRegex(firstRegex, 0);
+        final String first = nameString.chopWithRegex(firstRegex, 0);
         if (StringUtils.isBlank(first)) {
             throw new NameParseException("Couldn't find a first name in '{" + nameString.getWrappedString()
+ "}'");
         }
 
         // if anything's left, that's the middle name
-        String middle = nameString.getWrappedString();
+        final String middle = nameString.getWrappedString();
 
         return new Name(leadingInit, first, nickname, middle, last, suffix);
     }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/names/Name.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/names/Name.java b/src/main/java/org/apache/commons/text/names/Name.java
index 80141a5..6545b84 100644
--- a/src/main/java/org/apache/commons/text/names/Name.java
+++ b/src/main/java/org/apache/commons/text/names/Name.java
@@ -131,7 +131,7 @@ public final class Name {
         if (o == null || getClass() != o.getClass()) {
             return false;
         }
-        Name name = (Name) o;
+        final Name name = (Name) o;
         return Objects.equals(leadingInitial, name.leadingInitial)
                 && Objects.equals(firstName, name.firstName)
                 && Objects.equals(nickName, name.nickName)

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/names/NameString.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/names/NameString.java b/src/main/java/org/apache/commons/text/names/NameString.java
index 9513176..822497f 100644
--- a/src/main/java/org/apache/commons/text/names/NameString.java
+++ b/src/main/java/org/apache/commons/text/names/NameString.java
@@ -61,7 +61,7 @@ final class NameString {
      * @return the part of the namestring that got chopped off
      */
     String chopWithRegex(final String regex, final int submatchIndex) {
-        String chopped = "";
+        final String chopped = "";
         Pattern pattern = Pattern.compile(regex);
         Matcher matcher = pattern.matcher(this.str);
 
@@ -75,7 +75,7 @@ final class NameString {
         pattern = Pattern.compile(regex);
         matcher = pattern.matcher(this.str);
         if (matcher.find()) {
-            boolean subset = matcher.groupCount() > submatchIndex;
+            final boolean subset = matcher.groupCount() > submatchIndex;
             if (subset) {
                 this.str = this.str.replaceAll(regex, " ");
                 if (numReplacements > 1) {
@@ -97,7 +97,7 @@ final class NameString {
      * @throws NameParseException if a regex fails or a condition is not expected
      */
     void flip(final String flipAroundChar) {
-        String[] parts = this.str.split(flipAroundChar);
+        final String[] parts = this.str.split(flipAroundChar);
         if (parts.length == 2) {
             this.str = String.format("%s %s", parts[1], parts[0]);
             this.norm();

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/CosineDistance.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java
index f9a34ab..4b595ce 100644
--- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java
+++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java
@@ -36,12 +36,12 @@ public class CosineDistance implements EditDistance<Double> {
 
     @Override
     public Double apply(final CharSequence left, final CharSequence right) {
-        CharSequence[] leftTokens = tokenizer.tokenize(left);
-        CharSequence[] rightTokens = tokenizer.tokenize(right);
+        final CharSequence[] leftTokens = tokenizer.tokenize(left);
+        final CharSequence[] rightTokens = tokenizer.tokenize(right);
 
-        Map<CharSequence, Integer> leftVector = Counter.of(leftTokens);
-        Map<CharSequence, Integer> rightVector = Counter.of(rightTokens);
-        double similarity = cosineSimilarity.cosineSimilarity(leftVector, rightVector);
+        final Map<CharSequence, Integer> leftVector = Counter.of(leftTokens);
+        final Map<CharSequence, Integer> rightVector = Counter.of(rightTokens);
+        final double similarity = cosineSimilarity.cosineSimilarity(leftVector, rightVector);
         return 1.0 - similarity;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java
index 5e9af0d..7fe9414 100644
--- a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java
+++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java
@@ -43,15 +43,15 @@ public class CosineSimilarity {
             throw new IllegalArgumentException("Vectors must not be null");
         }
 
-        Set<CharSequence> intersection = getIntersection(leftVector, rightVector);
+        final Set<CharSequence> intersection = getIntersection(leftVector, rightVector);
 
-        double dotProduct = dot(leftVector, rightVector, intersection);
+        final double dotProduct = dot(leftVector, rightVector, intersection);
         double d1 = 0.0d;
-        for (Integer value : leftVector.values()) {
+        for (final Integer value : leftVector.values()) {
             d1 += Math.pow(value, 2);
         }
         double d2 = 0.0d;
-        for (Integer value : rightVector.values()) {
+        for (final Integer value : rightVector.values()) {
             d2 += Math.pow(value, 2);
         }
         double cosineSimilarity;
@@ -72,7 +72,7 @@ public class CosineSimilarity {
      */
     private Set<CharSequence> getIntersection(final Map<CharSequence, Integer>
leftVector,
             final Map<CharSequence, Integer> rightVector) {
-        Set<CharSequence> intersection = new HashSet<>(leftVector.keySet());
+        final Set<CharSequence> intersection = new HashSet<>(leftVector.keySet());
         intersection.retainAll(rightVector.keySet());
         return intersection;
     }
@@ -90,7 +90,7 @@ public class CosineSimilarity {
     private double dot(final Map<CharSequence, Integer> leftVector, final Map<CharSequence,
Integer> rightVector,
             final Set<CharSequence> intersection) {
         long dotProduct = 0;
-        for (CharSequence key : intersection) {
+        for (final CharSequence key : intersection) {
             dotProduct += leftVector.get(key) * rightVector.get(key);
         }
         return dotProduct;

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/Counter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/Counter.java b/src/main/java/org/apache/commons/text/similarity/Counter.java
index e095ba9..7f2a064 100644
--- a/src/main/java/org/apache/commons/text/similarity/Counter.java
+++ b/src/main/java/org/apache/commons/text/similarity/Counter.java
@@ -46,7 +46,7 @@ final class Counter {
      */
     public static Map<CharSequence, Integer> of(final CharSequence[] tokens) {
         final Map<CharSequence, Integer> innerCounter = new HashMap<>();
-        for (CharSequence token : tokens) {
+        for (final CharSequence token : tokens) {
             if (innerCounter.containsKey(token)) {
                 int value = innerCounter.get(token);
                 innerCounter.put(token, ++value);

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
b/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
index e8994dc..c2f5911 100644
--- a/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
+++ b/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
@@ -235,7 +235,7 @@ public class LevenshteinDetailedDistance implements EditDistance<LevenshteinResu
         int[] p = new int[n + 1]; // 'previous' cost array, horizontally
         int[] d = new int[n + 1]; // cost array, horizontally
         int[] tempD; // placeholder to assist in swapping p and d
-        int[][] matrix = new int[m + 1][n + 1];
+        final int[][] matrix = new int[m + 1][n + 1];
 
         //filling the first row and first column values in the matrix
         for (int index = 0; index <= n; index++) {
@@ -376,7 +376,7 @@ public class LevenshteinDetailedDistance implements EditDistance<LevenshteinResu
         int[] p = new int[n + 1]; // 'previous' cost array, horizontally
         int[] d = new int[n + 1]; // cost array, horizontally
         int[] tempD; //placeholder to assist in swapping p and d
-        int[][] matrix = new int[m + 1][n + 1];
+        final int[][] matrix = new int[m + 1][n + 1];
 
         // filling the first row and first column values in the matrix
         for (int index = 0; index <= n; index++) {

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java b/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
index cdb06ee..e6c666f 100644
--- a/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
+++ b/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
@@ -106,7 +106,7 @@ public class LevenshteinResults {
         if (o == null || getClass() != o.getClass()) {
             return false;
         }
-        LevenshteinResults result = (LevenshteinResults) o;
+        final LevenshteinResults result = (LevenshteinResults) o;
         return Objects.equals(distance, result.distance) && Objects.equals(insertCount,
result.insertCount)
                 && Objects.equals(deleteCount, result.deleteCount)
                 && Objects.equals(substituteCount, result.substituteCount);

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/similarity/RegexTokenizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/similarity/RegexTokenizer.java b/src/main/java/org/apache/commons/text/similarity/RegexTokenizer.java
index c3a742d..a849cde 100644
--- a/src/main/java/org/apache/commons/text/similarity/RegexTokenizer.java
+++ b/src/main/java/org/apache/commons/text/similarity/RegexTokenizer.java
@@ -38,9 +38,9 @@ class RegexTokenizer implements Tokenizer<CharSequence> {
         if (text == null || text.toString().trim().equals("")) {
             throw new IllegalArgumentException("Invalid text");
         }
-        Pattern pattern = Pattern.compile("(\\w)+");
-        Matcher matcher = pattern.matcher(text.toString());
-        List<String> tokens = new ArrayList<>();
+        final Pattern pattern = Pattern.compile("(\\w)+");
+        final Matcher matcher = pattern.matcher(text.toString());
+        final List<String> tokens = new ArrayList<>();
         while (matcher.find()) {
             tokens.add(matcher.group(0));
         }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java b/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java
index 0fed939..6c40dbe 100644
--- a/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java
+++ b/src/main/java/org/apache/commons/text/translate/CharSequenceTranslator.java
@@ -85,11 +85,11 @@ public abstract class CharSequenceTranslator {
             if (consumed == 0) {
                 // inlined implementation of Character.toChars(Character.codePointAt(input,
pos))
                 // avoids allocating temp char arrays and duplicate checks
-                char c1 = input.charAt(pos);
+                final char c1 = input.charAt(pos);
                 out.write(c1);
                 pos++;
                 if (Character.isHighSurrogate(c1) && pos < len) {
-                    char c2 = input.charAt(pos);
+                    final char c2 = input.charAt(pos);
                     if (Character.isLowSurrogate(c2)) {
                       out.write(c2);
                       pos++;

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
index f73f898..a03aa7e 100644
--- a/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
+++ b/src/test/java/org/apache/commons/text/AlphabetConverterTest.java
@@ -74,9 +74,9 @@ public class AlphabetConverterTest {
     }
 
     private AlphabetConverter createJavadocExample() {
-        Character[] original = {'a','b','c','d'};
-        Character[] encoding = {'0','1','d'};
-        Character[] doNotEncode = {'d'};
+        final Character[] original = {'a','b','c','d'};
+        final Character[] encoding = {'0','1','d'};
+        final Character[] doNotEncode = {'d'};
         
         return AlphabetConverter.createConverterFromChars(original, encoding, doNotEncode);
     }
@@ -86,7 +86,7 @@ public class AlphabetConverterTest {
      */
     @Test
     public void javadocExampleTest() throws UnsupportedEncodingException {
-        AlphabetConverter ac = createJavadocExample();
+        final AlphabetConverter ac = createJavadocExample();
         
         Assert.assertEquals("00", ac.encode("a"));
         Assert.assertEquals("01", ac.encode("b"));
@@ -97,23 +97,23 @@ public class AlphabetConverterTest {
 
     @Test
     public void unexpectedEndwhileDecodingTest() throws UnsupportedEncodingException {
-        String toDecode = "00d01d0";
+        final String toDecode = "00d01d0";
         
         thrown.expect(UnsupportedEncodingException.class);
         thrown.expectMessage("Unexpected end of string while decoding " + toDecode);
 
-        AlphabetConverter ac = createJavadocExample();
+        final AlphabetConverter ac = createJavadocExample();
         ac.decode(toDecode);
     }
 
     @Test
     public void unexpectedStringWhileDecodingTest() throws UnsupportedEncodingException {
-        String toDecode = "00XX";
+        final String toDecode = "00XX";
         
         thrown.expect(UnsupportedEncodingException.class);
         thrown.expectMessage("Unexpected string without decoding (XX) in " + toDecode);
 
-        AlphabetConverter ac = createJavadocExample();
+        final AlphabetConverter ac = createJavadocExample();
         ac.decode(toDecode);
     }
 
@@ -122,13 +122,13 @@ public class AlphabetConverterTest {
      */
     @Test
     public void unicodeTest() throws UnsupportedEncodingException {
-        AlphabetConverter ac = AlphabetConverter.createConverter(unicode, lower_case_english_codepoints,
doNotEncodePoints);
+        final AlphabetConverter ac = AlphabetConverter.createConverter(unicode, lower_case_english_codepoints,
doNotEncodePoints);
         
         Assert.assertEquals(2, ac.getEncodedCharLength());
         
-        String original = "\u8a43\u8a45 \u8dce ab \u8dc3 c \u8983";
-        String encoded = ac.encode(original);
-        String decoded = ac.decode(encoded);
+        final String original = "\u8a43\u8a45 \u8dce ab \u8dc3 c \u8983";
+        final String encoded = ac.encode(original);
+        final String decoded = ac.decode(encoded);
         
         Assert.assertEquals("Encoded '" + original + "' into '" + encoded + "', but decoded
into '" + decoded + "'", original, decoded);
     }
@@ -146,7 +146,7 @@ public class AlphabetConverterTest {
         thrown.expect(IllegalArgumentException.class);
         thrown.expectMessage("Must have at least two encoding characters (excluding those
in the 'do not encode' list), but has 1");
 
-        Character[] numbersPlusUnderscore = Arrays.copyOf(numbers, numbers.length + 1);
+        final Character[] numbersPlusUnderscore = Arrays.copyOf(numbers, numbers.length +
1);
         numbersPlusUnderscore[numbersPlusUnderscore.length -1] = '_';
 
         AlphabetConverter.createConverterFromChars(english_and_numbers, numbersPlusUnderscore,
numbers);
@@ -170,9 +170,9 @@ public class AlphabetConverterTest {
 
     private void test(final Character[] originalChars, final Character[] encodingChars, final
Character[] doNotEncodeChars, final String... strings) throws UnsupportedEncodingException
{
         
-        AlphabetConverter ac = AlphabetConverter.createConverterFromChars(originalChars,
encodingChars, doNotEncodeChars);
+        final AlphabetConverter ac = AlphabetConverter.createConverterFromChars(originalChars,
encodingChars, doNotEncodeChars);
         
-        AlphabetConverter reconstructedAlphabetConverter = AlphabetConverter.createConverterFromMap(ac.getOriginalToEncoded());
+        final AlphabetConverter reconstructedAlphabetConverter = AlphabetConverter.createConverterFromMap(ac.getOriginalToEncoded());
         
         Assert.assertEquals(ac, reconstructedAlphabetConverter);
         Assert.assertEquals(ac.hashCode(), reconstructedAlphabetConverter.hashCode());
@@ -181,19 +181,19 @@ public class AlphabetConverterTest {
         Assert.assertEquals("", ac.encode("")); // test empty conversion
 
         // test all the trial strings
-        for (String s : strings) {
-            String encoded = ac.encode(s);
+        for (final String s : strings) {
+            final String encoded = ac.encode(s);
 
             // test that only encoding chars are used
-            List<Character> originalEncodingChars = Arrays.asList(encodingChars);
+            final List<Character> originalEncodingChars = Arrays.asList(encodingChars);
             for (int i = 0; i < encoded.length(); i++) {
                 Assert.assertTrue(originalEncodingChars.contains(encoded.charAt(i)));
             }
 
-            String decoded = ac.decode(encoded);
+            final String decoded = ac.decode(encoded);
 
             // test that only the original alphabet is used after decoding
-            List<Character> originalCharsList = Arrays.asList(originalChars);
+            final List<Character> originalCharsList = Arrays.asList(originalChars);
             for (int i = 0; i < decoded.length(); i++) {
                 Assert.assertTrue(originalCharsList.contains(decoded.charAt(i)));
             }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
index 3e84206..f473206 100644
--- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
+++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
@@ -59,7 +59,7 @@ public class HumanNameParserTest {
 
     @Test
     public void testInputs() {
-        for (CSVRecord record : inputParser) {
+        for (final CSVRecord record : inputParser) {
             validateRecord(record);
         }
     }
@@ -71,9 +71,9 @@ public class HumanNameParserTest {
      * @param record a CSVRecord representing one record in the input file.
      */
     private void validateRecord(final CSVRecord record) {
-        Name result = nameParser.parse(record.get(Columns.Name));
+        final Name result = nameParser.parse(record.get(Columns.Name));
 
-        long recordNum = record.getRecordNumber();
+        final long recordNum = record.getRecordNumber();
         assertThat("Wrong LeadingInit in record " + recordNum,
                 result.getLeadingInitial(), equalTo(record.get(Columns.LeadingInit)));
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java
b/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java
index 90d4a20..93eea39 100644
--- a/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java
+++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinDetailedDistanceTest.java
@@ -89,7 +89,7 @@ public class LevenshteinDetailedDistanceTest {
     
     @Test
     public void testEquals() {
-     LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
+     final LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
      LevenshteinResults actualResult = classBeingTested.apply("hello", "hallo");
      LevenshteinResults expectedResult = new LevenshteinResults(1, 0, 0, 1);
      assertEquals(actualResult, expectedResult);
@@ -106,7 +106,7 @@ public class LevenshteinDetailedDistanceTest {
 
     @Test
     public void testHashCode() {
-     LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
+     final LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
      LevenshteinResults actualResult = classBeingTested.apply("aaapppp", "");
      LevenshteinResults expectedResult = new LevenshteinResults(7, 0, 7, 0);
      assertEquals(actualResult.hashCode(), expectedResult.hashCode());
@@ -122,7 +122,7 @@ public class LevenshteinDetailedDistanceTest {
 
     @Test
     public void testToString() {
-     LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
+     final LevenshteinDetailedDistance classBeingTested = new LevenshteinDetailedDistance();
      LevenshteinResults actualResult = classBeingTested.apply("fly", "ant");
      LevenshteinResults expectedResult = new LevenshteinResults(3, 0, 0, 3);
      assertEquals(actualResult.toString(), expectedResult.toString());

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java
b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java
index 0775a0a..1dadc9a 100644
--- a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java
+++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java
@@ -82,7 +82,7 @@ public class ParameterizedEditDistanceFromTest<R> {
 
     @Test
     public void test() {
-        EditDistanceFrom<R> editDistanceFrom = new EditDistanceFrom<>(editDistance,
left);
+        final EditDistanceFrom<R> editDistanceFrom = new EditDistanceFrom<>(editDistance,
left);
         assertThat(editDistanceFrom.apply(right), equalTo(distance));
     }
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java
b/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java
index 2ef5da2..4d627de 100644
--- a/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java
+++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedLevenshteinDistanceTest.java
@@ -118,7 +118,7 @@ public class ParameterizedLevenshteinDistanceTest {
 
     @Test
     public void test() {
-        LevenshteinDistance metric = new LevenshteinDistance(threshold);
+        final LevenshteinDistance metric = new LevenshteinDistance(threshold);
         assertThat(metric.apply(left, right), equalTo(distance));
     }
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java
b/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java
index ba39a04..2594731 100644
--- a/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java
+++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedSimilarityScoreFromTest.java
@@ -58,7 +58,7 @@ public class ParameterizedSimilarityScoreFromTest<R> {
 
     @Test
     public void test() {
-        SimilarityScoreFrom<R> similarityScoreFrom = new SimilarityScoreFrom<R>(similarityScore,
left);
+        final SimilarityScoreFrom<R> similarityScoreFrom = new SimilarityScoreFrom<R>(similarityScore,
left);
         assertThat(similarityScoreFrom.apply(right), equalTo(distance));
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java b/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java
index e36449b..6b5db63 100644
--- a/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java
+++ b/src/test/java/org/apache/commons/text/similarity/StringMetricFromTest.java
@@ -28,11 +28,11 @@ public class StringMetricFromTest {
 
     @Test
     public void testEquivalence() {
-        EditDistance<Integer> metric = new LevenshteinDistance();
-        String left = "Apache";
-        String right = "a patchy";
-        Integer distance = 4;
-        EditDistanceFrom<Integer> metricFrom = new EditDistanceFrom<>(metric,
left);
+        final EditDistance<Integer> metric = new LevenshteinDistance();
+        final String left = "Apache";
+        final String right = "a patchy";
+        final Integer distance = 4;
+        final EditDistanceFrom<Integer> metricFrom = new EditDistanceFrom<>(metric,
left);
 
         assertThat(metricFrom.apply(right), equalTo(distance));
         assertThat(metricFrom.apply(right), equalTo(metric.apply(left, right)));
@@ -40,15 +40,15 @@ public class StringMetricFromTest {
 
     @Test
     public void testJavadocExample() {
-        EditDistance<Integer> metric = new LevenshteinDistance();
-        String target = "Apache";
-        EditDistanceFrom<Integer> metricFrom =
+        final EditDistance<Integer> metric = new LevenshteinDistance();
+        final String target = "Apache";
+        final EditDistanceFrom<Integer> metricFrom =
             new EditDistanceFrom<>(metric, target);
         String mostSimilar = null;
         Integer shortestDistance = null;
         
-        for (String test : new String[] { "Appaloosa", "a patchy", "apple" }) {
-            Integer distance = metricFrom.apply(test);
+        for (final String test : new String[] { "Appaloosa", "a patchy", "apple" }) {
+            final Integer distance = metricFrom.apply(test);
             if (shortestDistance == null || distance < shortestDistance) {
                 shortestDistance = distance;
                 mostSimilar = test;

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java
b/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java
index 799c3e9..5d02104 100644
--- a/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java
+++ b/src/test/java/org/apache/commons/text/translate/AggregateTranslatorTest.java
@@ -32,17 +32,17 @@ public class AggregateTranslatorTest {
 
     @Test
     public void testNullConstructor() throws NoSuchFieldException, IllegalAccessException
{
-        org.apache.commons.text.translate.AggregateTranslator subject = new org.apache.commons.text.translate.AggregateTranslator(null);
-        Field field = AggregateTranslator.class.getDeclaredField("translators");
+        final org.apache.commons.text.translate.AggregateTranslator subject = new org.apache.commons.text.translate.AggregateTranslator(null);
+        final Field field = AggregateTranslator.class.getDeclaredField("translators");
         field.setAccessible(Boolean.TRUE);
         assertNull(field.get(subject));
     }
 
     @Test
     public void testNonNull() throws IOException{
-        CharSequenceTranslator translator1 = new org.apache.commons.text.translate.LookupTranslator(new
CharSequence[][] { { "one", "two" } });
-        CharSequenceTranslator translator2 = new org.apache.commons.text.translate.LookupTranslator(new
CharSequence[][] { { "three", "four" } });
-        org.apache.commons.text.translate.AggregateTranslator subject = new org.apache.commons.text.translate.AggregateTranslator(translator1,
translator2);
+        final CharSequenceTranslator translator1 = new org.apache.commons.text.translate.LookupTranslator(new
CharSequence[][] { { "one", "two" } });
+        final CharSequenceTranslator translator2 = new org.apache.commons.text.translate.LookupTranslator(new
CharSequence[][] { { "three", "four" } });
+        final org.apache.commons.text.translate.AggregateTranslator subject = new org.apache.commons.text.translate.AggregateTranslator(translator1,
translator2);
         final StringWriter out1 = new StringWriter();
         final int result1 = subject.translate(new StringBuffer("one"), 0, out1);
         assertEquals("Incorrect codepoint consumption", 3, result1);

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java
index f797f83..f61dd72 100644
--- a/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java
+++ b/src/test/java/org/apache/commons/text/translate/EntityArraysTest.java
@@ -95,8 +95,8 @@ public class EntityArraysTest  {
     }
 
     private void testEscapeVsUnescapeArrays(final String[][] escapeArray, final String[][]
unescapeArray) {
-        for (String[] escapeElement : escapeArray) {
-            for (String[] unescapeElement : unescapeArray) {
+        for (final String[] escapeElement : escapeArray) {
+            for (final String[] unescapeElement : unescapeArray) {
                 if (escapeElement[0] == unescapeElement[1]) {
                     assertEquals(escapeElement[1], unescapeElement[0]);
                 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/aca047e2/src/test/java/org/apache/commons/text/translate/JavaUnicodeEscaperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/translate/JavaUnicodeEscaperTest.java b/src/test/java/org/apache/commons/text/translate/JavaUnicodeEscaperTest.java
index aab7599..7aaf9d3 100644
--- a/src/test/java/org/apache/commons/text/translate/JavaUnicodeEscaperTest.java
+++ b/src/test/java/org/apache/commons/text/translate/JavaUnicodeEscaperTest.java
@@ -59,7 +59,7 @@ public class JavaUnicodeEscaperTest {
         final org.apache.commons.text.translate.JavaUnicodeEscaper jue = org.apache.commons.text.translate.JavaUnicodeEscaper.below('F');
         // According to https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B10000..U.2B10FFFF,
         // Character ?,	U+24B62,	Binary Code Point 0010 0100 1011 0110 0010,	Binary UTF-167
1101 1000 0101 0010 1101 1111 0110 0010, UTF-16 Hex Code Units D852 DF62
-        String encoding = jue.toUtf16Escape(Integer.parseInt("024B62", 16));
+        final String encoding = jue.toUtf16Escape(Integer.parseInt("024B62", 16));
         assertEquals("\\uD852\\uDF62",encoding);
     }
 }


Mime
View raw message