org.apache.commons.codec.language
Class DoubleMetaphone

java.lang.Object
  extended byorg.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.

Version:
$Id: DoubleMetaphone.java,v 1.14 2003/11/07 23:12:54 ggregory Exp $
Author:
Benjamin Walstrum, Gary Gregory

Nested Class Summary
 class DoubleMetaphone.DoubleMetaphoneResult
          Inner class for storing results, since there is the optional alternate encoding.
 
Field Summary
protected  int maxCodeLen
          Maximum length of an encoding, default is 4
 
Constructor Summary
DoubleMetaphone()
          Creates an instance of this DoubleMetaphone encoder
 
Method Summary
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
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.
 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
 void setMaxCodeLen(int maxCodeLen)
          Sets the maxCodeLen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxCodeLen

protected int maxCodeLen
Maximum length of an encoding, default is 4

Constructor Detail

DoubleMetaphone

public DoubleMetaphone()
Creates an instance of this DoubleMetaphone encoder

Method Detail

doubleMetaphone

public String doubleMetaphone(String value)
Encode a value with Double Metaphone

Parameters:
value - String to encode
Returns:
an encoded string

doubleMetaphone

public String doubleMetaphone(String value,
                              boolean alternate)
Encode a value with Double Metaphone, optionally using the alternate encoding.

Parameters:
value - String to encode
alternate - use alternate encode
Returns:
an encoded string

encode

public Object encode(Object obj)
              throws EncoderException
Encode the value using DoubleMetaphone. It will only work if obj is a String (like Metaphone).

Specified by:
encode in interface Encoder
Parameters:
obj - Object to encode (should be of type String)
Returns:
An encoded Object (will be of type String)
Throws:
EncoderException - an encoder exception is thrown if the encoder experiences a failure condition during the encoding process.

encode

public String encode(String value)
Encode the value using DoubleMetaphone.

Specified by:
encode in interface StringEncoder
Parameters:
value - String to encode
Returns:
An encoded String
Throws:
EncoderException - thrown if there is an exception during the encoding process.

isDoubleMetaphoneEqual

public boolean isDoubleMetaphoneEqual(String value1,
                                      String value2)
Check if the Double Metaphone values of two String values are equal


isDoubleMetaphoneEqual

public 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


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

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


contains

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



Copyright © 2002-2003 Apache Software Foundation. All Rights Reserved.