Class DoubleMetaphone
- java.lang.Object
-
- org.apache.commons.codec.language.DoubleMetaphone
-
- All Implemented Interfaces:
Encoder,StringEncoder
public class DoubleMetaphone extends java.lang.Object implements 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 invokesetMaxCodeLen(int)after initial setup.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDoubleMetaphone.DoubleMetaphoneResultInner class for storing results, since there is the optional alternate encoding.
-
Constructor Summary
Constructors Constructor Description DoubleMetaphone()Creates an instance of this DoubleMetaphone encoder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringdoubleMetaphone(java.lang.String value)Encode a value with Double Metaphone.java.lang.StringdoubleMetaphone(java.lang.String value, boolean alternate)Encode a value with Double Metaphone, optionally using the alternate encoding.java.lang.Objectencode(java.lang.Object obj)Encode the value using DoubleMetaphone.java.lang.Stringencode(java.lang.String value)Encode the value using DoubleMetaphone.intgetMaxCodeLen()Returns the maxCodeLen.booleanisDoubleMetaphoneEqual(java.lang.String value1, java.lang.String value2)Check if the Double Metaphone values of twoStringvalues are equal.booleanisDoubleMetaphoneEqual(java.lang.String value1, java.lang.String value2, boolean alternate)Check if the Double Metaphone values of twoStringvalues are equal, optionally using the alternate value.voidsetMaxCodeLen(int maxCodeLen)Sets the maxCodeLen.
-
-
-
Method Detail
-
doubleMetaphone
public java.lang.String doubleMetaphone(java.lang.String value)
Encode a value with Double Metaphone.- Parameters:
value- String to encode- Returns:
- an encoded string
-
doubleMetaphone
public java.lang.String doubleMetaphone(java.lang.String value, boolean alternate)Encode a value with Double Metaphone, optionally using the alternate encoding.- Parameters:
value- String to encodealternate- use alternate encode- Returns:
- an encoded string
-
encode
public java.lang.Object encode(java.lang.Object obj) throws EncoderExceptionEncode 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
public java.lang.String encode(java.lang.String value)
Encode the value using DoubleMetaphone.- Specified by:
encodein interfaceStringEncoder- Parameters:
value- String to encode- Returns:
- An encoded String
-
isDoubleMetaphoneEqual
public boolean isDoubleMetaphoneEqual(java.lang.String value1, java.lang.String value2)Check if 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(String,String,boolean)
-
isDoubleMetaphoneEqual
public boolean isDoubleMetaphoneEqual(java.lang.String value1, java.lang.String value2, boolean alternate)Check if 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.
-
getMaxCodeLen
public int getMaxCodeLen()
Returns the maxCodeLen.- Returns:
- int
-
setMaxCodeLen
public void setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.- Parameters:
maxCodeLen- The maxCodeLen to set
-
-