DoubleMetaphone (Apache Commons Codec 1.22.1 API)
Description: declaration: package: org.apache.commons.codec.language, class: DoubleMetaphone

Package org.apache.commons.codec.language

# 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.

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:
  - Dr. Dobbs Original Article
  - Wikipedia Metaphone
  - Double Metaphone C++ source by Lawrence Philips

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `DoubleMetaphone.DoubleMetaphoneResult`
  Stores results, since there is the optional alternate encoding.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DoubleMetaphone()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected char`
  `charAt(String value, int index)`
  Gets the character at index `index` if available, or `Character.MIN_VALUE` if out of bounds.
  `protected static boolean`
  `contains(String value, int start, int length, String... criteria)`
  Tests whether `value` contains any of the `criteria` starting at index `start` and matching up to length `length`.
  `String`
  `doubleMetaphone(String value)`
  Encodes a value with Double Metaphone.
  `String`
  `doubleMetaphone(String value, boolean alternate)`
  Encodes a value with Double Metaphone, optionally using the alternate encoding.
  `Object`
  `encode(Object obj)`
  Encodes the value using DoubleMetaphone.
  `String`
  `encode(String value)`
  Encodes the value using DoubleMetaphone.
  `int`
  `getMaxCodeLen()`
  Gets the maxCodeLen.
  `boolean`
  `isDoubleMetaphoneEqual(String value1, String value2)`
  Tests whether the Double Metaphone values of two `String` values are equal.
  `boolean`
  `isDoubleMetaphoneEqual(String value1, String value2, boolean alternate)`
  Tests whether 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`

- ## Constructor Details

  - ### DoubleMetaphone

    public DoubleMetaphone()
    Constructs a new instance.

- ## Method Details

  - ### contains

    protected static boolean contains(String value, int start, int length, String... criteria)
    Tests whether `value` contains any of the `criteria` starting at index `start` and matching up to length `length`.
    Parameters:
      `value` - The value to test.
      `start` - Where in `value` to start testing.
      `length` - How many to test.
      `criteria` - The search criteria.
    Returns:
      Whether there was a match.

  - ### charAt

    protected char charAt(String value, int index)
    Gets the character at index `index` if available, or `Character.MIN_VALUE` if out of bounds.
    Parameters:
      `value` - The String to query.
      `index` - A string index.
    Returns:
      The character at the index or `Character.MIN_VALUE` if out of bounds.

  - ### doubleMetaphone

    public String doubleMetaphone(String value)
    Encodes a value with Double Metaphone.
    Parameters:
      `value` - String to encode.
    Returns:
      An encoded string.

  - ### doubleMetaphone

    public String doubleMetaphone(String value, boolean alternate)
    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

    public Object encode(Object obj) throws EncoderException
    Encodes 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` - encode parameter is not of type String.

  - ### encode

    public String encode(String value)
    Encodes the value using DoubleMetaphone.
    Specified by:
      `encode` in interface `StringEncoder`
    Parameters:
      `value` - String to encode.
    Returns:
      An encoded String.

  - ### getMaxCodeLen

    public int getMaxCodeLen()
    Gets the maxCodeLen.
    Returns:
      The maxCodeLen.

  - ### isDoubleMetaphoneEqual

    public boolean isDoubleMetaphoneEqual(String value1, String value2)
    Tests whether the Double Metaphone values of two `String` values are equal.
    Parameters:
      `value1` - The left-hand side of the encoded `String.equals(Object)`.
      `value2` - The right-hand side of the encoded `String.equals(Object)`.
    Returns:
      `true` if the encoded `String`s are equal; `false` otherwise.
    See Also:
      - `isDoubleMetaphoneEqual(String,String,boolean)`

  - ### isDoubleMetaphoneEqual

    public boolean isDoubleMetaphoneEqual(String value1, String value2, boolean alternate)
    Tests whether the Double Metaphone values of two `String` values are equal, optionally using the alternate value.
    Parameters:
      `value1` - The left-hand side of the encoded `String.equals(Object)`.
      `value2` - The right-hand side of the encoded `String.equals(Object)`.
      `alternate` - use the alternate value if `true`.
    Returns:
      `true` if the encoded `String`s are equal; `false` otherwise.

  - ### setMaxCodeLen

    public void setMaxCodeLen(int maxCodeLen)
    Sets the maxCodeLen.
    Parameters:
      `maxCodeLen` - The maxCodeLen to set.