Class DoubleMetaphone
java.lang.Object
org.apache.commons.codec.language.DoubleMetaphone
- All Implemented Interfaces:
Encoder
,StringEncoder
Encodes a string into a double metaphone value. This Implementation is based on the algorithm by Lawrence
Philips.
This class is conditionally thread-safe. The instance field for the maximum code length 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Inner class for storing results, since there is the optional alternate encoding. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected char
protected static boolean
doubleMetaphone
(String value) Encode a value with Double Metaphone.doubleMetaphone
(String value, boolean alternate) Encode a value with Double Metaphone, optionally using the alternate encoding.Encode the value using DoubleMetaphone.Encode the value using DoubleMetaphone.int
Returns the maxCodeLen.boolean
isDoubleMetaphoneEqual
(String value1, String value2) Check if the Double Metaphone values of twoString
values are equal.boolean
isDoubleMetaphoneEqual
(String value1, String value2, boolean alternate) Check if the Double Metaphone values of twoString
values are equal, optionally using the alternate value.void
setMaxCodeLen
(int maxCodeLen) Sets the maxCodeLen.
-
Constructor Details
-
DoubleMetaphone
public DoubleMetaphone()
-
-
Method Details
-
contains
-
charAt
-
doubleMetaphone
Encode a value with Double Metaphone.- Parameters:
value
- String to encode- Returns:
- an encoded string
-
doubleMetaphone
Encode a value with Double Metaphone, optionally using the alternate encoding.- Parameters:
value
- String to encodealternate
- use alternate encode- Returns:
- an encoded string
-
encode
Encode the value using DoubleMetaphone. It will only work ifobj
is aString
(likeMetaphone
).- Specified by:
encode
in interfaceEncoder
- Parameters:
obj
- Object to encode (should be of type String)- Returns:
- An encoded Object (will be of type String)
- Throws:
EncoderException
- encode parameter is not of type String
-
encode
Encode the value using DoubleMetaphone.- Specified by:
encode
in interfaceStringEncoder
- Parameters:
value
- String to encode- Returns:
- An encoded String
-
getMaxCodeLen
Returns the maxCodeLen.- Returns:
- int
-
isDoubleMetaphoneEqual
Check if the Double Metaphone values of twoString
values are equal.- Parameters:
value1
- The left-hand side of the encodedString.equals(Object)
.value2
- The right-hand side of the encodedString.equals(Object)
.- Returns:
true
if the encodedString
s are equal;false
otherwise.- See Also:
-
isDoubleMetaphoneEqual
Check if the Double Metaphone values of twoString
values are equal, optionally using the alternate value.- Parameters:
value1
- The left-hand side of the encodedString.equals(Object)
.value2
- The right-hand side of the encodedString.equals(Object)
.alternate
- use the alternate value iftrue
.- Returns:
true
if the encodedString
s are equal;false
otherwise.
-
setMaxCodeLen
Sets the maxCodeLen.- Parameters:
maxCodeLen
- The maxCodeLen to set
-