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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassStores results, since there is the optional alternate encoding. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected charGets the character at indexindexif available, orCharacter.MIN_VALUEif out of bounds.protected static booleanTests whethervaluecontains any of thecriteriastarting at indexstartand matching up to lengthlength.doubleMetaphone(String value) Encodes a value with Double Metaphone.doubleMetaphone(String value, boolean alternate) Encodes a value with Double Metaphone, optionally using the alternate encoding.Encodes the value using DoubleMetaphone.Encodes the value using DoubleMetaphone.intGets the maxCodeLen.booleanisDoubleMetaphoneEqual(String value1, String value2) Tests whether the Double Metaphone values of twoStringvalues are equal.booleanisDoubleMetaphoneEqual(String value1, String value2, boolean alternate) Tests whether the Double Metaphone values of twoStringvalues are equal, optionally using the alternate value.voidsetMaxCodeLen(int maxCodeLen) Sets the maxCodeLen.
-
Constructor Details
-
DoubleMetaphone
public DoubleMetaphone()Constructs a new instance.
-
-
Method Details
-
contains
Tests whethervaluecontains any of thecriteriastarting at indexstartand matching up to lengthlength.- Parameters:
value- The value to test.start- Where invalueto start testing.length- How many to test.criteria- The search criteria.- Returns:
- Whether there was a match.
-
charAt
Gets the character at indexindexif available, orCharacter.MIN_VALUEif out of bounds.- Parameters:
value- The String to query.index- A string index.- Returns:
- The character at the index or
Character.MIN_VALUEif out of bounds.
-
doubleMetaphone
Encodes a value with Double Metaphone.- Parameters:
value- String to encode.- Returns:
- an encoded string.
-
doubleMetaphone
Encodes a value with Double Metaphone, optionally using the alternate encoding.- Parameters:
value- String to encode.alternate- use alternate encode.- Returns:
- an encoded string.
-
encode
Encodes the value using DoubleMetaphone. It will only work ifobjis aString(likeMetaphone).- Specified by:
encodein 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
Encodes the value using DoubleMetaphone.- Specified by:
encodein interfaceStringEncoder- Parameters:
value- String to encode.- Returns:
- An encoded String.
-
getMaxCodeLen
Gets the maxCodeLen.- Returns:
- the maxCodeLen.
-
isDoubleMetaphoneEqual
Tests whether the Double Metaphone values of twoStringvalues are equal.- Parameters:
value1- The left-hand side of the encodedString.equals(Object).value2- The right-hand side of the encodedString.equals(Object).- Returns:
trueif the encodedStrings are equal;falseotherwise.- See Also:
-
isDoubleMetaphoneEqual
Tests whether the Double Metaphone values of twoStringvalues 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:
trueif the encodedStrings are equal;falseotherwise.
-
setMaxCodeLen
Sets the maxCodeLen.- Parameters:
maxCodeLen- The maxCodeLen to set.
-