Home All Groups
commons-codec / org / apache / commons / codec / language / DoubleMetaphone.html /

Class 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 maxCodeLen 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.

    $Id: DoubleMetaphone.java 1544347 2013-11-21 22:30:31Z ggregory $
    See Also:
    Original Article, http://en.wikipedia.org/wiki/Metaphone
    • 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.
        value - String to encode
        an encoded string
      • doubleMetaphone

        public String doubleMetaphone(String value,
                             boolean alternate)
        Encode a value with Double Metaphone, optionally using the alternate encoding.
        value - String to encode
        alternate - use alternate encode
        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
        obj - Object to encode (should be of type String)
        An encoded Object (will be of type String)
        EncoderException - encode parameter is not of type String
      • encode

        public String encode(String value)
        Encode the value using DoubleMetaphone.
        Specified by:
        encode in interface  StringEncoder
        value - String to encode
        An encoded String
      • 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.
        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.
        true if the encoded Strings are equal; false otherwise.
      • getMaxCodeLen

        public int getMaxCodeLen()
        Returns the maxCodeLen.
      • setMaxCodeLen

        public void setMaxCodeLen(int maxCodeLen)
        Sets the maxCodeLen.
        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–2013 The Apache Software Foundation. All rights reserved.