TEXT-62: Now there are 321 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/fb65bb67 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/fb65bb67 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/fb65bb67 Branch: refs/heads/release Commit: fb65bb67e345ccaa479c1172ae3b94baac9cb691 Parents: 629c0a7 Author: Rob Tompkins <chtom...@gmail.com> Authored: Sat Jan 28 13:36:29 2017 -0500 Committer: Rob Tompkins <chtom...@gmail.com> Committed: Sat Jan 28 13:36:29 2017 -0500 ---------------------------------------------------------------------- checkstyle-suppressions.xml | 1 + .../commons/text/beta/AlphabetConverter.java | 191 +++++++++++++------ .../org/apache/commons/text/beta/Builder.java | 2 +- .../commons/text/beta/CharacterPredicate.java | 8 +- .../commons/text/beta/CharacterPredicates.java | 8 +- .../commons/text/beta/CompositeFormat.java | 18 +- .../text/beta/ExtendedMessageFormat.java | 72 +++++-- .../apache/commons/text/beta/FormatFactory.java | 4 +- .../commons/text/beta/FormattableUtils.java | 29 +-- .../text/beta/similarity/CosineSimilarity.java | 3 +- 10 files changed, 228 insertions(+), 108 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/checkstyle-suppressions.xml ---------------------------------------------------------------------- diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index 7f310bd..e445f90 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -25,4 +25,5 @@ <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" /> </suppressions> http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/AlphabetConverter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/AlphabetConverter.java b/src/main/java/org/apache/commons/text/beta/AlphabetConverter.java index 40c9698..3080fe5 100644 --- a/src/main/java/org/apache/commons/text/beta/AlphabetConverter.java +++ b/src/main/java/org/apache/commons/text/beta/AlphabetConverter.java @@ -31,15 +31,18 @@ import java.util.Set; /** * <p> - * Convert from one alphabet to another, with the possibility of leaving certain characters unencoded. + * Convert from one alphabet to another, with the possibility of leaving certain + * characters unencoded. * </p> * * <p> - * The target and do not encode languages must be in the Unicode BMP, but the source language does not. + * The target and do not encode languages must be in the Unicode BMP, but the + * source language does not. * </p> * * <p> - * The encoding will all be of a fixed length, except for the 'do not encode' chars, which will be of length 1 + * The encoding will all be of a fixed length, except for the 'do not encode' + * chars, which will be of length 1 * </p> * * <h3>Sample usage</h3> @@ -49,7 +52,8 @@ import java.util.Set; * Character[] encoding; // 0, 1, d * Character[] doNotEncode; // d * - * AlphabetConverter ac = AlphabetConverter.createConverterFromChars(originals, encoding, doNotEncode); + * AlphabetConverter ac = AlphabetConverter.createConverterFromChars(originals, + * encoding, doNotEncode); * * ac.encode("a"); // 00 * ac.encode("b"); // 01 @@ -59,7 +63,8 @@ import java.util.Set; * </pre> * * <p> - * #ThreadSafe# AlphabetConverter class methods are threadsafe as they do not change internal state. + * #ThreadSafe# AlphabetConverter class methods are threadsafe as they do not + * change internal state. * </p> * * @since 1.0 @@ -86,7 +91,8 @@ public final class AlphabetConverter { /** * Line separator, used for converting the object into a string. */ - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + private static final String LINE_SEPARATOR = + System.getProperty("line.separator"); /** * Hidden constructor for alphabet converter. Used by static helper methods. @@ -95,8 +101,9 @@ public final class AlphabetConverter { * @param encodedToOriginal encoding alphabet * @param encodedLetterLength length of the encoded letter */ - private AlphabetConverter(final Map<Integer, String> originalToEncoded, final Map<String, String> encodedToOriginal, - final int encodedLetterLength) { + private AlphabetConverter(final Map<Integer, String> originalToEncoded, + final Map<String, String> encodedToOriginal, + final int encodedLetterLength) { this.originalToEncoded = originalToEncoded; this.encodedToOriginal = encodedToOriginal; @@ -108,9 +115,11 @@ public final class AlphabetConverter { * * @param original the string to be encoded * @return the encoded string, {@code null} if the given string is null - * @throws UnsupportedEncodingException if chars that are not supported are encountered + * @throws UnsupportedEncodingException if chars that are not supported are + * encountered */ - public String encode(final String original) throws UnsupportedEncodingException { + public String encode(final String original) + throws UnsupportedEncodingException { if (original == null) { return null; } @@ -124,7 +133,11 @@ public final class AlphabetConverter { if (nextLetter == null) { throw new UnsupportedEncodingException( - "Couldn't find encoding for '" + codePointToString(codepoint) + "' in " + original); + "Couldn't find encoding for '" + + codePointToString(codepoint) + + "' in " + + original + ); } sb.append(nextLetter); @@ -138,11 +151,14 @@ public final class AlphabetConverter { /** * Decode a given string. * - * @param encoded a string that has been encoded using this AlphabetConverter + * @param encoded a string that has been encoded using this + * AlphabetConverter * @return the decoded string, {@code null} if the given string is null - * @throws UnsupportedEncodingException if unexpected characters that cannot be handled are encountered + * @throws UnsupportedEncodingException if unexpected characters that + * cannot be handled are encountered */ - public String decode(final String encoded) throws UnsupportedEncodingException { + public String decode(final String encoded) + throws UnsupportedEncodingException { if (encoded == null) { return null; } @@ -155,16 +171,20 @@ public final class AlphabetConverter { if (s.equals(originalToEncoded.get(i))) { result.append(s); - j++; // because we do not encode in Unicode extended the length of each encoded char is 1 + j++; // because we do not encode in Unicode extended the + // length of each encoded char is 1 } else { if (j + encodedLetterLength > encoded.length()) { - throw new UnsupportedEncodingException("Unexpected end of string while decoding " + encoded); + throw new UnsupportedEncodingException("Unexpected end " + + "of string while decoding " + encoded); } - final String nextGroup = encoded.substring(j, j + encodedLetterLength); + 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); + "Unexpected string without decoding (" + + nextGroup + ") in " + encoded); } result.append(next); j += encodedLetterLength; @@ -175,7 +195,8 @@ public final class AlphabetConverter { } /** - * Get the length of characters in the encoded alphabet that are necessary for each character in the original + * Get the length of characters in the encoded alphabet that are necessary + * for each character in the original * alphabet. * * @return the length of the encoded char @@ -185,7 +206,8 @@ public final class AlphabetConverter { } /** - * Get the mapping from integer code point of source language to encoded string. Use to reconstruct converter from + * Get the mapping from integer code point of source language to encoded + * string. Use to reconstruct converter from * serialized map. * * @return the original map @@ -204,8 +226,11 @@ public final class AlphabetConverter { * @param doNotEncodeMap map of values that should not be encoded */ @SuppressWarnings("PMD") - private void addSingleEncoding(final int level, final String currentEncoding, final Collection<Integer> encoding, - final Iterator<Integer> originals, final Map<Integer, String> doNotEncodeMap) { + private void addSingleEncoding(final int level, + final String currentEncoding, + final Collection<Integer> encoding, + final Iterator<Integer> originals, + final Map<Integer, String> doNotEncodeMap) { if (level > 0) { for (final int encodingLetter : encoding) { @@ -213,9 +238,15 @@ public final class AlphabetConverter { // this skips the doNotEncode chars if they are in the // leftmost place - if (level != encodedLetterLength || !doNotEncodeMap.containsKey(encodingLetter)) { - addSingleEncoding(level - 1, currentEncoding + codePointToString(encodingLetter), encoding, - originals, doNotEncodeMap); + if (level != encodedLetterLength + || !doNotEncodeMap.containsKey(encodingLetter)) { + addSingleEncoding(level - 1, + currentEncoding + + codePointToString(encodingLetter), + encoding, + originals, + doNotEncodeMap + ); } } else { return; // done encoding all the original alphabet @@ -228,7 +259,8 @@ public final class AlphabetConverter { final String originalLetterAsString = codePointToString(next); originalToEncoded.put(next, originalLetterAsString); - encodedToOriginal.put(originalLetterAsString, originalLetterAsString); + encodedToOriginal.put(originalLetterAsString, + originalLetterAsString); if (!originals.hasNext()) { return; @@ -248,8 +280,11 @@ public final class AlphabetConverter { public String toString() { final StringBuilder sb = new StringBuilder(); - for (final Entry<Integer, String> entry : originalToEncoded.entrySet()) { - sb.append(codePointToString(entry.getKey())).append(ARROW).append(entry.getValue()).append(LINE_SEPARATOR); + for (final Entry<Integer, String> entry + : originalToEncoded.entrySet()) { + sb.append(codePointToString(entry.getKey())) + .append(ARROW) + .append(entry.getValue()).append(LINE_SEPARATOR); } return sb.toString(); @@ -267,13 +302,16 @@ public final class AlphabetConverter { return false; } final AlphabetConverter other = (AlphabetConverter) obj; - return originalToEncoded.equals(other.originalToEncoded) && encodedToOriginal.equals(other.encodedToOriginal) + return originalToEncoded.equals(other.originalToEncoded) + && encodedToOriginal.equals(other.encodedToOriginal) && encodedLetterLength == other.encodedLetterLength; } @Override public int hashCode() { - return Objects.hash(originalToEncoded, encodedToOriginal, encodedLetterLength); + return Objects.hash(originalToEncoded, + encodedToOriginal, + encodedLetterLength); } // -- static methods @@ -285,14 +323,17 @@ public final class AlphabetConverter { * @return the reconstructed AlphabetConverter * @see AlphabetConverter#getOriginalToEncoded() */ - public static AlphabetConverter createConverterFromMap(final Map<Integer, String> originalToEncoded) { - final Map<Integer, String> unmodifiableOriginalToEncoded = Collections.unmodifiableMap(originalToEncoded); + public static AlphabetConverter createConverterFromMap( + final Map<Integer, String> originalToEncoded) { + final Map<Integer, String> unmodifiableOriginalToEncoded = + Collections.unmodifiableMap(originalToEncoded); final Map<String, String> encodedToOriginal = new LinkedHashMap<>(); final Map<Integer, String> doNotEncodeMap = new HashMap<>(); int encodedLetterLength = 1; - for (final Entry<Integer, String> e : unmodifiableOriginalToEncoded.entrySet()) { + for (final Entry<Integer, String> e + : unmodifiableOriginalToEncoded.entrySet()) { final String originalAsString = codePointToString(e.getKey()); encodedToOriginal.put(e.getValue(), originalAsString); @@ -305,25 +346,35 @@ public final class AlphabetConverter { } } - return new AlphabetConverter(unmodifiableOriginalToEncoded, encodedToOriginal, encodedLetterLength); + return new AlphabetConverter(unmodifiableOriginalToEncoded, + encodedToOriginal, + encodedLetterLength); } /** - * Create an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving - * the characters in <em>doNotEncode</em> as they are (if possible). + * Create an alphabet converter, for converting from the original alphabet, + * to the encoded alphabet, while leaving the characters in + * <em>doNotEncode</em> as they are (if possible). * * <p>Duplicate letters in either original or encoding will be ignored.</p> * * @param original an array of chars representing the original alphabet - * @param encoding an array of chars representing the alphabet to be used for encoding - * @param doNotEncode an array of chars to be encoded using the original alphabet - every char here must appear in - * both the previous params + * @param encoding an array of chars representing the alphabet to be used + * for encoding + * @param doNotEncode an array of chars to be encoded using the original + * alphabet - every char here must appear in + * both the previous params * @return the AlphabetConverter - * @throws IllegalArgumentException if an AlphabetConverter cannot be constructed + * @throws IllegalArgumentException if an AlphabetConverter cannot be + * constructed */ - public static AlphabetConverter createConverterFromChars(final Character[] original, final Character[] encoding, + public static AlphabetConverter createConverterFromChars( + final Character[] original, + final Character[] encoding, final Character[] doNotEncode) { - return AlphabetConverter.createConverter(convertCharsToIntegers(original), convertCharsToIntegers(encoding), + return AlphabetConverter.createConverter( + convertCharsToIntegers(original), + convertCharsToIntegers(encoding), convertCharsToIntegers(doNotEncode)); } @@ -345,20 +396,27 @@ public final class AlphabetConverter { } /** - * Create an alphabet converter, for converting from the original alphabet, to the encoded alphabet, while leaving + * Create an alphabet converter, for converting from the original alphabet, + * to the encoded alphabet, while leaving * the characters in <em>doNotEncode</em> as they are (if possible). * * <p>Duplicate letters in either original or encoding will be ignored.</p> * - * @param original an array of ints representing the original alphabet in codepoints - * @param encoding an array of ints representing the alphabet to be used for encoding, in codepoints - * @param doNotEncode an array of ints representing the chars to be encoded using the original alphabet - every char - * here must appear in both the previous params + * @param original an array of ints representing the original alphabet in + * codepoints + * @param encoding an array of ints representing the alphabet to be used for + * encoding, in codepoints + * @param doNotEncode an array of ints representing the chars to be encoded + * using the original alphabet - every char + * here must appear in both the previous params * @return the AlphabetConverter - * @throws IllegalArgumentException if an AlphabetConverter cannot be constructed + * @throws IllegalArgumentException if an AlphabetConverter cannot be + * constructed */ - public static AlphabetConverter createConverter(final Integer[] original, final Integer[] encoding, final Integer[] doNotEncode) { - + public static AlphabetConverter createConverter( + final Integer[] original, + final Integer[] encoding, + final Integer[] 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)); @@ -372,7 +430,8 @@ public final class AlphabetConverter { 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 '" + "Can not use 'do not encode' list because original " + + "alphabet does not contain '" + codePointToString(i) + "'"); } @@ -391,11 +450,14 @@ public final class AlphabetConverter { final Iterator<Integer> it = encodingCopy.iterator(); for (final int originalLetter : originalCopy) { - final String originalLetterAsString = codePointToString(originalLetter); + final String originalLetterAsString = + codePointToString(originalLetter); if (doNotEncodeMap.containsKey(originalLetter)) { - originalToEncoded.put(originalLetter, originalLetterAsString); - encodedToOriginal.put(originalLetterAsString, originalLetterAsString); + originalToEncoded.put(originalLetter, + originalLetterAsString); + encodedToOriginal.put(originalLetterAsString, + originalLetterAsString); } else { Integer next = it.next(); @@ -406,15 +468,19 @@ public final class AlphabetConverter { final String encodedLetter = codePointToString(next); originalToEncoded.put(originalLetter, encodedLetter); - encodedToOriginal.put(encodedLetter, originalLetterAsString); + encodedToOriginal.put(encodedLetter, + originalLetterAsString); } } - return new AlphabetConverter(originalToEncoded, encodedToOriginal, encodedLetterLength); + return new AlphabetConverter(originalToEncoded, + encodedToOriginal, + encodedLetterLength); } else if (encodingCopy.size() - doNotEncodeCopy.size() < 2) { throw new IllegalArgumentException( - "Must have at least two encoding characters (excluding those in the 'do not encode' list), but has " + "Must have at least two encoding characters (excluding " + + "those in the 'do not encode' list), but has " + (encodingCopy.size() - doNotEncodeCopy.size())); } else { // we start with one which is our minimum, and because we do the @@ -433,9 +499,16 @@ public final class AlphabetConverter { encodedLetterLength = lettersSoFar + 1; - final AlphabetConverter ac = new AlphabetConverter(originalToEncoded, encodedToOriginal, encodedLetterLength); + final AlphabetConverter ac = + new AlphabetConverter(originalToEncoded, + encodedToOriginal, + encodedLetterLength); - ac.addSingleEncoding(encodedLetterLength, "", encodingCopy, originalCopy.iterator(), doNotEncodeMap); + ac.addSingleEncoding(encodedLetterLength, + "", + encodingCopy, + originalCopy.iterator(), + doNotEncodeMap); return ac; } http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/Builder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/Builder.java b/src/main/java/org/apache/commons/text/beta/Builder.java index c789cbc..59879cd 100644 --- a/src/main/java/org/apache/commons/text/beta/Builder.java +++ b/src/main/java/org/apache/commons/text/beta/Builder.java @@ -85,4 +85,4 @@ public interface Builder<T> { * @return the object constructed or result calculated by the builder. */ T build(); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/CharacterPredicate.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/CharacterPredicate.java b/src/main/java/org/apache/commons/text/beta/CharacterPredicate.java index ddf72c8..60a7c47 100644 --- a/src/main/java/org/apache/commons/text/beta/CharacterPredicate.java +++ b/src/main/java/org/apache/commons/text/beta/CharacterPredicate.java @@ -19,14 +19,14 @@ package org.apache.commons.text.beta; /** * A predicate for selecting code points. Implementations of this interface must * be thread safe. - * + * * @since 1.0 */ public interface CharacterPredicate { - + /** * Tests the code point with this predicate. - * + * * @param codePoint * the code point to test * @return {@code true} if the code point matches the predicate, @@ -34,4 +34,4 @@ public interface CharacterPredicate { * @since 1.0 */ boolean test(int codePoint); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/CharacterPredicates.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/CharacterPredicates.java b/src/main/java/org/apache/commons/text/beta/CharacterPredicates.java index 097de09..3bd4aca 100644 --- a/src/main/java/org/apache/commons/text/beta/CharacterPredicates.java +++ b/src/main/java/org/apache/commons/text/beta/CharacterPredicates.java @@ -21,14 +21,14 @@ package org.apache.commons.text.beta; * Commonly used implementations of {@link CharacterPredicate}. Per the interface * requirements, all implementations are thread safe. * </p> - * + * * @since 1.0 */ public enum CharacterPredicates implements CharacterPredicate { /** - * Tests code points against {@link Character#isLetter(int)} - * + * Tests code points against {@link Character#isLetter(int)}. + * * @since 1.0 */ LETTERS { @@ -40,7 +40,7 @@ public enum CharacterPredicates implements CharacterPredicate { /** * Tests code points against {@link Character#isDigit(int)}. - * + * * @since 1.0 */ DIGITS { http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/CompositeFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/CompositeFormat.java b/src/main/java/org/apache/commons/text/beta/CompositeFormat.java index f44219d..fd29442 100644 --- a/src/main/java/org/apache/commons/text/beta/CompositeFormat.java +++ b/src/main/java/org/apache/commons/text/beta/CompositeFormat.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. @@ -32,7 +32,7 @@ public class CompositeFormat extends Format { /** * Required for serialization support. - * + * * @see java.io.Serializable */ private static final long serialVersionUID = -4329119827877627683L; @@ -45,7 +45,7 @@ public class CompositeFormat extends Format { /** * Create a format that points its parseObject method to one implementation * and its format method to another. - * + * * @param parser implementation * @param formatter implementation */ @@ -56,7 +56,7 @@ public class CompositeFormat extends Format { /** * Uses the formatter Format instance. - * + * * @param obj the object to format * @param toAppendTo the {@link StringBuffer} to append to * @param pos the FieldPosition to use (or ignore). @@ -71,7 +71,7 @@ public class CompositeFormat extends Format { /** * Uses the parser Format instance. - * + * * @param source the String source * @param pos the ParsePosition containing the position to parse from, will * be updated according to parsing success (index) or failure @@ -86,7 +86,7 @@ public class CompositeFormat extends Format { /** * Provides access to the parser Format implementation. - * + * * @return parser Format implementation */ public Format getParser() { @@ -95,7 +95,7 @@ public class CompositeFormat extends Format { /** * Provides access to the parser Format implementation. - * + * * @return formatter Format implementation */ public Format getFormatter() { @@ -104,7 +104,7 @@ public class CompositeFormat extends Format { /** * Utility method to parse and then reformat a String. - * + * * @param input String to reformat * @return A reformatted String * @throws ParseException thrown by parseObject(String) call http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/ExtendedMessageFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/text/beta/ExtendedMessageFormat.java index 09a3e02..0d1eaba 100644 --- a/src/main/java/org/apache/commons/text/beta/ExtendedMessageFormat.java +++ b/src/main/java/org/apache/commons/text/beta/ExtendedMessageFormat.java @@ -64,16 +64,50 @@ import java.util.Objects; * @since 1.0 */ public class ExtendedMessageFormat extends MessageFormat { + + /** + * Serializable Object. + */ private static final long serialVersionUID = -2362048321261811743L; + + /** + * Our initial seed value for calculating hashes. + */ private static final int HASH_SEED = 31; + /** + * The empty string. + */ private static final String DUMMY_PATTERN = ""; + + /** + * A comma. + */ private static final char START_FMT = ','; + + /** + * A right side squigly brace. + */ private static final char END_FE = '}'; + + /** + * A left side squigly brace. + */ private static final char START_FE = '{'; + + /** + * A properly escaped character representing a single quote. + */ private static final char QUOTE = '\''; + /** + * To pattern string. + */ private String toPattern; + + /** + * Our registry of FormatFactory's. + */ private final Map<String, ? extends FormatFactory> registry; /** @@ -104,7 +138,8 @@ public class ExtendedMessageFormat extends MessageFormat { * @param registry the registry of format factories, may be null * @throws IllegalArgumentException in case of a bad pattern. */ - public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry) { + public ExtendedMessageFormat(final String pattern, + final Map<String, ? extends FormatFactory> registry) { this(pattern, Locale.getDefault(), registry); } @@ -116,7 +151,9 @@ public class ExtendedMessageFormat extends MessageFormat { * @param registry the registry of format factories, may be null * @throws IllegalArgumentException in case of a bad pattern. */ - public ExtendedMessageFormat(final String pattern, final Locale locale, final Map<String, ? extends FormatFactory> registry) { + public ExtendedMessageFormat(final String pattern, + final Locale locale, + final Map<String, ? extends FormatFactory> registry) { super(DUMMY_PATTERN); setLocale(locale); this.registry = registry; @@ -174,7 +211,7 @@ public class ExtendedMessageFormat extends MessageFormat { } foundFormats.add(format); foundDescriptions.add(format == null ? null : formatDescription); - if(foundFormats.size() != fmtCount) { + if (foundFormats.size() != fmtCount) { throw new IllegalArgumentException("The validated expression is false"); } if (foundDescriptions.size() != fmtCount) { @@ -212,7 +249,8 @@ public class ExtendedMessageFormat extends MessageFormat { * * @param formatElementIndex format element index * @param newFormat the new format - * @throws UnsupportedOperationException always thrown since this isn't supported by ExtendMessageFormat + * @throws UnsupportedOperationException always thrown since this isn't + * supported by ExtendMessageFormat */ @Override public void setFormat(final int formatElementIndex, final Format newFormat) { @@ -224,10 +262,12 @@ public class ExtendedMessageFormat extends MessageFormat { * * @param argumentIndex argument index * @param newFormat the new format - * @throws UnsupportedOperationException always thrown since this isn't supported by ExtendMessageFormat + * @throws UnsupportedOperationException always thrown since this isn't + * supported by ExtendMessageFormat */ @Override - public void setFormatByArgumentIndex(final int argumentIndex, final Format newFormat) { + public void setFormatByArgumentIndex(final int argumentIndex, + final Format newFormat) { throw new UnsupportedOperationException(); } @@ -235,7 +275,8 @@ public class ExtendedMessageFormat extends MessageFormat { * Throws UnsupportedOperationException - see class Javadoc for details. * * @param newFormats new formats - * @throws UnsupportedOperationException always thrown since this isn't supported by ExtendMessageFormat + * @throws UnsupportedOperationException always thrown since this isn't + * supported by ExtendMessageFormat */ @Override public void setFormats(final Format[] newFormats) { @@ -246,7 +287,8 @@ public class ExtendedMessageFormat extends MessageFormat { * Throws UnsupportedOperationException - see class Javadoc for details. * * @param newFormats new formats - * @throws UnsupportedOperationException always thrown since this isn't supported by ExtendMessageFormat + * @throws UnsupportedOperationException always thrown since this isn't + * supported by ExtendMessageFormat */ @Override public void setFormatsByArgumentIndex(final Format[] newFormats) { @@ -273,7 +315,7 @@ public class ExtendedMessageFormat extends MessageFormat { if (!Objects.equals(getClass(), obj.getClass())) { return false; } - final ExtendedMessageFormat rhs = (ExtendedMessageFormat)obj; + final ExtendedMessageFormat rhs = (ExtendedMessageFormat) obj; if (!Objects.equals(toPattern, rhs.toPattern)) { return false; } @@ -318,7 +360,7 @@ public class ExtendedMessageFormat extends MessageFormat { } /** - * Read the argument index from the current format element + * Read the argument index from the current format element. * * @param pattern pattern to parse * @param pos current parse position @@ -453,7 +495,7 @@ public class ExtendedMessageFormat extends MessageFormat { } /** - * Convenience method to advance parse position by 1 + * Convenience method to advance parse position by 1. * * @param pos ParsePosition * @return <code>pos</code> @@ -474,11 +516,11 @@ public class ExtendedMessageFormat extends MessageFormat { */ private StringBuilder appendQuotedString(final String pattern, final ParsePosition pos, final StringBuilder appendTo) { - assert pattern.toCharArray()[pos.getIndex()] == QUOTE : - "Quoted string must start with quote character"; + assert pattern.toCharArray()[pos.getIndex()] == QUOTE + : "Quoted string must start with quote character"; // handle quote character at the beginning of the string - if(appendTo != null) { + if (appendTo != null) { appendTo.append(QUOTE); } next(pos); @@ -501,7 +543,7 @@ public class ExtendedMessageFormat extends MessageFormat { } /** - * Consume quoted string only + * Consume quoted string only. * * @param pattern pattern to parse * @param pos current parse position http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/FormatFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/FormatFactory.java b/src/main/java/org/apache/commons/text/beta/FormatFactory.java index 0daa581..2a469e1 100644 --- a/src/main/java/org/apache/commons/text/beta/FormatFactory.java +++ b/src/main/java/org/apache/commons/text/beta/FormatFactory.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. http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/FormattableUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/FormattableUtils.java b/src/main/java/org/apache/commons/text/beta/FormattableUtils.java index 206a055..2cd40cd 100644 --- a/src/main/java/org/apache/commons/text/beta/FormattableUtils.java +++ b/src/main/java/org/apache/commons/text/beta/FormattableUtils.java @@ -23,7 +23,7 @@ import static java.util.FormattableFlags.LEFT_JUSTIFY; /** * <p>Provides utilities for working with the {@code Formattable} interface.</p> - * + * * <p>The {@link Formattable} interface provides basic control over formatting * when using a {@code Formatter}. It is primarily concerned with numeric precision * and padding, and is not designed to allow generalised alternate formats.</p> @@ -42,7 +42,7 @@ public class FormattableUtils { * <p>{@code FormattableUtils} instances should NOT be constructed in * standard programming. Instead, the methods of the class should be invoked * statically.</p> - * + * * <p>This constructor is public to permit tools that require a JavaBean * instance to operate.</p> */ @@ -54,7 +54,7 @@ public class FormattableUtils { /** * Get the default formatted representation of the specified * {@code Formattable}. - * + * * @param formattable the instance to convert to a string, not null * @return the resulting string, not null */ @@ -66,7 +66,7 @@ public class FormattableUtils { * Handles the common {@code Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow, and padding width underflow with * spaces. - * + * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} @@ -82,7 +82,7 @@ public class FormattableUtils { /** * Handles the common {@link Formattable} operations of truncate-pad-append, * with no ellipsis on precision overflow. - * + * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} @@ -99,7 +99,7 @@ public class FormattableUtils { /** * Handles the common {@link Formattable} operations of truncate-pad-append, * padding width underflow with spaces. - * + * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} @@ -116,7 +116,7 @@ public class FormattableUtils { /** * Handles the common {@link Formattable} operations of truncate-pad-append. - * + * * @param seq the string to handle, not null * @param formatter the destination formatter, not null * @param flags the flags for formatting, see {@code Formattable} @@ -129,18 +129,21 @@ public class FormattableUtils { */ public static Formatter append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision, final char padChar, final CharSequence ellipsis) { - if ( ! (ellipsis == null || precision < 0 || ellipsis.length() <= precision) ) { - throw new IllegalArgumentException(String.format("Specified ellipsis '%1$s' exceeds precision of %2$s", ellipsis, Integer.valueOf(precision))); + if (!(ellipsis == null || precision < 0 || ellipsis.length() <= precision)) { + throw new IllegalArgumentException( + String.format("Specified ellipsis '%1$s' exceeds precision of %2$s", + ellipsis, + Integer.valueOf(precision))); } final StringBuilder buf = new StringBuilder(seq); if (precision >= 0 && precision < seq.length()) { - final CharSequence _ellipsis; + final CharSequence normalizedEllipsis; if (ellipsis == null) { - _ellipsis = ""; + normalizedEllipsis = ""; } else { - _ellipsis = ellipsis; + normalizedEllipsis = ellipsis; } - buf.replace(precision - _ellipsis.length(), seq.length(), _ellipsis.toString()); + buf.replace(precision - normalizedEllipsis.length(), seq.length(), normalizedEllipsis.toString()); } final boolean leftJustify = (flags & LEFT_JUSTIFY) == LEFT_JUSTIFY; for (int i = buf.length(); i < width; i++) { http://git-wip-us.apache.org/repos/asf/commons-text/blob/fb65bb67/src/main/java/org/apache/commons/text/beta/similarity/CosineSimilarity.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/beta/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/beta/similarity/CosineSimilarity.java index b8fe704..d318dc3 100644 --- a/src/main/java/org/apache/commons/text/beta/similarity/CosineSimilarity.java +++ b/src/main/java/org/apache/commons/text/beta/similarity/CosineSimilarity.java @@ -40,7 +40,8 @@ public class CosineSimilarity { * @param rightVector right vector * @return cosine similarity between the two vectors */ - public Double cosineSimilarity(final Map<CharSequence, Integer> leftVector, final Map<CharSequence, Integer> rightVector) { + public Double cosineSimilarity(final Map<CharSequence, Integer> leftVector, + final Map<CharSequence, Integer> rightVector) { if (leftVector == null || rightVector == null) { throw new IllegalArgumentException("Vectors must not be null"); }