Record Class SmsTemplate

java.lang.Object
java.lang.Record
cloud.opencode.base.sms.template.SmsTemplate
Record Components:
id - the template ID | 模板ID
name - the template name | 模板名称
content - the template content | 模板内容
variableNames - the variable names | 变量名称列表

public record SmsTemplate(String id, String name, String content, List<String> variableNames) extends Record
SMS Template 短信模板

Template for SMS messages with variable substitution.

支持变量替换的短信消息模板。

Features | 主要功能:

  • Automatic variable name extraction from content - 从内容自动提取变量名
  • Variable substitution rendering - 变量替换渲染
  • Immutable record design - 不可变记录设计

Usage Examples | 使用示例:

SmsTemplate tpl = SmsTemplate.of("verify", "Your code is ${code}");
List<String> vars = tpl.variableNames(); // ["code"]

Security | 安全性:

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

    • SmsTemplate

      public SmsTemplate(String id, String name, String content, List<String> variableNames)
      Creates an instance of a SmsTemplate record class.
      Parameters:
      id - the value for the id record component
      name - the value for the name record component
      content - the value for the content record component
      variableNames - the value for the variableNames record component
  • Method Details

    • of

      public static SmsTemplate of(String id, String content)
      Create template from content 从内容创建模板
      Parameters:
      id - the template ID | 模板ID
      content - the content | 内容
      Returns:
      the template | 模板
    • of

      public static SmsTemplate of(String id, String name, String content)
      Create template with name 使用名称创建模板
      Parameters:
      id - the template ID | 模板ID
      name - the name | 名称
      content - the content | 内容
      Returns:
      the template | 模板
    • render

      public String render(Map<String,String> variables)
      Render template with variables 使用变量渲染模板
      Parameters:
      variables - the variables | 变量
      Returns:
      the rendered content | 渲染后的内容
    • hasAllVariables

      public boolean hasAllVariables(Map<String,String> variables)
      Check if all variables are provided 检查是否提供了所有变量
      Parameters:
      variables - the variables | 变量
      Returns:
      true if all provided | 如果全部提供返回true
    • getMissingVariables

      public List<String> getMissingVariables(Map<String,String> variables)
      Get missing variables 获取缺失的变量
      Parameters:
      variables - the variables | 变量
      Returns:
      the missing variable names | 缺失的变量名称
    • 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 Objects::equals(Object,Object).
      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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • content

      public String content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • variableNames

      public List<String> variableNames()
      Returns the value of the variableNames record component.
      Returns:
      the value of the variableNames record component