Class DoubleMetaphone

    • Field Detail

      • SILENT_START

        private static final java.lang.String[] SILENT_START
        Prefixes when present which are not pronounced.
      • L_R_N_M_B_H_F_V_W_SPACE

        private static final java.lang.String[] L_R_N_M_B_H_F_V_W_SPACE
      • ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER

        private static final java.lang.String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER
      • L_T_K_S_N_M_B_Z

        private static final java.lang.String[] L_T_K_S_N_M_B_Z
      • maxCodeLen

        private int maxCodeLen
        Maximum length of an encoding, default is 4.
    • Constructor Detail

      • DoubleMetaphone

        public DoubleMetaphone()
        Constructs a new instance.
    • Method Detail

      • contains

        protected static boolean contains​(java.lang.String value,
                                          int start,
                                          int length,
                                          java.lang.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​(java.lang.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.
      • cleanInput

        private java.lang.String cleanInput​(java.lang.String input)
        Cleans the input.
      • conditionC0

        private boolean conditionC0​(java.lang.String value,
                                    int index)
        Complex condition 0 for 'C'.
      • conditionCH0

        private boolean conditionCH0​(java.lang.String value,
                                     int index)
        Complex condition 0 for 'CH'.
      • conditionCH1

        private boolean conditionCH1​(java.lang.String value,
                                     int index)
        Complex condition 1 for 'CH'.
      • conditionL0

        private boolean conditionL0​(java.lang.String value,
                                    int index)
        Complex condition 0 for 'L'.
      • conditionM0

        private boolean conditionM0​(java.lang.String value,
                                    int index)
        Complex condition 0 for 'M'.
      • doubleMetaphone

        public java.lang.String doubleMetaphone​(java.lang.String value)
        Encodes a value with Double Metaphone.
        Parameters:
        value - String to encode.
        Returns:
        an encoded string.
      • doubleMetaphone

        public java.lang.String doubleMetaphone​(java.lang.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 java.lang.Object encode​(java.lang.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 java.lang.String encode​(java.lang.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​(java.lang.String value1,
                                              java.lang.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 Strings are equal; false otherwise.
        See Also:
        isDoubleMetaphoneEqual(String,String,boolean)
      • isDoubleMetaphoneEqual

        public boolean isDoubleMetaphoneEqual​(java.lang.String value1,
                                              java.lang.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 Strings are equal; false otherwise.
      • isSilentStart

        private boolean isSilentStart​(java.lang.String value)
        Tests whether or not the value starts with a silent letter. It will return true if the value starts with any of 'GN', 'KN', 'PN', 'WR' or 'PS'.
      • isSlavoGermanic

        private boolean isSlavoGermanic​(java.lang.String value)
        Tests whether or not a value is of slavo-germanic origin. A value is of Slavo-Germanic origin if it contains any of 'W', 'K', 'CZ', or 'WITZ'.
      • isVowel

        private boolean isVowel​(char ch)
        Tests whether or not a character is a vowel or not.
      • setMaxCodeLen

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