Java String Difference differenceEncoded(String es1, String es2)

Here you can find the source of differenceEncoded(String es1, String es2)

Description

Returns the number of characters in the two Soundex encoded Strings that are the same.

License

Apache License

Parameter

Parameter Description
es1 An encoded String.
es2 An encoded String.

Return

The number of characters in the two Soundex encoded Strings that are the same.

Declaration

static int differenceEncoded(String es1, String es2) 

Method Source Code

//package com.java2s;
/*/*from  w w  w  .ja va 2  s . c  om*/
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
    * Returns the number of characters in the two Soundex encoded Strings that
    * are the same.
    * <ul>
    * <li>For Soundex, this return value ranges from 0 through 4: 0 indicates
    * little or no similarity, and 4 indicates strong similarity or identical
    * values.</li>
    * <li>For refined Soundex, the return value can be greater than 4.</li>
    * </ul>
    * 
    * @param es1
    *                  An encoded String.
    * @param es2
    *                  An encoded String.
    * @return The number of characters in the two Soundex encoded Strings that
    *             are the same.
    * 
    * @see <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_de-dz_8co5.asp">
    *          MS T-SQL DIFFERENCE</a>
    */
    static int differenceEncoded(String es1, String es2) {

        if (es1 == null || es2 == null) {
            return 0;
        }
        int lengthToMatch = Math.min(es1.length(), es2.length());
        int diff = 0;
        for (int i = 0; i < lengthToMatch; i++) {
            if (es1.charAt(i) == es2.charAt(i)) {
                diff++;
            }
        }
        return diff;
    }
}

Related

  1. difference(String str1, String str2)
  2. difference(String str1, String str2)
  3. difference(String string1, String string2)
  4. difference(String xpath1, String xpath2)
  5. differenceAt(String s1, String s2)
  6. differenceEncoded(String es1, String es2)