Record Class FuzzyMatch<T>

java.lang.Object
java.lang.Record
cloud.opencode.base.string.match.FuzzyMatch<T>
Type Parameters:
T - the type of the matched item | 匹配项目的类型
Record Components:
item - the matched item | 匹配的项目
key - the string key used for matching | 用于匹配的字符串键
score - the similarity score (0.0 - 1.0) | 相似度分数(0.0 - 1.0)

Security | 安全性:

  • Thread-safe: Yes (record is immutable) - 线程安全: 是(记录不可变)

public record FuzzyMatch<T>(T item, String key, double score) extends Record
Fuzzy Match Result - Represents a fuzzy matching result 模糊匹配结果 - 表示一个模糊匹配的结果

Contains the matched item, its string key, and the similarity score.

包含匹配的项目、其字符串键和相似度分数。

Features | 主要功能:

  • Score as percentage display - 分数百分比显示
  • Match strength classification (exact, strong, weak) - 匹配强度分类

Usage Examples | 使用示例:

FuzzyMatch<String> match = ...;
String item = match.item();    // The matched item
String key = match.key();      // The string used for matching
double score = match.score();  // Similarity score (0.0 - 1.0)
Since:
JDK 25, opencode-base-string V1.2.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    FuzzyMatch(T item, String key, double score)
    Creates an instance of a FuzzyMatch record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Checks if this is an exact match.
    boolean
    Checks if this is a strong match (score >= 0.8).
    boolean
    Checks if this is a weak match (score < 0.6).
    Returns the value of the item record component.
    key()
    Returns the value of the key record component.
    double
    Returns the value of the score record component.
    Returns a formatted score as percentage.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FuzzyMatch

      public FuzzyMatch(T item, String key, double score)
      Creates an instance of a FuzzyMatch record class.
      Parameters:
      item - the value for the item record component
      key - the value for the key record component
      score - the value for the score record component
  • Method Details

    • scoreAsPercent

      public String scoreAsPercent()
      Returns a formatted score as percentage. 返回格式化为百分比的分数。
      Returns:
      score as percentage string | 百分比字符串形式的分数
    • isExactMatch

      public boolean isExactMatch()
      Checks if this is an exact match. 检查是否为精确匹配。
      Returns:
      true if score is 1.0 | 如果分数为1.0则返回true
    • isStrongMatch

      public boolean isStrongMatch()
      Checks if this is a strong match (score >= 0.8). 检查是否为强匹配(分数 >= 0.8)。
      Returns:
      true if score >= 0.8 | 如果分数 >= 0.8则返回true
    • isWeakMatch

      public boolean isWeakMatch()
      Checks if this is a weak match (score < 0.6). 检查是否为弱匹配(分数 < 0.6)。
      Returns:
      true if score < 0.6 | 如果分数小于 0.6 则返回 true
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • item

      public T item()
      Returns the value of the item record component.
      Returns:
      the value of the item record component
    • key

      public String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • score

      public double score()
      Returns the value of the score record component.
      Returns:
      the value of the score record component