Enum Class SearchAlgorithm

java.lang.Object
java.lang.Enum<SearchAlgorithm>
tk.airshipcraft.commonlib.utils.search.SearchAlgorithm
All Implemented Interfaces:
Serializable, Comparable<SearchAlgorithm>, Constable, StringDistance

public enum SearchAlgorithm extends Enum<SearchAlgorithm> implements StringDistance
Enumerates available string distance algorithms which can be used to compare similarity or dissimilarity between two strings. Each algorithm follows the StringDistance interface to provide a standardized approach for calculation.
Since:
2023-06-23
Version:
1.0.0
Author:
notzune
  • Enum Constant Details

    • NORMALIZED_LEVENSHTEIN

      public static final SearchAlgorithm NORMALIZED_LEVENSHTEIN
      Normalized Levenshtein distance algorithm.
    • DUKE_JARO_WINKLER

      public static final SearchAlgorithm DUKE_JARO_WINKLER
      Jaro-Winkler distance algorithm.
  • Field Details

    • NAMES

      public static final @Unmodifiable Map<String,SearchAlgorithm> NAMES
      A map of search algorithm names to their corresponding SearchAlgorithm enum constants. This allows for easy lookup and usage of search algorithms by their name.
  • Method Details

    • values

      public static SearchAlgorithm[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SearchAlgorithm valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • calculate

      public double calculate(byte @NotNull [] x, byte @NotNull [] y)
      Calculates the string distance between two sequences of bytes using the associated algorithm. The result is negated to transform a distance measure into a similarity score where a higher value means greater similarity.
      Specified by:
      calculate in interface StringDistance
      Parameters:
      x - The first byte array.
      y - The second byte array.
      Returns:
      The negated string distance, interpreted as a similarity score.