Fix checkstyle issues

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

Branch: refs/heads/master
Commit: c8a803c21cd53e431e90569233730e0dd4d025ba
Parents: 579fd28
Author: Bruno P. Kinoshita <brunodepau...@yahoo.com.br>
Authored: Wed Nov 9 21:09:26 2016 +1300
Committer: Bruno P. Kinoshita <brunodepau...@yahoo.com.br>
Committed: Wed Nov 9 21:09:26 2016 +1300

----------------------------------------------------------------------
 .../similarity/LevenshteinDetailedDistance.java | 73 ++++++----------
 .../text/similarity/LevenshteinResults.java     | 89 ++++++++++----------
 2 files changed, 72 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8a803c2/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 d0869a2..89c3681 100644
--- 
a/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
+++ 
b/src/main/java/org/apache/commons/text/similarity/LevenshteinDetailedDistance.java
@@ -26,16 +26,13 @@ import java.util.Arrays;
  * where each change is a single character modification (deletion, insertion
  * or substitution).
  * </p>
- *
  */
 public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResults> {
 
-
     /**
      * Default instance.
      */
     private static final LevenshteinDetailedDistance DEFAULT_INSTANCE = new 
LevenshteinDetailedDistance();
-
     /**
      * Threshold.
      */
@@ -54,14 +51,11 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
     }
 
     /**
-     * <p>
      * If the threshold is not null, distance calculations will be limited to 
a maximum length.
-     * If the threshold is null, the unlimited version of the algorithm will 
be used.
-     * </p>
      *
-     * @param threshold
-     *        If this is null then distances calculations will not be limited.
-     *        This may not be negative.
+     * <p>If the threshold is null, the unlimited version of the algorithm 
will be used.</p>
+     *
+     * @param threshold If this is null then distances calculations will not 
be limited. This may not be negative.
      */
     public LevenshteinDetailedDistance(final Integer threshold) {
         if (threshold != null && threshold < 0) {
@@ -159,7 +153,7 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
      * @param threshold the target threshold, must not be negative
      * @return result distance, or -1
      */
-    private static LevenshteinResults limitedCompare(CharSequence left, 
CharSequence right, int threshold) { // NOPMD
+    private static LevenshteinResults limitedCompare(CharSequence left, 
CharSequence right, int threshold) { //NOPMD
         if (left == null || right == null) {
             throw new IllegalArgumentException("Strings must not be null");
         }
@@ -220,8 +214,7 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
         int n = left.length(); // length of left
         int m = right.length(); // length of right
 
-        // if one string is empty, the edit distance is necessarily the length
-        // of the other
+        // if one string is empty, the edit distance is necessarily the length 
of the other
         if (n == 0) {
             return m <= threshold ? new LevenshteinResults(m, m, 0, 0) : new 
LevenshteinResults(-1, 0, 0, 0);
         } else if (m == 0) {
@@ -242,16 +235,16 @@ 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];
+        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++) {
+        for (int index = 0; index <= n; index++) {
             matrix[0][index] = index;
         }
-        for(int index = 0; index <=m; index++) {
+        for (int index = 0; index <= m; index++) {
             matrix[index][0] = index;
         }
-        
+
         // fill in starting table values
         final int boundary = Math.min(n, threshold) + 1;
         for (int i = 0; i < boundary; i++) {
@@ -272,8 +265,7 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
             final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min(
                     n, j + threshold);
 
-            // the stripe may lead off of the table if s and t are of different
-            // sizes
+            // the stripe may lead off of the table if s and t are of 
different sizes
             if (min > max) {
                 return new LevenshteinResults(-1, 0, 0, 0);
             }
@@ -289,8 +281,7 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
                     // diagonally left and up
                     d[i] = p[i - 1];
                 } else {
-                    // 1 + minimum of cell to the left, to the top, diagonally
-                    // left and up
+                    // 1 + minimum of cell to the left, to the top, diagonally 
left and up
                     d[i] = 1 + Math.min(Math.min(d[i - 1], p[i]), p[i - 1]);
                 }
                 matrix[j][i] = d[i];
@@ -302,9 +293,7 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
             d = tempD;
         }
 
-        // if p[n] is greater than the threshold, there's no guarantee on it
-        // being the correct
-        // distance
+        // if p[n] is greater than the threshold, there's no guarantee on it 
being the correct distance
         if (p[n] <= threshold) {
             return findDetailedResults(left, right, matrix, swapped);
         }
@@ -384,16 +373,16 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
             swapped = true;
         }
 
-        int[] p = new int[n + 1]; //'previous' cost array, horizontally
+        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];
+        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++) {
+        // filling the first row and first column values in the matrix
+        for (int index = 0; index <= n; index++) {
             matrix[0][index] = index;
         }
-        for(int index = 0; index <=m; index++) {
+        for (int index = 0; index <= m; index++) {
             matrix[index][0] = index;
         }
 
@@ -407,11 +396,11 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
         for (i = 0; i <= n; i++) {
             p[i] = i;
         }
-        
+
         for (j = 1; j <= m; j++) {
             rightJ = right.charAt(j - 1);
             d[0] = j;
-            
+
             for (i = 1; i <= n; i++) {
                 cost = left.charAt(i - 1) == rightJ ? 0 : 1;
                 // minimum of cell to the left+1, to the top+1, diagonally 
left and up +cost
@@ -432,18 +421,13 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
      * Finds count for each of the three [insert, delete, substitute] 
operations
      * needed. This is based on the matrix formed based on the two character
      * sequence.
-     * 
-     * @param left
-     *            character sequence which need to be converted from.
-     * @param right
-     *            character sequence which need to be converted to.
-     * @param matrix
-     *            two dimensional array containing
-     * @param swapped
-     *            tells whether the value for left character sequence and right
+     *
+     * @param left character sequence which need to be converted from
+     * @param right character sequence which need to be converted to
+     * @param matrix two dimensional array containing
+     * @param swapped tells whether the value for left character sequence and 
right
      *            character sequence were swapped to save memory
-     * @return result object containing the count of insert, delete and
-     *         substitute and total count needed
+     * @return result object containing the count of insert, delete and 
substitute and total count needed
      */
     private static LevenshteinResults findDetailedResults(CharSequence left, 
CharSequence right, int[][] matrix,
             boolean swapped) {
@@ -498,18 +482,17 @@ public class LevenshteinDetailedDistance implements 
EditDistance<LevenshteinResu
             if (data - 1 == dataAtLeft && (data <= dataAtDiagonal && data <= 
dataAtTop)
                     || (dataAtDiagonal == -1 && dataAtTop == -1)) { // NOPMD
                 columnIndex--;
-                if (swapped == true) {
+                if (swapped) {
                     addCount++;
                     added = true;
                 } else {
                     delCount++;
                     deleted = true;
                 }
-            }
-            else if (data - 1 == dataAtTop && (data <= dataAtDiagonal && data 
<= dataAtLeft)
+            } else if (data - 1 == dataAtTop && (data <= dataAtDiagonal && 
data <= dataAtLeft)
                     || (dataAtDiagonal == -1 && dataAtLeft == -1)) { // NOPMD
                 rowIndex--;
-                if (swapped == true) {
+                if (swapped) {
                     delCount++;
                     deleted = true;
                 } else {

http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8a803c2/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 12043da..9da8235 100644
--- a/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
+++ b/src/main/java/org/apache/commons/text/similarity/LevenshteinResults.java
@@ -19,18 +19,41 @@ package org.apache.commons.text.similarity;
 import java.util.Objects;
 
 /**
- * Container class to store Levenshtein distance between two character 
sequence.
- * It also stores the count of inserts, deletions and substitutions needed to
- * change one character sequence to other.
- * 
+ * Container class to store Levenshtein distance between two character 
sequences.
+ *
+ * <p>Stores the count of insert, deletion and substitute operations needed to
+ * change one character sequence into another.</p>
+ *
+ * <p>This class is immutable.</p>
+ *
+ * @since 1.0
  */
 public class LevenshteinResults {
-
+    /**
+     * Edit distance.
+     */
     private final Integer distance;
+    /**
+     * Insert character count.
+     */
     private final Integer insertCount;
+    /**
+     * Delete character count.
+     */
     private final Integer deleteCount;
+    /**
+     * Substitute character count.
+     */
     private final Integer substituteCount;
 
+    /**
+     * Create the results for a detailed Levenshtein distance.
+     *
+     * @param distance distance between two character sequences.
+     * @param insertCount insert character count
+     * @param deleteCount delete character count
+     * @param substituteCount substitute character count
+     */
     public LevenshteinResults(final Integer distance, final Integer 
insertCount, final Integer deleteCount,
             final Integer substituteCount) {
         this.distance = distance;
@@ -40,87 +63,63 @@ public class LevenshteinResults {
     }
 
     /**
-     * gets the distance between two character sequence.
-     * 
-     * @return distance between two character sequence.
+     * Get the distance between two character sequences.
+     *
+     * @return distance between two character sequence
      */
     public Integer getDistance() {
         return distance;
     }
 
     /**
-     * gets the number of insertion needed to change one character sequence to
-     * other.
-     * 
-     * @return insert character count.
+     * Get the number of insertion needed to change one character sequence 
into another.
+     *
+     * @return insert character count
      */
     public Integer getInsertCount() {
         return insertCount;
     }
 
     /**
-     * gets the number of character deletion needed to change one character
-     * sequence to other.
-     * 
-     * @return delete character count.
+     * Get the number of character deletion needed to change one character 
sequence to other.
+     *
+     * @return delete character count
      */
     public Integer getDeleteCount() {
         return deleteCount;
     }
 
     /**
-     * get the number of character substitution needed to change one character
-     * sequence to other.
-     * 
-     * @return substitute character count.
+     * Get the number of character substitution needed to change one character 
sequence into another.
+     *
+     * @return substitute character count
      */
     public Integer getSubstituteCount() {
         return substituteCount;
     }
 
-    /**
-     * indicates whether this object is equal to the object passed. It checks
-     * whether each of the individual attributes of both the objects are equal.
-     * 
-     * @param o
-     *            - the object to which this object needs to be compared.
-     * 
-     * @return - true if this object is same as the one passed as argument,
-     *         false otherwise.
-     */
     @Override
     public boolean equals(Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        if (o == null || getClass() != o.getClass())
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
+        }
         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);
     }
 
-    /**
-     * gets the hash code value for this object. This hash code is made from
-     * individual attributes of this object.
-     * 
-     * @return - hash code value of this object.
-     */
     @Override
     public int hashCode() {
         return Objects.hash(distance, insertCount, deleteCount, 
substituteCount);
     }
 
-    /**
-     * returns the textual representation of this object, its formed using
-     * individual attributes of this object.
-     * 
-     * @return - textual representation of this object.
-     */
     @Override
     public String toString() {
         return "Distance: " + distance + ", Insert: " + insertCount + ", 
Delete: " + deleteCount + ", Substitute: "
                 + substituteCount;
-
     }
 }

Reply via email to