Skip to content

Commit

Permalink
Added missing javadoc for Nysiis, renamed trueLength to strict
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1298987 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
netomi committed Mar 9, 2012
1 parent 00530c9 commit 89de3df
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions src/main/java/org/apache/commons/codec/language/Nysiis.java
Expand Up @@ -166,28 +166,44 @@ private static char[] transcodeRemaining(final char prev, final char curr, final
return new char[] { curr };
}

private final boolean trueLength;
/** Indicates the strict mode. */
private final boolean strict;

/**
* Creates an instance of the {@link Nysiis} encoder with strict mode (original form),
* i.e. encoded strings have a maximum length of 6.
*/
public Nysiis() {
this(true);
}

public Nysiis(boolean trueLength) {
this.trueLength = trueLength;
/**
* Create an instance of the {@link Nysiis} encoder with the specified strict mode:
*
* <ul>
* <li><code>true</code>: encoded strings have a maximum length of 6</li>
* <li><code>false</code>: encoded strings may have arbitrary length</li>
* </ul>
*
* @param strict
* the strict mode
*/
public Nysiis(final boolean strict) {
this.strict = strict;
}

/**
* Encodes an Object using the NYSIIS algorithm. This method is provided in order to satisfy the requirements of the
* Encoder interface, and will throw an {@link EncoderException} if the supplied object is not of type
* {@link String}.
*
*
* @param pObject
* Object to encode
* @return An object (or a {@link String}) containing the NYSIIS code which corresponds to the given String.
* @throws EncoderException
* if the parameter supplied is not of a {@link String}
* if the parameter supplied is not of a {@link String}
* @throws IllegalArgumentException
* if a character is not mapped
* if a character is not mapped
*/
public Object encode(Object pObject) throws EncoderException {
if (!(pObject instanceof String)) {
Expand All @@ -198,24 +214,29 @@ public Object encode(Object pObject) throws EncoderException {

/**
* Encodes a String using the NYSIIS algorithm.
*
*
* @param pString
* A String object to encode
* @return A Nysiis code corresponding to the String supplied
* @throws IllegalArgumentException
* if a character is not mapped
* if a character is not mapped
*/
public String encode(String pString) {
return this.nysiis(pString);
}

public boolean isTrueLength() {
return this.trueLength;
/**
* Indicates the strict mode for this {@link Nysiis} encoder.
*
* @return <code>true</code> if the encoder is configured for strict mode, <code>false</code> otherwise
*/
public boolean isStrict() {
return this.strict;
}

/**
* Retrieves the NYSIIS code for a given String object.
*
*
* @param str
* String to encode using the NYSIIS algorithm
* @return A NYSIIS code for the String supplied
Expand All @@ -239,7 +260,7 @@ public String nysiis(String str) {
str = PAT_K.matcher(str).replaceFirst("C");
str = PAT_PH_PF.matcher(str).replaceFirst("FF");
str = PAT_SCH.matcher(str).replaceFirst("SSS");

// Translate last characters of name:
// EE -> Y, IE -> Y, DT | RT | RD | NT | ND -> D
str = PAT_EE_IE.matcher(str).replaceFirst("Y");
Expand Down Expand Up @@ -289,7 +310,7 @@ public String nysiis(String str) {
}

final String string = key.toString();
return this.isTrueLength() ? string.substring(0, Math.min(TRUE_LENGTH, string.length())) : string;
return this.isStrict() ? string.substring(0, Math.min(TRUE_LENGTH, string.length())) : string;
}

}

0 comments on commit 89de3df

Please sign in to comment.