Class Holiday

java.lang.Object
cloud.opencode.base.date.holiday.Holiday
All Implemented Interfaces:
Serializable, Comparable<Holiday>

public final class Holiday extends Object implements Comparable<Holiday>, Serializable
Represents a holiday with date and metadata 表示带有日期和元数据的假日

This class represents a single holiday with its date, name, type, and additional information.

此类表示单个假日,包含其日期、名称、类型和附加信息。

Features | 主要功能:

  • Holiday date and name - 假日日期和名称
  • Holiday type classification - 假日类型分类
  • Observed date support - 调休日期支持
  • Multi-language support - 多语言支持

Usage Examples | 使用示例:

Holiday newYear = Holiday.of(
    LocalDate.of(2024, 1, 1),
    "New Year's Day",
    HolidayType.PUBLIC
);

Holiday springFestival = Holiday.builder()
    .date(LocalDate.of(2024, 2, 10))
    .name("Spring Festival")
    .chineseName("春节")
    .type(HolidayType.PUBLIC)
    .build();

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Yes (with explicit null checks in builder) - 空值安全: 是(构建器中有明确的空值检查)
Since:
JDK 25, opencode-base-date V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • of

      public static Holiday of(LocalDate date, String name)
      Creates a simple holiday 创建简单假日
      Parameters:
      date - the date | 日期
      name - the name | 名称
      Returns:
      the Holiday | 假日
    • of

      public static Holiday of(LocalDate date, String name, Holiday.HolidayType type)
      Creates a holiday with type 创建带类型的假日
      Parameters:
      date - the date | 日期
      name - the name | 名称
      type - the type | 类型
      Returns:
      the Holiday | 假日
    • of

      public static Holiday of(LocalDate date, String name, String chineseName, Holiday.HolidayType type)
      Creates a holiday with bilingual names 创建双语名称的假日
      Parameters:
      date - the date | 日期
      name - the English name | 英文名称
      chineseName - the Chinese name | 中文名称
      type - the type | 类型
      Returns:
      the Holiday | 假日
    • builder

      public static Holiday.Builder builder()
      Creates a builder 创建构建器
      Returns:
      the builder | 构建器
    • getDate

      public LocalDate getDate()
      Gets the date 获取日期
      Returns:
      the date | 日期
    • getName

      public String getName()
      Gets the name 获取名称
      Returns:
      the name | 名称
    • getChineseName

      public String getChineseName()
      Gets the Chinese name 获取中文名称
      Returns:
      the Chinese name, or null if not set | 中文名称,如果未设置则为null
    • getLocalizedName

      public String getLocalizedName(boolean preferChinese)
      Gets the localized name 获取本地化名称
      Parameters:
      preferChinese - whether to prefer Chinese | 是否偏好中文
      Returns:
      the localized name | 本地化名称
    • getType

      public Holiday.HolidayType getType()
      Gets the type 获取类型
      Returns:
      the type | 类型
    • getObservedDate

      public LocalDate getObservedDate()
      Gets the observed date 获取调休日期
      Returns:
      the observed date, or the actual date if not set | 调休日期,如果未设置则返回实际日期
    • isDayOff

      public boolean isDayOff()
      Checks if this is a day off 检查是否放假
      Returns:
      true if day off | 如果放假返回true
    • getDescription

      public String getDescription()
      Gets the description 获取描述
      Returns:
      the description, or null if not set | 描述,如果未设置则为null
    • isOn

      public boolean isOn(LocalDate date)
      Checks if the holiday falls on the specified date 检查假日是否在指定日期
      Parameters:
      date - the date to check | 要检查的日期
      Returns:
      true if on this date | 如果在此日期返回true
    • isPublicHoliday

      public boolean isPublicHoliday()
      Checks if this is a public holiday 检查是否为公共假日
      Returns:
      true if public holiday | 如果是公共假日返回true
    • getYear

      public int getYear()
      Gets the year of the holiday 获取假日的年份
      Returns:
      the year | 年份
    • compareTo

      public int compareTo(Holiday other)
      Specified by:
      compareTo in interface Comparable<Holiday>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object