public class DoubleMetaphone extends Object implements StringEncoder
This class is conditionally thread-safe. The instance field maxCodeLen
is mutable
setMaxCodeLen(int)
but is not volatile, and accesses are not synchronized. If an instance of the class is
shared between threads, the caller needs to ensure that suitable synchronization is used to ensure safe publication
of the value between threads, and must not invoke setMaxCodeLen(int)
after initial setup.
Modifier and Type | Class and Description |
---|---|
class |
DoubleMetaphone.DoubleMetaphoneResult
Inner class for storing results, since there is the optional alternate encoding.
|
Modifier and Type | Field and Description |
---|---|
private static String[] |
ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER |
private static String[] |
L_R_N_M_B_H_F_V_W_SPACE |
private static String[] |
L_T_K_S_N_M_B_Z |
private int |
maxCodeLen
Maximum length of an encoding, default is 4
|
private static String[] |
SILENT_START
Prefixes when present which are not pronounced
|
private static String |
VOWELS
"Vowels" to test for
|
Constructor and Description |
---|
DoubleMetaphone()
Creates an instance of this DoubleMetaphone encoder
|
Modifier and Type | Method and Description |
---|---|
protected char |
charAt(String value,
int index)
Gets the character at index
index if available, otherwise
it returns Character.MIN_VALUE so that there is some sort
of a default. |
private String |
cleanInput(String input)
Cleans the input.
|
private boolean |
conditionC0(String value,
int index)
Complex condition 0 for 'C'.
|
private boolean |
conditionCH0(String value,
int index)
Complex condition 0 for 'CH'.
|
private boolean |
conditionCH1(String value,
int index)
Complex condition 1 for 'CH'.
|
private boolean |
conditionL0(String value,
int index)
Complex condition 0 for 'L'.
|
private boolean |
conditionM0(String value,
int index)
Complex condition 0 for 'M'.
|
protected static boolean |
contains(String value,
int start,
int length,
String... criteria)
Determines whether
value contains any of the criteria starting at index start and
matching up to length length . |
String |
doubleMetaphone(String value)
Encode a value with Double Metaphone.
|
String |
doubleMetaphone(String value,
boolean alternate)
Encode a value with Double Metaphone, optionally using the alternate encoding.
|
Object |
encode(Object obj)
Encode the value using DoubleMetaphone.
|
String |
encode(String value)
Encode the value using DoubleMetaphone.
|
int |
getMaxCodeLen()
Returns the maxCodeLen.
|
private int |
handleAEIOUY(DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'A', 'E', 'I', 'O', 'U', and 'Y' cases.
|
private int |
handleC(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'C' cases.
|
private int |
handleCC(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'CC' cases.
|
private int |
handleCH(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'CH' cases.
|
private int |
handleD(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'D' cases.
|
private int |
handleG(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index,
boolean slavoGermanic)
Handles 'G' cases.
|
private int |
handleGH(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'GH' cases.
|
private int |
handleH(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'H' cases.
|
private int |
handleJ(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index,
boolean slavoGermanic)
Handles 'J' cases.
|
private int |
handleL(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'L' cases.
|
private int |
handleP(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'P' cases.
|
private int |
handleR(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index,
boolean slavoGermanic)
Handles 'R' cases.
|
private int |
handleS(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index,
boolean slavoGermanic)
Handles 'S' cases.
|
private int |
handleSC(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'SC' cases.
|
private int |
handleT(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'T' cases.
|
private int |
handleW(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'W' cases.
|
private int |
handleX(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index)
Handles 'X' cases.
|
private int |
handleZ(String value,
DoubleMetaphone.DoubleMetaphoneResult result,
int index,
boolean slavoGermanic)
Handles 'Z' cases.
|
boolean |
isDoubleMetaphoneEqual(String value1,
String value2)
Check if the Double Metaphone values of two
String values
are equal. |
boolean |
isDoubleMetaphoneEqual(String value1,
String value2,
boolean alternate)
Check if the Double Metaphone values of two
String values
are equal, optionally using the alternate value. |
private boolean |
isSilentStart(String value)
Determines whether or not the value starts with a silent letter.
|
private boolean |
isSlavoGermanic(String value)
Determines whether or not a value is of slavo-germanic origin.
|
private boolean |
isVowel(char ch)
Determines whether or not a character is a vowel or not
|
void |
setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.
|
private static final String VOWELS
private static final String[] SILENT_START
private static final String[] L_R_N_M_B_H_F_V_W_SPACE
private static final String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER
private static final String[] L_T_K_S_N_M_B_Z
private int maxCodeLen
public DoubleMetaphone()
public String doubleMetaphone(String value)
value
- String to encodepublic String doubleMetaphone(String value, boolean alternate)
value
- String to encodealternate
- use alternate encodepublic Object encode(Object obj) throws EncoderException
obj
is a String
(like Metaphone
).encode
in interface Encoder
obj
- Object to encode (should be of type String)EncoderException
- encode parameter is not of type Stringpublic String encode(String value)
encode
in interface StringEncoder
value
- String to encodepublic boolean isDoubleMetaphoneEqual(String value1, String value2)
String
values
are equal.value1
- The left-hand side of the encoded String.equals(Object)
.value2
- The right-hand side of the encoded String.equals(Object)
.true
if the encoded String
s are equal;
false
otherwise.isDoubleMetaphoneEqual(String,String,boolean)
public boolean isDoubleMetaphoneEqual(String value1, String value2, boolean alternate)
String
values
are equal, optionally using the alternate value.value1
- The left-hand side of the encoded String.equals(Object)
.value2
- The right-hand side of the encoded String.equals(Object)
.alternate
- use the alternate value if true
.true
if the encoded String
s are equal;
false
otherwise.public int getMaxCodeLen()
public void setMaxCodeLen(int maxCodeLen)
maxCodeLen
- The maxCodeLen to setprivate int handleAEIOUY(DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleC(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleCC(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleCH(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleD(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleG(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index, boolean slavoGermanic)
private int handleGH(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleH(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleJ(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index, boolean slavoGermanic)
private int handleL(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleP(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleR(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index, boolean slavoGermanic)
private int handleS(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index, boolean slavoGermanic)
private int handleSC(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleT(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleW(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleX(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index)
private int handleZ(String value, DoubleMetaphone.DoubleMetaphoneResult result, int index, boolean slavoGermanic)
private boolean conditionC0(String value, int index)
private boolean conditionCH0(String value, int index)
private boolean conditionCH1(String value, int index)
private boolean conditionL0(String value, int index)
private boolean conditionM0(String value, int index)
private boolean isSlavoGermanic(String value)
private boolean isVowel(char ch)
private boolean isSilentStart(String value)
true
if the value starts with any of 'GN', 'KN',
'PN', 'WR' or 'PS'.private String cleanInput(String input)
protected char charAt(String value, int index)
index
if available, otherwise
it returns Character.MIN_VALUE
so that there is some sort
of a default.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses