SoundexUtilspublic final class SoundexUtils extends Object Utility methods for {@link Soundex} and {@link RefinedSoundex} classes. |
Methods Summary |
---|
static java.lang.String | clean(java.lang.String str)Cleans up the input string before Soundex processing by only returning
upper case letters.
if (str == null || str.length() == 0) {
return str;
}
int len = str.length();
char[] chars = new char[len];
int count = 0;
for (int i = 0; i < len; i++) {
if (Character.isLetter(str.charAt(i))) {
chars[count++] = str.charAt(i);
}
}
if (count == len) {
return str.toUpperCase();
}
return new String(chars, 0, count).toUpperCase();
| static int | difference(org.apache.commons.codec.StringEncoder encoder, java.lang.String s1, java.lang.String s2)Encodes the Strings and returns the number of characters in the two
encoded Strings that are the same.
- For Soundex, this return value ranges from 0 through 4: 0 indicates
little or no similarity, and 4 indicates strong similarity or identical
values.
- For refined Soundex, the return value can be greater than 4.
return differenceEncoded(encoder.encode(s1), encoder.encode(s2));
| static int | differenceEncoded(java.lang.String es1, java.lang.String es2)Returns the number of characters in the two Soundex encoded Strings that
are the same.
- For Soundex, this return value ranges from 0 through 4: 0 indicates
little or no similarity, and 4 indicates strong similarity or identical
values.
- For refined Soundex, the return value can be greater than 4.
if (es1 == null || es2 == null) {
return 0;
}
int lengthToMatch = Math.min(es1.length(), es2.length());
int diff = 0;
for (int i = 0; i < lengthToMatch; i++) {
if (es1.charAt(i) == es2.charAt(i)) {
diff++;
}
}
return diff;
|
|