public class Soundex
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private char[] |
soundexMapping
Every letter of the alphabet is "mapped" to a numerical value.
|
static Soundex |
US_ENGLISH
An instance of Soundex using the US_ENGLISH_MAPPING mapping.
|
private static char[] |
US_ENGLISH_MAPPING
This is a default mapping of the 26 letters used in US English.
|
static java.lang.String |
US_ENGLISH_MAPPING_STRING
This is a default mapping of the 26 letters used in US English.
|
Constructor and Description |
---|
Soundex()
Creates an instance using US_ENGLISH_MAPPING
|
Soundex(char[] mapping)
Creates a soundex instance using the given mapping.
|
Soundex(java.lang.String mapping)
Creates a refined soundex instance using a custom mapping.
|
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.String |
clean(java.lang.String str)
Cleans up the input string before Soundex processing by only returning
upper case letters.
|
(package private) static int |
difference(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.
|
int |
difference(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.
|
(package private) 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.
|
java.lang.Object |
encode(java.lang.Object pObject)
Encodes an Object using the soundex algorithm.
|
java.lang.String |
encode(java.lang.String pString)
Encodes a String using the soundex algorithm.
|
private char |
getMappingCode(java.lang.String str,
int index)
Used internally by the SoundEx algorithm.
|
private char[] |
getSoundexMapping()
Returns the soundex mapping.
|
private char |
map(char ch)
Maps the given upper-case character to its Soundex code.
|
java.lang.String |
soundex(java.lang.String str)
Retrieves the Soundex code for a given String object.
|
public static final java.lang.String US_ENGLISH_MAPPING_STRING
0
for a letter position
means do not encode.
(This constant is provided as both an implementation convenience and to allow Javadoc to pick up the value for the constant values page.)
US_ENGLISH_MAPPING
,
Constant Field Valuesprivate static final char[] US_ENGLISH_MAPPING
0
for a letter position
means do not encode.Soundex(char[])
public static final Soundex US_ENGLISH
US_ENGLISH_MAPPING
private final char[] soundexMapping
public Soundex()
Soundex(char[])
,
US_ENGLISH_MAPPING
public Soundex(char[] mapping)
mapping
- Mapping array to use when finding the corresponding code for a given characterpublic Soundex(java.lang.String mapping)
mapping
- Mapping string to use when finding the corresponding code for a given characterpublic int difference(java.lang.String s1, java.lang.String s2) throws EncoderException
s1
- A String that will be encoded and compared.s2
- A String that will be encoded and compared.EncoderException
- if an error occurs encoding one of the stringsSoundexUtils#difference(StringEncoder,String,String)
,
MS
T-SQL DIFFERENCE public java.lang.Object encode(java.lang.Object pObject) throws EncoderException
pObject
- Object to encodeEncoderException
- if the parameter supplied is not of type java.lang.Stringjava.lang.IllegalArgumentException
- if a character is not mappedpublic java.lang.String encode(java.lang.String pString)
pString
- A String object to encodejava.lang.IllegalArgumentException
- if a character is not mappedprivate char getMappingCode(java.lang.String str, int index)
str
- the cleaned working string to encode (in upper case).index
- the character position to encodejava.lang.IllegalArgumentException
- if the character is not mappedprivate char[] getSoundexMapping()
private char map(char ch)
ch
- An upper-case character.java.lang.IllegalArgumentException
- Thrown if ch
is not mapped.public java.lang.String soundex(java.lang.String str)
str
- String to encode using the Soundex algorithmjava.lang.IllegalArgumentException
- if a character is not mappedstatic java.lang.String clean(java.lang.String str)
str
- The String to clean.static int difference(StringEncoder encoder, java.lang.String s1, java.lang.String s2) throws EncoderException
encoder
- The encoder to use to encode the Strings.s1
- A String that will be encoded and compared.s2
- A String that will be encoded and compared.EncoderException
- if an error occurs encoding one of the stringsdifferenceEncoded(String,String)
,
MS T-SQL DIFFERENCEstatic int differenceEncoded(java.lang.String es1, java.lang.String es2)
es1
- An encoded String.es2
- An encoded String.