You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by gg...@apache.org on 2004/06/02 02:55:29 UTC
cvs commit: jakarta-commons/codec/src/java/org/apache/commons/codec/language Soundex.java
ggregory 2004/06/01 17:55:29
Modified: codec/src/java/org/apache/commons/codec/language
Soundex.java
Log:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=29080
Throw an exception with a clear message.
Revision Changes Path
1.22 +9 -12 jakarta-commons/codec/src/java/org/apache/commons/codec/language/Soundex.java
Index: Soundex.java
===================================================================
RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/language/Soundex.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Soundex.java 17 Mar 2004 18:30:59 -0000 1.21
+++ Soundex.java 2 Jun 2004 00:55:29 -0000 1.22
@@ -117,17 +117,10 @@
* if the parameter supplied is not of type java.lang.String
*/
public Object encode(Object pObject) throws EncoderException {
-
- Object result;
-
- if (!(pObject instanceof java.lang.String)) {
+ if (!(pObject instanceof String)) {
throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String");
- } else {
- result = soundex((String) pObject);
- }
-
- return result;
-
+ }
+ return soundex((String) pObject);
}
/**
@@ -196,7 +189,11 @@
* @return A Soundex code.
*/
private char map(char c) {
- return this.getSoundexMapping()[c - 'A'];
+ int index = c - 'A';
+ if (index < 0 || index >= this.getSoundexMapping().length) {
+ throw new IllegalArgumentException("The character is not mapped: " + c);
+ }
+ return this.getSoundexMapping()[index];
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org