Record Class MaskPattern

java.lang.Object
java.lang.Record
cloud.opencode.base.string.desensitize.strategy.MaskPattern

public record MaskPattern(int startKeep, int endKeep, char maskChar) extends Record
Mask Pattern - Record defining masking pattern configuration. 掩码模式 - 定义掩码模式配置的记录。

Features | 主要功能:

  • Configurable start/end keep lengths - 可配置首尾保留长度
  • Configurable mask character - 可配置掩码字符
  • Predefined patterns (MOBILE, ID_CARD, etc.) - 预定义模式

Usage Examples | 使用示例:

MaskPattern pattern = new MaskPattern(3, 4, '*');
MaskPattern mobile = MaskPattern.MOBILE; // keep first 3, last 4

Security | 安全性:

  • Thread-safe: Yes (record is immutable) - 线程安全: 是(记录不可变)
Since:
JDK 25, opencode-base-string V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

  • Constructor Details

    • MaskPattern

      public MaskPattern(int startKeep, int endKeep, char maskChar)
      Creates an instance of a MaskPattern record class.
      Parameters:
      startKeep - the value for the startKeep record component
      endKeep - the value for the endKeep record component
      maskChar - the value for the maskChar record component
  • Method Details

    • 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. All components in this record class 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.
    • startKeep

      public int startKeep()
      Returns the value of the startKeep record component.
      Returns:
      the value of the startKeep record component
    • endKeep

      public int endKeep()
      Returns the value of the endKeep record component.
      Returns:
      the value of the endKeep record component
    • maskChar

      public char maskChar()
      Returns the value of the maskChar record component.
      Returns:
      the value of the maskChar record component