Class LevenshteinDistance

java.lang.Object
com.helger.commons.string.util.LevenshteinDistance

@Immutable public final class LevenshteinDistance extends Object
Utility class for calculating the Levenshtein distance of 2 strings.
Author:
Philip Helger
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getDistance(char[] aStr1, char[] aStr2)
    Get the distance of the 2 strings, using the costs 1 for insertion, deletion and substitution.
    static int
    getDistance(char[] aStr1, char[] aStr2, int nCostInsert, int nCostDelete, int nCostSubstitution)
     
    static int
    getDistance(String sStr1, String sStr2)
    Get the distance of the 2 strings, using the costs 1 for insertion, deletion and substitution.
    static int
    getDistance(String sStr1, String sStr2, int nCostInsert, int nCostDelete, int nCostSubstitution)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getDistance

      public static int getDistance(@Nullable char[] aStr1, @Nullable char[] aStr2)
      Get the distance of the 2 strings, using the costs 1 for insertion, deletion and substitution.
      Parameters:
      aStr1 - First string.
      aStr2 - Second string.
      Returns:
      The Levenshtein distance.
    • getDistance

      public static int getDistance(@Nullable char[] aStr1, @Nullable char[] aStr2, @Nonnegative int nCostInsert, @Nonnegative int nCostDelete, @Nonnegative int nCostSubstitution)
    • getDistance

      public static int getDistance(@Nullable String sStr1, @Nullable String sStr2)
      Get the distance of the 2 strings, using the costs 1 for insertion, deletion and substitution.
      Parameters:
      sStr1 - First string.
      sStr2 - second string.
      Returns:
      The Levenshtein distance.
    • getDistance

      public static int getDistance(@Nullable String sStr1, @Nullable String sStr2, @Nonnegative int nCostInsert, @Nonnegative int nCostDelete, @Nonnegative int nCostSubstitution)