Class DoubleMetaphone
java.lang.Object
org.apache.commons.codec.language.DoubleMetaphone
- All Implemented Interfaces:
Encoder,StringEncoder
public class DoubleMetaphone extends Object implements StringEncoder
Encodes a string into a double metaphone value.
This Implementation is based on the algorithm by Lawrence Philips.
- Original Article: http://www.cuj.com/documents/s=8038/cuj0006philips/
- Original Source Code: ftp://ftp.cuj.com/pub/2000/1806/philips.zip
- Version:
- $Id: DoubleMetaphone.java,v 1.24 2004/06/05 18:32:04 ggregory Exp $
- Author:
- Apache Software Foundation
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDoubleMetaphone.DoubleMetaphoneResultInner class for storing results, since there is the optional alternate encoding. -
Field Summary
Fields Modifier and Type Field Description protected intmaxCodeLenMaximum length of an encoding, default is 4 -
Constructor Summary
Constructors Constructor Description DoubleMetaphone()Creates an instance of this DoubleMetaphone encoder -
Method Summary
Modifier and Type Method Description protected charcharAt(String value, int index)Gets the character at indexindexif available, otherwise it returnsCharacter.MIN_VALUEso that there is some sort of a defaultprotected static booleancontains(String value, int start, int length, String[] criteria)Determines whethervaluecontains any of the criteria starting at indexstartand matching up to lengthlengthStringdoubleMetaphone(String value)Encode a value with Double MetaphoneStringdoubleMetaphone(String value, boolean alternate)Encode a value with Double Metaphone, optionally using the alternate encoding.Objectencode(Object obj)Encode the value using DoubleMetaphone.Stringencode(String value)Encode the value using DoubleMetaphone.intgetMaxCodeLen()Returns the maxCodeLen.booleanisDoubleMetaphoneEqual(String value1, String value2)Check if the Double Metaphone values of twoStringvalues are equal.booleanisDoubleMetaphoneEqual(String value1, 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.
-
Field Details
-
maxCodeLen
protected int maxCodeLenMaximum length of an encoding, default is 4
-
-
Constructor Details
-
DoubleMetaphone
public DoubleMetaphone()Creates an instance of this DoubleMetaphone encoder
-
-
Method Details
-
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 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
Encode the value using DoubleMetaphone.- Specified by:
encodein interfaceStringEncoder- Parameters:
value- String to encode- Returns:
- An encoded String
-
isDoubleMetaphoneEqual
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
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
-
charAt
Gets the character at indexindexif available, otherwise it returnsCharacter.MIN_VALUEso that there is some sort of a default -
contains
Determines whethervaluecontains any of the criteria starting at indexstartand matching up to lengthlength
-