diff --git a/src/main/java/org/apache/commons/codec/binary/BinaryCodec.java b/src/main/java/org/apache/commons/codec/binary/BinaryCodec.java index 823170fe73..c64b6e53a6 100644 --- a/src/main/java/org/apache/commons/codec/binary/BinaryCodec.java +++ b/src/main/java/org/apache/commons/codec/binary/BinaryCodec.java @@ -211,6 +211,13 @@ public static String toAsciiString(final byte[] raw) { return new String(toAsciiChars(raw)); } + /** + * Constructs a new instance. + */ + public BinaryCodec() { + // empty + } + /** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * diff --git a/src/main/java/org/apache/commons/codec/binary/CharSequenceUtils.java b/src/main/java/org/apache/commons/codec/binary/CharSequenceUtils.java index ece4d81d03..e3cfdbb80f 100644 --- a/src/main/java/org/apache/commons/codec/binary/CharSequenceUtils.java +++ b/src/main/java/org/apache/commons/codec/binary/CharSequenceUtils.java @@ -29,16 +29,6 @@ */ public class CharSequenceUtils { - /** - * Consider package-private. - * - * @deprecated Will be package-private in the next major version. - */ - @Deprecated - public CharSequenceUtils() { - // empty - } - /** * Green implementation of regionMatches. * @@ -86,4 +76,14 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi } return true; } + + /** + * Consider private. + * + * @deprecated Will be private in the next major version. + */ + @Deprecated + public CharSequenceUtils() { + // empty + } } diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java index 53a3f75f9b..24856133de 100644 --- a/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java +++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash3.java @@ -73,6 +73,13 @@ public final class MurmurHash3 { @Deprecated public static class IncrementalHash32 extends IncrementalHash32x86 { + /** + * Constructs a new instance. + */ + public IncrementalHash32() { + // empty + } + /** * {@inheritDoc} * @@ -155,6 +162,13 @@ private static int orBytes(final byte b1, final byte b2, final byte b3, final by */ private int hash; + /** + * Constructs a new instance. + */ + public IncrementalHash32x86() { + // empty + } + /** * Adds the byte array to the current incremental hash. * diff --git a/src/main/java/org/apache/commons/codec/language/AbstractCaverphone.java b/src/main/java/org/apache/commons/codec/language/AbstractCaverphone.java index c0a4fcf2c7..1d2a3bfbb0 100644 --- a/src/main/java/org/apache/commons/codec/language/AbstractCaverphone.java +++ b/src/main/java/org/apache/commons/codec/language/AbstractCaverphone.java @@ -34,12 +34,19 @@ public abstract class AbstractCaverphone implements StringEncoder { /** - * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of + * Constructs a new instance for subclasses. + */ + public AbstractCaverphone() { + // empty + } + + /** + * Encodes an Object using the Caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type {@link String}. * * @param source * Object to encode - * @return An object (or type {@link String}) containing the caverphone code which corresponds to the String + * @return An object (or type {@link String}) containing the Caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type {@link String}. diff --git a/src/main/java/org/apache/commons/codec/language/Caverphone.java b/src/main/java/org/apache/commons/codec/language/Caverphone.java index 416f96b2d3..b9459dc64b 100644 --- a/src/main/java/org/apache/commons/codec/language/Caverphone.java +++ b/src/main/java/org/apache/commons/codec/language/Caverphone.java @@ -39,24 +39,31 @@ public class Caverphone implements StringEncoder { */ private final Caverphone2 encoder = new Caverphone2(); + /** + * Constructs a new instance. + */ + public Caverphone() { + // empty + } + /** * Encodes the given String into a Caverphone value. * * @param source * String the source string - * @return A caverphone code for the given String + * @return A Caverphone code for the given String */ public String caverphone(final String source) { return this.encoder.encode(source); } /** - * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of + * Encodes an Object using the Caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type {@link String}. * * @param obj * Object to encode - * @return An object (or type {@link String}) containing the caverphone code which corresponds to the String + * @return An object (or type {@link String}) containing the Caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type {@link String}. @@ -74,7 +81,7 @@ public Object encode(final Object obj) throws EncoderException { * * @param str * String object to encode - * @return The caverphone code corresponding to the String supplied + * @return The Caverphone code corresponding to the String supplied */ @Override public String encode(final String str) { @@ -82,13 +89,13 @@ public String encode(final String str) { } /** - * Tests if the caverphones of two strings are identical. + * Tests if the Caverphones of two strings are identical. * * @param str1 * First of two strings to compare * @param str2 * Second of two strings to compare - * @return {@code true} if the caverphones of these strings are identical, {@code false} otherwise. + * @return {@code true} if the Caverphones of these strings are identical, {@code false} otherwise. */ public boolean isCaverphoneEqual(final String str1, final String str2) { return caverphone(str1).equals(caverphone(str2)); diff --git a/src/main/java/org/apache/commons/codec/language/Caverphone1.java b/src/main/java/org/apache/commons/codec/language/Caverphone1.java index 1c562008e6..72b98b6f77 100644 --- a/src/main/java/org/apache/commons/codec/language/Caverphone1.java +++ b/src/main/java/org/apache/commons/codec/language/Caverphone1.java @@ -33,12 +33,19 @@ public class Caverphone1 extends AbstractCaverphone { private static final String SIX_1 = "111111"; + /** + * Constructs a new instance. + */ + public Caverphone1() { + // empty + } + /** * Encodes the given String into a Caverphone value. * * @param source * String the source string - * @return A caverphone code for the given String + * @return A Caverphone code for the given String */ @Override public String encode(final String source) { diff --git a/src/main/java/org/apache/commons/codec/language/Caverphone2.java b/src/main/java/org/apache/commons/codec/language/Caverphone2.java index 318ce10012..b4fe12c1d5 100644 --- a/src/main/java/org/apache/commons/codec/language/Caverphone2.java +++ b/src/main/java/org/apache/commons/codec/language/Caverphone2.java @@ -33,12 +33,19 @@ public class Caverphone2 extends AbstractCaverphone { private static final String TEN_1 = "1111111111"; + /** + * Constructs a new instance. + */ + public Caverphone2() { + // empty + } + /** * Encodes the given String into a Caverphone 2.0 value. * * @param source * String the source string - * @return A caverphone code for the given String + * @return A Caverphone code for the given String */ @Override public String encode(final String source) { diff --git a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java index 05b0af6a16..10cffc48c8 100644 --- a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java +++ b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java @@ -305,6 +305,13 @@ private static boolean arrayContains(final char[] arr, final char key) { return false; } + /** + * Constructs a new instance. + */ + public ColognePhonetic() { + // empty + } + /** *

* Implements the Kölner Phonetik algorithm. diff --git a/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java b/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java index 24880c7adc..e784ec165b 100644 --- a/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java +++ b/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java @@ -37,7 +37,7 @@ public class DoubleMetaphone implements StringEncoder { /** - * Inner class for storing results, since there is the optional alternate encoding. + * Stores results, since there is the optional alternate encoding. */ public class DoubleMetaphoneResult { @@ -45,36 +45,73 @@ public class DoubleMetaphoneResult { private final StringBuilder alternate = new StringBuilder(getMaxCodeLen()); private final int maxLength; + /** + * Constructs a new instance. + * + * @param maxLength The maximum length. + */ public DoubleMetaphoneResult(final int maxLength) { this.maxLength = maxLength; } + /** + * Appends the given value as primary and alternative. + * + * @param value The value to append. + */ public void append(final char value) { appendPrimary(value); appendAlternate(value); } + /** + * Appends the given primary and alternative values. + * + * @param primary The primary value. + * @param alternate The alternate value. + */ public void append(final char primary, final char alternate) { appendPrimary(primary); appendAlternate(alternate); } + /** + * Appends the given value as primary and alternative. + * + * @param value The value to append. + */ public void append(final String value) { appendPrimary(value); appendAlternate(value); } + /** + * Appends the given primary and alternative values. + * + * @param primary The primary value. + * @param alternate The alternate value. + */ public void append(final String primary, final String alternate) { appendPrimary(primary); appendAlternate(alternate); } + /** + * Appends the given value as alternative. + * + * @param value The value to append. + */ public void appendAlternate(final char value) { if (this.alternate.length() < this.maxLength) { this.alternate.append(value); } } + /** + * Appends the given value as alternative. + * + * @param value The value to append. + */ public void appendAlternate(final String value) { final int addChars = this.maxLength - this.alternate.length(); if (value.length() <= addChars) { @@ -84,12 +121,22 @@ public void appendAlternate(final String value) { } } + /** + * Appends the given value as primary. + * + * @param value The value to append. + */ public void appendPrimary(final char value) { if (this.primary.length() < this.maxLength) { this.primary.append(value); } } + /** + * Appends the given value as primary. + * + * @param value The value to append. + */ public void appendPrimary(final String value) { final int addChars = this.maxLength - this.primary.length(); if (value.length() <= addChars) { @@ -99,47 +146,61 @@ public void appendPrimary(final String value) { } } + /** + * Gets the alternate string. + * + * @return the alternate string. + */ public String getAlternate() { return this.alternate.toString(); } + /** + * Gets the primary string. + * + * @return the primary string. + */ public String getPrimary() { return this.primary.toString(); } + /** + * Tests whether this result is complete. + * + * @return whether this result is complete. + */ public boolean isComplete() { - return this.primary.length() >= this.maxLength && - this.alternate.length() >= this.maxLength; + return this.primary.length() >= this.maxLength && this.alternate.length() >= this.maxLength; } } /** - * "Vowels" to test for + * "Vowels" to test. */ private static final String VOWELS = "AEIOUY"; + /** - * Prefixes when present which are not pronounced + * Prefixes when present which are not pronounced. */ - private static final String[] SILENT_START = - { "GN", "KN", "PN", "WR", "PS" }; - private static final String[] L_R_N_M_B_H_F_V_W_SPACE = - { "L", "R", "N", "M", "B", "H", "F", "V", "W", " " }; - private static final String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER = - { "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER" }; + private static final String[] SILENT_START = { "GN", "KN", "PN", "WR", "PS" }; - private static final String[] L_T_K_S_N_M_B_Z = - { "L", "T", "K", "S", "N", "M", "B", "Z" }; + private static final String[] L_R_N_M_B_H_F_V_W_SPACE = { "L", "R", "N", "M", "B", "H", "F", "V", "W", " " }; + private static final String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER = { "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER" }; + private static final String[] L_T_K_S_N_M_B_Z = { "L", "T", "K", "S", "N", "M", "B", "Z" }; - /* - * Determines whether {@code value} contains any of the criteria starting at index {@code start} and - * matching up to length {@code length}. + /** + * Tests whether {@code value} contains any of the {@code criteria} starting at index {@code start} and matching up to length {@code length}. + * + * @param value The value to test. + * @param start Where in {@code value} to start testing. + * @param length How many to test. + * @param criteria The search criteria. + * @return Whether there was a match. */ - protected static boolean contains(final String value, final int start, final int length, - final String... criteria) { + protected static boolean contains(final String value, final int start, final int length, final String... criteria) { boolean result = false; if (start >= 0 && start + length <= value.length()) { final String target = value.substring(start, start + length); - for (final String element : criteria) { if (target.equals(element)) { result = true; @@ -155,10 +216,19 @@ protected static boolean contains(final String value, final int start, final int */ private int maxCodeLen = 4; - /* - * Gets the character at index {@code index} if available, otherwise - * it returns {@code Character.MIN_VALUE} so that there is some sort - * of default. + /** + * Constructs a new instance. + */ + public DoubleMetaphone() { + // empty + } + + /** + * Gets the character at index {@code index} if available, or {@link Character#MIN_VALUE} if out of bounds. + * + * @param value The String to query. + * @param index A string index. + * @return The character at the index or {@link Character#MIN_VALUE} if out of bounds. */ protected char charAt(final String value, final int index) { if (index < 0 || index >= value.length()) { diff --git a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java index 5374cecf9e..3163ece966 100644 --- a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java +++ b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java @@ -62,6 +62,13 @@ public class MatchRatingApproachEncoder implements StringEncoder { { "BB", "CC", "DD", "FF", "GG", "HH", "JJ", "KK", "LL", "MM", "NN", "PP", "QQ", "RR", "SS", "TT", "VV", "WW", "XX", "YY", "ZZ" }; + /** + * Constructs a new instance. + */ + public MatchRatingApproachEncoder() { + // empty + } + /** * Cleans up a name: 1. Upper-cases everything 2. Removes some common punctuation 3. Removes accents 4. Removes any * spaces. diff --git a/src/main/java/org/apache/commons/codec/language/Metaphone.java b/src/main/java/org/apache/commons/codec/language/Metaphone.java index c95bd140d3..1dd58233e1 100644 --- a/src/main/java/org/apache/commons/codec/language/Metaphone.java +++ b/src/main/java/org/apache/commons/codec/language/Metaphone.java @@ -74,6 +74,13 @@ public class Metaphone implements StringEncoder { */ private int maxCodeLen = 4; + /** + * Constructs a new instance. + */ + public Metaphone() { + // empty + } + /** * Encodes an Object using the metaphone algorithm. This method * is provided in order to satisfy the requirements of the diff --git a/src/main/java/org/apache/commons/codec/language/bm/BeiderMorseEncoder.java b/src/main/java/org/apache/commons/codec/language/bm/BeiderMorseEncoder.java index 08df642148..025eb9ecbc 100644 --- a/src/main/java/org/apache/commons/codec/language/bm/BeiderMorseEncoder.java +++ b/src/main/java/org/apache/commons/codec/language/bm/BeiderMorseEncoder.java @@ -75,17 +75,25 @@ * @see Reference implementation * *

- * This class is Not ThreadSafe + * This class is Not ThreadSafe. *

* @since 1.6 */ public class BeiderMorseEncoder implements StringEncoder { + // Implementation note: This class is a spring-friendly facade to PhoneticEngine. It allows read/write configuration // of an immutable PhoneticEngine instance that will be delegated to for the actual encoding. // a cached object private PhoneticEngine engine = new PhoneticEngine(NameType.GENERIC, RuleType.APPROX, true); + /** + * Constructs a new instance. + */ + public BeiderMorseEncoder() { + // empty + } + @Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { diff --git a/src/main/java/org/apache/commons/codec/language/bm/Languages.java b/src/main/java/org/apache/commons/codec/language/bm/Languages.java index 479693c3b7..61b2846202 100644 --- a/src/main/java/org/apache/commons/codec/language/bm/Languages.java +++ b/src/main/java/org/apache/commons/codec/language/bm/Languages.java @@ -74,6 +74,13 @@ public static LanguageSet from(final Set langs) { return langs.isEmpty() ? NO_LANGUAGES : new SomeLanguages(langs); } + /** + * Constructs a new instance for subclasses. + */ + public LanguageSet() { + // empty + } + public abstract boolean contains(String language); public abstract String getAny(); @@ -162,6 +169,7 @@ public String toString() { * No languages at all. */ public static final LanguageSet NO_LANGUAGES = new LanguageSet() { + @Override public boolean contains(final String language) { return false; @@ -202,6 +210,7 @@ public String toString() { * Any/all languages. */ public static final LanguageSet ANY_LANGUAGE = new LanguageSet() { + @Override public boolean contains(final String language) { return true;