public class

DoubleMetaphone

extends Object
implements StringEncoder
java.lang.Object
   ↳ org.apache.commons.codec.language.DoubleMetaphone

Class Overview

Encodes a string into a double metaphone value. This Implementation is based on the algorithm by Lawrence Philips.

Summary

Nested Classes
class DoubleMetaphone.DoubleMetaphoneResult Inner class for storing results, since there is the optional alternate encoding. 
Fields
protected int maxCodeLen Maximum length of an encoding, default is 4
Public Constructors
DoubleMetaphone()
Creates an instance of this DoubleMetaphone encoder
Public Methods
String doubleMetaphone(String value, boolean alternate)
Encode a value with Double Metaphone, optionally using the alternate encoding.
String doubleMetaphone(String value)
Encode a value with Double Metaphone
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.
Protected Methods
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
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
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.commons.codec.Encoder
From interface org.apache.commons.codec.StringEncoder

Fields

protected int maxCodeLen

Maximum length of an encoding, default is 4

Public Constructors

public DoubleMetaphone ()

Creates an instance of this DoubleMetaphone encoder

Public Methods

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

public String doubleMetaphone (String value)

Encode a value with Double Metaphone

Parameters
value String to encode
Returns
  • an encoded string

public Object encode (Object obj)

Encode the value using DoubleMetaphone. It will only work if obj is a String (like Metaphone).

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

public String encode (String value)

Encode the value using DoubleMetaphone.

Parameters
value String to encode
Returns
  • An encoded String

public int getMaxCodeLen ()

Returns the maxCodeLen.

Returns
  • int

public boolean isDoubleMetaphoneEqual (String value1, String value2)

Check if the Double Metaphone values of two String values are equal.

Parameters
value1 The left-hand side of the encoded equals(Object).
value2 The right-hand side of the encoded equals(Object).
Returns
  • true if the encoded Strings are equal; false otherwise.

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.

Parameters
value1 The left-hand side of the encoded equals(Object).
value2 The right-hand side of the encoded equals(Object).
alternate use the alternate value if true.
Returns
  • true if the encoded Strings are equal; false otherwise.

public void setMaxCodeLen (int maxCodeLen)

Sets the maxCodeLen.

Parameters
maxCodeLen The maxCodeLen to set

Protected Methods

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