@@ -166,28 +166,44 @@ private static char[] transcodeRemaining(final char prev, final char curr, final
166166 return new char [] { curr };
167167 }
168168
169- private final boolean trueLength ;
169+ /** Indicates the strict mode. */
170+ private final boolean strict ;
170171
172+ /**
173+ * Creates an instance of the {@link Nysiis} encoder with strict mode (original form),
174+ * i.e. encoded strings have a maximum length of 6.
175+ */
171176 public Nysiis () {
172177 this (true );
173178 }
174179
175- public Nysiis (boolean trueLength ) {
176- this .trueLength = trueLength ;
180+ /**
181+ * Create an instance of the {@link Nysiis} encoder with the specified strict mode:
182+ *
183+ * <ul>
184+ * <li><code>true</code>: encoded strings have a maximum length of 6</li>
185+ * <li><code>false</code>: encoded strings may have arbitrary length</li>
186+ * </ul>
187+ *
188+ * @param strict
189+ * the strict mode
190+ */
191+ public Nysiis (final boolean strict ) {
192+ this .strict = strict ;
177193 }
178194
179195 /**
180196 * Encodes an Object using the NYSIIS algorithm. This method is provided in order to satisfy the requirements of the
181197 * Encoder interface, and will throw an {@link EncoderException} if the supplied object is not of type
182198 * {@link String}.
183- *
199+ *
184200 * @param pObject
185201 * Object to encode
186202 * @return An object (or a {@link String}) containing the NYSIIS code which corresponds to the given String.
187203 * @throws EncoderException
188- * if the parameter supplied is not of a {@link String}
204+ * if the parameter supplied is not of a {@link String}
189205 * @throws IllegalArgumentException
190- * if a character is not mapped
206+ * if a character is not mapped
191207 */
192208 public Object encode (Object pObject ) throws EncoderException {
193209 if (!(pObject instanceof String )) {
@@ -198,24 +214,29 @@ public Object encode(Object pObject) throws EncoderException {
198214
199215 /**
200216 * Encodes a String using the NYSIIS algorithm.
201- *
217+ *
202218 * @param pString
203219 * A String object to encode
204220 * @return A Nysiis code corresponding to the String supplied
205221 * @throws IllegalArgumentException
206- * if a character is not mapped
222+ * if a character is not mapped
207223 */
208224 public String encode (String pString ) {
209225 return this .nysiis (pString );
210226 }
211227
212- public boolean isTrueLength () {
213- return this .trueLength ;
228+ /**
229+ * Indicates the strict mode for this {@link Nysiis} encoder.
230+ *
231+ * @return <code>true</code> if the encoder is configured for strict mode, <code>false</code> otherwise
232+ */
233+ public boolean isStrict () {
234+ return this .strict ;
214235 }
215236
216237 /**
217238 * Retrieves the NYSIIS code for a given String object.
218- *
239+ *
219240 * @param str
220241 * String to encode using the NYSIIS algorithm
221242 * @return A NYSIIS code for the String supplied
@@ -239,7 +260,7 @@ public String nysiis(String str) {
239260 str = PAT_K .matcher (str ).replaceFirst ("C" );
240261 str = PAT_PH_PF .matcher (str ).replaceFirst ("FF" );
241262 str = PAT_SCH .matcher (str ).replaceFirst ("SSS" );
242-
263+
243264 // Translate last characters of name:
244265 // EE -> Y, IE -> Y, DT | RT | RD | NT | ND -> D
245266 str = PAT_EE_IE .matcher (str ).replaceFirst ("Y" );
@@ -289,7 +310,7 @@ public String nysiis(String str) {
289310 }
290311
291312 final String string = key .toString ();
292- return this .isTrueLength () ? string .substring (0 , Math .min (TRUE_LENGTH , string .length ())) : string ;
313+ return this .isStrict () ? string .substring (0 , Math .min (TRUE_LENGTH , string .length ())) : string ;
293314 }
294315
295316}
0 commit comments