TEXT-62: 200 checkstyle errors
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/c8c189a8 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/c8c189a8 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/c8c189a8 Branch: refs/heads/release Commit: c8c189a87798e31df0baf1f2c1db45a4822f6328 Parents: cc4df47 Author: Rob Tompkins <chtom...@gmail.com> Authored: Sun Jan 29 16:53:55 2017 -0500 Committer: Rob Tompkins <chtom...@gmail.com> Committed: Sun Jan 29 16:53:55 2017 -0500 ---------------------------------------------------------------------- checkstyle-suppressions.xml | 25 +++-- .../apache/commons/text/beta/StrBuilder.java | 53 +++++---- .../commons/text/beta/StringEscapeUtils.java | 109 +++++++++++-------- .../similarity/LevenshteinDetailedDistance.java | 10 +- .../beta/similarity/LevenshteinDistance.java | 8 +- .../similarity/LongestCommonSubsequence.java | 9 +- .../LongestCommonSubsequenceDistance.java | 3 + .../text/beta/similarity/package-info.java | 3 +- 8 files changed, 130 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/checkstyle-suppressions.xml ---------------------------------------------------------------------- diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index f02851e..f577e79 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -19,16 +19,19 @@ limitations under the License. --> <suppressions> - <suppress checks="AvoidInlineConditionals" files=".+\.java" lines="0-9999" /> - <suppress checks="FinalParameters" files=".+\.java" lines="0-9999" /> - <suppress checks="HiddenField" files=".+\.java" lines="0-9999" /> - <suppress checks="DesignForExtension" files=".+\.java" lines="0-9999" /> - <suppress checks="HideUtilityClassConstructor" files=".+\.java" lines="0-9999" /> - <suppress checks="VisibilityModifier" files=".+\.java" lines="0-9999" /> - <suppress checks="EmptyBlock" files="ExtendedMessageFormat.java" lines="387-390" /> - <suppress checks="LocalFinalVariableName" files="FormattableUtils.java" lines="140-146" /> + <suppress checks="AvoidInlineConditionals" files=".+\.java" lines="0-99999" /> + <suppress checks="FinalParameters" files=".+\.java" lines="0-99999" /> + <suppress checks="HiddenField" files=".+\.java" lines="0-99999" /> + <suppress checks="DesignForExtension" files=".+\.java" lines="0-99999" /> + <suppress checks="HideUtilityClassConstructor" files=".+\.java" lines="0-99999" /> + <suppress checks="VisibilityModifier" files=".+\.java" lines="0-99999" /> + <suppress checks="EmptyBlock" files="ExtendedMessageFormat.java" lines="0-99999" /> + <suppress checks="LocalFinalVariableName" files="FormattableUtils.java" lines="0-99999" /> <suppress checks="MagicNumber" files="JaccardDistance.java" lines="0-99999" /> - <suppress checks="MagicNumber" files="JaccardSimilarity.java" lines="0-9999" /> - <suppress checks="MagicNumber" files="JaroWinklerDistance.java" lines="0-9999" /> - <suppress checks="NoWhitespaceAfter" files="JaroWinklerDistance.java" lines="0-9999" /> + <suppress checks="MagicNumber" files="JaccardSimilarity.java" lines="0-99999" /> + <suppress checks="MagicNumber" files="JaroWinklerDistance.java" lines="0-99999" /> + <suppress checks="NoWhitespaceAfter" files="JaroWinklerDistance.java" lines="0-99999" /> + <suppress checks="FileLength" files="StrBuilder.java" lines="0-99999" /> + <suppress checks="MagicNumber" files="StrBuilder.java" lines="0-99999"/> + <suppress checks="MagicNumber" files="StringEscapeUtils.java" lines="0-99999"/> </suppressions> http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/StrBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/StrBuilder.java b/src/main/java/org/apache/commons/text/beta/StrBuilder.java index aa0b50a..260055a 100644 --- a/src/main/java/org/apache/commons/text/beta/StrBuilder.java +++ b/src/main/java/org/apache/commons/text/beta/StrBuilder.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -76,7 +76,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build /** * Required for serialization support. - * + * * @see java.io.Serializable */ private static final long serialVersionUID = 7628716375283629643L; @@ -352,7 +352,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build if (size == 0) { return new char[0]; } - final char chars[] = new char[size]; + final char[] chars = new char[size]; System.arraycopy(buffer, 0, chars, 0, size); return chars; } @@ -373,7 +373,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build if (len == 0) { return new char[0]; } - final char chars[] = new char[len]; + final char[] chars = new char[len]; System.arraycopy(buffer, startIndex, chars, 0, len); return chars; } @@ -403,7 +403,10 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @throws NullPointerException if the array is null * @throws IndexOutOfBoundsException if any index is invalid */ - public void getChars(final int startIndex, final int endIndex, final char destination[], final int destinationIndex) { + public void getChars(final int startIndex, + final int endIndex, + final char[] destination, + final int destinationIndex) { if (startIndex < 0) { throw new StringIndexOutOfBoundsException(startIndex); } @@ -1593,7 +1596,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @return this, to enable chaining * @throws IndexOutOfBoundsException if the index is invalid */ - public StrBuilder insert(final int index, final char chars[]) { + public StrBuilder insert(final int index, final char[] chars) { validateIndex(index); if (chars == null) { return insert(index, nullText); @@ -1619,7 +1622,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @return this, to enable chaining * @throws IndexOutOfBoundsException if any index is invalid */ - public StrBuilder insert(final int index, final char chars[], final int offset, final int length) { + public StrBuilder insert(final int index, final char[] chars, final int offset, final int length) { validateIndex(index); if (chars == null) { return insert(index, nullText); @@ -1883,7 +1886,11 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build * @param insertLen the length of the insert string, must be valid * @throws IndexOutOfBoundsException if any index is invalid */ - private void replaceImpl(final int startIndex, final int endIndex, final int removeLen, final String insertStr, final int insertLen) { + private void replaceImpl(final int startIndex, + final int endIndex, + final int removeLen, + final String insertStr, + final int insertLen) { final int newSize = size - removeLen + insertLen; if (insertLen != removeLen) { ensureCapacity(newSize); @@ -2098,7 +2105,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build final int half = size / 2; final char[] buf = buffer; - for (int leftIdx = 0, rightIdx = size - 1; leftIdx < half; leftIdx++,rightIdx--) { + for (int leftIdx = 0, rightIdx = size - 1; leftIdx < half; leftIdx++, rightIdx--) { final char swap = buf[leftIdx]; buf[leftIdx] = buf[rightIdx]; buf[rightIdx] = swap; @@ -2183,7 +2190,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build return false; } int pos = size - len; - for (int i = 0; i < len; i++,pos++) { + for (int i = 0; i < len; i++, pos++) { if (buffer[pos] != str.charAt(i)) { return false; } @@ -2732,7 +2739,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build // nullText = null; // return (String) con.newInstance( // new Object[] {Integer.valueOf(0), Integer.valueOf(size), buffer}); -// +// // } catch (Exception ex) { // ex.printStackTrace(); // throw new UnsupportedOperationException("StrBuilder.toSharedString is unsupported: " + ex.getMessage()); @@ -2754,8 +2761,8 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build if (this.size != other.size) { return false; } - final char thisBuf[] = this.buffer; - final char otherBuf[] = other.buffer; + final char[] thisBuf = this.buffer; + final char[] otherBuf = other.buffer; for (int i = size - 1; i >= 0; i--) { final char c1 = thisBuf[i]; final char c2 = otherBuf[i]; @@ -2783,8 +2790,8 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build if (this.size != other.size) { return false; } - final char thisBuf[] = this.buffer; - final char otherBuf[] = other.buffer; + final char[] thisBuf = this.buffer; + final char[] otherBuf = other.buffer; for (int i = size - 1; i >= 0; i--) { if (thisBuf[i] != otherBuf[i]) { return false; @@ -2813,7 +2820,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build */ @Override public int hashCode() { - final char buf[] = buffer; + final char[] buf = buffer; int hash = 0; for (int i = size - 1; i >= 0; i--) { hash = 31 * hash + buf[i]; @@ -2869,7 +2876,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build //----------------------------------------------------------------------- /** * Validates parameters defining a range of the builder. - * + * * @param startIndex the start index, inclusive, must be valid * @param endIndex the end index, exclusive, must be valid except * that if too large it is treated as end of string @@ -2891,7 +2898,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build /** * Validates parameters defining a single index in the builder. - * + * * @param index the index, must be valid * @throws IndexOutOfBoundsException if the index is invalid */ @@ -2961,7 +2968,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build /** {@inheritDoc} */ @Override public int read() { - if (ready() == false) { + if (!ready()) { return -1; } return StrBuilder.this.charAt(pos++); @@ -2969,9 +2976,9 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build /** {@inheritDoc} */ @Override - public int read(final char b[], final int off, int len) { - if (off < 0 || len < 0 || off > b.length || - (off + len) > b.length || (off + len) < 0) { + public int read(final char[] b, final int off, int len) { + if (off < 0 || len < 0 || off > b.length + || (off + len) > b.length || (off + len) < 0) { throw new IndexOutOfBoundsException(); } if (len == 0) { http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/StringEscapeUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/StringEscapeUtils.java b/src/main/java/org/apache/commons/text/beta/StringEscapeUtils.java index 0e8bfff..d6f8ded 100644 --- a/src/main/java/org/apache/commons/text/beta/StringEscapeUtils.java +++ b/src/main/java/org/apache/commons/text/beta/StringEscapeUtils.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,10 +54,10 @@ public class StringEscapeUtils { /* ESCAPE TRANSLATORS */ /** - * Translator object for escaping Java. + * Translator object for escaping Java. * - * While {@link #escapeJava(String)} is the expected method of use, this - * object allows the Java escaping functionality to be used + * While {@link #escapeJava(String)} is the expected method of use, this + * object allows the Java escaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator ESCAPE_JAVA; @@ -73,10 +73,10 @@ public class StringEscapeUtils { } /** - * Translator object for escaping EcmaScript/JavaScript. + * Translator object for escaping EcmaScript/JavaScript. * - * While {@link #escapeEcmaScript(String)} is the expected method of use, this - * object allows the EcmaScript escaping functionality to be used + * While {@link #escapeEcmaScript(String)} is the expected method of use, this + * object allows the EcmaScript escaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator ESCAPE_ECMASCRIPT; @@ -194,8 +194,8 @@ public class StringEscapeUtils { /** * Translator object for escaping HTML version 3.0. * - * While {@link #escapeHtml3(String)} is the expected method of use, this - * object allows the HTML escaping functionality to be used + * While {@link #escapeHtml3(String)} is the expected method of use, this + * object allows the HTML escaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator ESCAPE_HTML3 = @@ -226,8 +226,8 @@ public class StringEscapeUtils { /** * Translator object for escaping HTML version 4.0. * - * While {@link #escapeHtml4(String)} is the expected method of use, this - * object allows the HTML escaping functionality to be used + * While {@link #escapeHtml4(String)} is the expected method of use, this + * object allows the HTML escaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator ESCAPE_HTML4 = @@ -260,10 +260,10 @@ public class StringEscapeUtils { ); /** - * Translator object for escaping individual Comma Separated Values. + * Translator object for escaping individual Comma Separated Values. * - * While {@link #escapeCsv(String)} is the expected method of use, this - * object allows the CSV escaping functionality to be used + * While {@link #escapeCsv(String)} is the expected method of use, this + * object allows the CSV escaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator ESCAPE_CSV = new CsvTranslators.CsvEscaper(); @@ -307,10 +307,10 @@ public class StringEscapeUtils { /* UNESCAPE TRANSLATORS */ /** - * Translator object for unescaping escaped Java. + * Translator object for unescaping escaped Java. * - * While {@link #unescapeJava(String)} is the expected method of use, this - * object allows the Java unescaping functionality to be used + * While {@link #unescapeJava(String)} is the expected method of use, this + * object allows the Java unescaping functionality to be used * as the foundation for a custom translator. */ // TODO: throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per the compiler)? @@ -330,10 +330,10 @@ public class StringEscapeUtils { } /** - * Translator object for unescaping escaped EcmaScript. + * Translator object for unescaping escaped EcmaScript. * - * While {@link #unescapeEcmaScript(String)} is the expected method of use, this - * object allows the EcmaScript unescaping functionality to be used + * While {@link #unescapeEcmaScript(String)} is the expected method of use, this + * object allows the EcmaScript unescaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA; @@ -348,10 +348,10 @@ public class StringEscapeUtils { public static final CharSequenceTranslator UNESCAPE_JSON = UNESCAPE_JAVA; /** - * Translator object for unescaping escaped HTML 3.0. + * Translator object for unescaping escaped HTML 3.0. * - * While {@link #unescapeHtml3(String)} is the expected method of use, this - * object allows the HTML unescaping functionality to be used + * While {@link #unescapeHtml3(String)} is the expected method of use, this + * object allows the HTML unescaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator UNESCAPE_HTML3 = @@ -362,10 +362,10 @@ public class StringEscapeUtils { ); /** - * Translator object for unescaping escaped HTML 4.0. + * Translator object for unescaping escaped HTML 4.0. * - * While {@link #unescapeHtml4(String)} is the expected method of use, this - * object allows the HTML unescaping functionality to be used + * While {@link #unescapeHtml4(String)} is the expected method of use, this + * object allows the HTML unescaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator UNESCAPE_HTML4 = @@ -379,8 +379,8 @@ public class StringEscapeUtils { /** * Translator object for unescaping escaped XML. * - * While {@link #unescapeXml(String)} is the expected method of use, this - * object allows the XML unescaping functionality to be used + * While {@link #unescapeXml(String)} is the expected method of use, this + * object allows the XML unescaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator UNESCAPE_XML = @@ -393,12 +393,19 @@ public class StringEscapeUtils { /** * Translator object for unescaping escaped Comma Separated Value entries. * - * While {@link #unescapeCsv(String)} is the expected method of use, this - * object allows the CSV unescaping functionality to be used + * While {@link #unescapeCsv(String)} is the expected method of use, this + * object allows the CSV unescaping functionality to be used * as the foundation for a custom translator. */ public static final CharSequenceTranslator UNESCAPE_CSV = new CsvTranslators.CsvUnescaper(); + /** + * Translator object for unescaping escaped XSI Value entries. + * + * While {@link #unescapeXSI(String)} is the expected method of use, this + * object allows the XSI unescaping functionality to be used + * as the foundation for a custom translator. + */ public static final CharSequenceTranslator UNESCAPE_XSI = new XsiUnescaper(); /** @@ -406,12 +413,15 @@ public class StringEscapeUtils { */ static class XsiUnescaper extends CharSequenceTranslator { + /** + * Escaped backslash constant. + */ private static final char BACKSLASH = '\\'; @Override public int translate(final CharSequence input, final int index, final Writer out) throws IOException { - if(index != 0) { + if (index != 0) { throw new IllegalStateException("XsiUnescaper should never reach the [1] index"); } @@ -469,11 +479,23 @@ public class StringEscapeUtils { * </pre> * */ - public static class Builder { + public static final class Builder { + /** + * StringBuilder to be used in the Builder class. + */ private final StringBuilder sb; + + /** + * CharSequenceTranslator to be used in the Builder class. + */ private final CharSequenceTranslator translator; + /** + * Builder constructor. + * + * @param translator a CharSequenceTranslator. + */ private Builder(final CharSequenceTranslator translator) { this.sb = new StringBuilder(); this.translator = translator; @@ -570,9 +592,8 @@ public class StringEscapeUtils { * {@code '\\\"'} which could result in potential issues in the case where the string being escaped is being used * in an HTML tag like {@code <select onmouseover="..." />}. If you wish to have more rigorous string escaping, you * may consider the - * <a href="https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API_JAVA">ESAPI Libraries</a>. Further, - * you can view the - * <a href="https://github.com/esapi">ESAPI GitHub Org</a>. + * <a href="https://www.owasp.org/index.php/Category:OWASP_Enterprise_Security_API_JAVA">ESAPI Libraries</a>. + * Further, you can view the <a href="https://github.com/esapi">ESAPI GitHub Org</a>. * * @param input String to escape values in, may be null * @return String with escaped values, {@code null} if null string input @@ -657,7 +678,7 @@ public class StringEscapeUtils { * * <p> * For example: - * </p> + * </p> * <p><code>"bread" & "butter"</code></p> * becomes: * <p> @@ -842,7 +863,7 @@ public class StringEscapeUtils { * <p>Supports only the five basic XML entities (gt, lt, quot, amp, apos). * Does not support DTDs or external entities.</p> * - * <p>Note that numerical \\u Unicode codes are unescaped to their respective + * <p>Note that numerical \\u Unicode codes are unescaped to their respective * Unicode characters. This may change in future releases. </p> * * @param input the {@code String} to unescape, may be null @@ -882,21 +903,21 @@ public class StringEscapeUtils { /** * <p>Returns a {@code String} value for an unescaped CSV column. </p> * - * <p>If the value is enclosed in double quotes, and contains a comma, newline - * or double quote, then quotes are removed. + * <p>If the value is enclosed in double quotes, and contains a comma, newline + * or double quote, then quotes are removed. * </p> * - * <p>Any double quote escaped characters (a pair of double quotes) are unescaped + * <p>Any double quote escaped characters (a pair of double quotes) are unescaped * to just one double quote. </p> * - * <p>If the value is not enclosed in double quotes, or is and does not contain a + * <p>If the value is not enclosed in double quotes, or is and does not contain a * comma, newline or double quote, then the String value is returned unchanged.</p> * * see <a href="http://en.wikipedia.org/wiki/Comma-separated_values">Wikipedia</a> and * <a href="http://tools.ietf.org/html/rfc4180">RFC 4180</a>. * * @param input the input CSV column String, may be null - * @return the input String, with enclosing double quotes removed and embedded double + * @return the input String, with enclosing double quotes removed and embedded double * quotes unescaped, {@code null} if null string input */ public static final String unescapeCsv(final String input) { @@ -935,4 +956,4 @@ public class StringEscapeUtils { return UNESCAPE_XSI.translate(input); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDetailedDistance.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDetailedDistance.java b/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDetailedDistance.java index 9ec633e..ec69f1d 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDetailedDistance.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDetailedDistance.java @@ -155,7 +155,9 @@ 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, final int threshold) { //NOPMD + private static LevenshteinResults limitedCompare(CharSequence left, + CharSequence right, + final int threshold) { //NOPMD if (left == null || right == null) { throw new IllegalArgumentException("Strings must not be null"); } @@ -431,8 +433,10 @@ public class LevenshteinDetailedDistance implements EditDistance<LevenshteinResu * character sequence were swapped to save memory * @return result object containing the count of insert, delete and substitute and total count needed */ - private static LevenshteinResults findDetailedResults(final CharSequence left, final CharSequence right, final int[][] matrix, - final boolean swapped) { + private static LevenshteinResults findDetailedResults(final CharSequence left, + final CharSequence right, + final int[][] matrix, + final boolean swapped) { int delCount = 0; int addCount = 0; http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDistance.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDistance.java b/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDistance.java index 6877fff..1f7d9a8 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDistance.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/LevenshteinDistance.java @@ -366,7 +366,7 @@ public class LevenshteinDistance implements EditDistance<Integer> { // indexes into strings left and right int i; // iterates through left int j; // iterates through right - int upper_left; + int upperLeft; int upper; char rightJ; // jth character of right @@ -377,7 +377,7 @@ public class LevenshteinDistance implements EditDistance<Integer> { } for (j = 1; j <= m; j++) { - upper_left = p[0]; + upperLeft = p[0]; rightJ = right.charAt(j - 1); p[0] = j; @@ -385,8 +385,8 @@ public class LevenshteinDistance implements EditDistance<Integer> { upper = p[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 - p[i] = Math.min(Math.min(p[i - 1] + 1, p[i] + 1), upper_left + cost); - upper_left = upper; + p[i] = Math.min(Math.min(p[i - 1] + 1, p[i] + 1), upperLeft + cost); + upperLeft = upper; } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequence.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequence.java b/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequence.java index a782eee..b985a67 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequence.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequence.java @@ -75,8 +75,9 @@ public class LongestCommonSubsequence implements SimilarityScore<Integer> { * </p> * * <p> - * For reference, we give the definition of a subsequence for the reader: a <i>subsequence</i> is a sequence that can be - * derived from another sequence by deleting some elements without changing the order of the remaining elements. + * For reference, we give the definition of a subsequence for the reader: a <i>subsequence</i> is a sequence that + * can be derived from another sequence by deleting some elements without changing the order of the remaining + * elements. * </p> * * @param left first character sequence @@ -122,8 +123,8 @@ public class LongestCommonSubsequence implements SimilarityScore<Integer> { */ public int[][] longestCommonSubstringLengthArray(final CharSequence left, final CharSequence right) { int[][] lcsLengthArray = new int[left.length() + 1][right.length() + 1]; - for (int i=0; i < left.length(); i++) { - for (int j=0; j < right.length(); j++) { + for (int i = 0; i < left.length(); i++) { + for (int j = 0; j < right.length(); j++) { if (i == 0) { lcsLengthArray[i][j] = 0; } http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequenceDistance.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequenceDistance.java b/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequenceDistance.java index dd00f10..46a73a3 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequenceDistance.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/LongestCommonSubsequenceDistance.java @@ -36,6 +36,9 @@ package org.apache.commons.text.beta.similarity; */ public class LongestCommonSubsequenceDistance implements EditDistance<Integer> { + /** + * Object for calculating the longest common subsequence that we can then normalize in apply. + */ private final LongestCommonSubsequence longestCommonSubsequence = new LongestCommonSubsequence(); /** http://git-wip-us.apache.org/repos/asf/commons-text/blob/c8c189a8/src/main/java/org/apache/commons/text/beta/similarity/package-info.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/package-info.java b/src/main/java/org/apache/commons/text/beta/similarity/package-info.java index 957901c..de5a313 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/package-info.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/package-info.java @@ -30,7 +30,8 @@ * <li>{@link org.apache.commons.text.beta.similarity.HammingDistance Hamming Distance}</li> * <li>{@link org.apache.commons.text.beta.similarity.JaroWinklerDistance Jaro-Winkler Distance}</li> * <li>{@link org.apache.commons.text.beta.similarity.LevenshteinDistance Levenshtein Distance}</li> - * <li>{@link org.apache.commons.text.beta.similarity.LongestCommonSubsequenceDistance Longest Commons Subsequence Distance}</li> + * <li>{@link org.apache.commons.text.beta.similarity.LongestCommonSubsequenceDistance + * Longest Commons Subsequence Distance}</li> * </ul> * * <p>The {@link org.apache.commons.text.beta.similarity.CosineDistance Cosine Distance}