Record Class CronExplanation

java.lang.Object
java.lang.Record
cloud.opencode.base.cron.CronExplanation
Record Components:
expression - the original cron expression string | 原始Cron表达式字符串
description - a human-readable description of the expression | 表达式的人类可读描述
nextExecutions - the upcoming execution times (unmodifiable) | 即将到来的执行时间(不可修改)
estimatedInterval - the estimated interval between consecutive executions | 连续执行之间的预估间隔
All Implemented Interfaces:
Serializable

public record CronExplanation(String expression, String description, List<ZonedDateTime> nextExecutions, Duration estimatedInterval) extends Record implements Serializable
Cron Explanation - One-Stop Debugging Info Container for Cron Expressions Cron解释 - Cron表达式的一站式调试信息容器

An immutable record that bundles together all the information needed to understand and debug a cron expression: the original expression string, a human-readable description, upcoming execution times, and the estimated interval between executions.

一个不可变记录,将理解和调试Cron表达式所需的所有信息捆绑在一起: 原始表达式字符串、人类可读描述、即将到来的执行时间以及执行之间的预估间隔。

Features | 主要功能:

  • Immutable and thread-safe (Java record) - 不可变且线程安全(Java记录)
  • Unmodifiable next-executions list - 不可修改的下次执行列表
  • Formatted multi-line toString() for debugging - 格式化的多行toString()用于调试
  • Serializable for transport/storage - 可序列化用于传输/存储

Usage Examples | 使用示例:

CronExpression expr = CronExpression.parse("0 9 * * MON-FRI");
ZonedDateTime now = ZonedDateTime.now();
CronExplanation explanation = new CronExplanation(
    expr.getExpression(),
    expr.describe(),
    expr.nextExecutions(now, 5),
    Duration.ofHours(24)
);
System.out.println(explanation);
// Expression : 0 9 * * MON-FRI
// Description: At 09:00, Monday through Friday
// Interval   : PT24H
// Next executions:
//   1. 2026-04-03T09:00:00+08:00[Asia/Shanghai]
//   2. 2026-04-06T09:00:00+08:00[Asia/Shanghai]
//   ...

Security | 安全性:

  • Thread-safe: Yes (immutable record with defensive copy) - 线程安全: 是(不可变记录,防御性拷贝)
  • Null-safe: Yes (rejects null inputs) - 空值安全: 是
Since:
JDK 25, opencode-base-cron V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • CronExplanation

      public CronExplanation(String expression, String description, List<ZonedDateTime> nextExecutions, Duration estimatedInterval)
      Compact constructor — validates inputs and creates a defensive copy of the list. 紧凑构造器 — 验证输入并创建列表的防御性拷贝。
  • Method Details

    • toString

      public String toString()
      Returns a nicely formatted multi-line debug output. 返回格式良好的多行调试输出。
      Specified by:
      toString in class Record
      Returns:
      the formatted debug string | 格式化的调试字符串
    • 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.
    • expression

      public String expression()
      Returns the value of the expression record component.
      Returns:
      the value of the expression record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • nextExecutions

      public List<ZonedDateTime> nextExecutions()
      Returns the value of the nextExecutions record component.
      Returns:
      the value of the nextExecutions record component
    • estimatedInterval

      public Duration estimatedInterval()
      Returns the value of the estimatedInterval record component.
      Returns:
      the value of the estimatedInterval record component