Record Class DateRange

java.lang.Object
java.lang.Record
net.tangly.core.DateRange
All Implemented Interfaces:
Serializable

public record DateRange(LocalDate from, LocalDate to) extends Record implements Serializable
Defines an absolute local date range. The range can be open, meaning either the lower or upper date can be null.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Tests if the date is inside the date interval specified in the filter.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final DateRange
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a fully open date range.
    Creates an instance of a DateRange record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the from record component.
    Creates a new data range with the given lower bound.
    final int
    Returns a hash code value for this object.
    boolean
    Returns true if the date now is in the time interval of the instance.
    boolean
    isActive(@NotNull LocalDate date)
    Returns true if the date is in the time interval of the instance.
    boolean
    Returns true if the date range is fully open.
    static DateRange
    of(LocalDate from, LocalDate to)
    Factory method.
    to()
    Returns the value of the to record component.
    Creates a new data range with the given upper bound.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    • INFINITE

      public static final DateRange INFINITE
  • Constructor Details

    • DateRange

      public DateRange()
      Creates a fully open date range.
    • DateRange

      public DateRange(LocalDate from, LocalDate to)
      Creates an instance of a DateRange record class.
      Parameters:
      from - the value for the from record component
      to - the value for the to record component
  • Method Details

    • of

      public static DateRange of(LocalDate from, LocalDate to)
      Factory method.
      Parameters:
      from - start of the date range. can be null
      to - end of the date range. can be null
      Returns:
      new date range
    • from

      public DateRange from(LocalDate from)
      Creates a new data range with the given lower bound.
      Parameters:
      from - new lower bound
      Returns:
      new date range with the given lower bound
      See Also:
    • to

      public DateRange to(LocalDate to)
      Creates a new data range with the given upper bound.
      Parameters:
      to - new upper bound
      Returns:
      new date range with the given upper bound
      See Also:
    • isActive

      public boolean isActive(@NotNull @NotNull LocalDate date)
      Returns true if the date is in the time interval of the instance.
      Parameters:
      date - date against which the inclusion test is evaluated
      Returns:
      true if inside the interval otherwise false
    • isActive

      public boolean isActive()
      Returns true if the date now is in the time interval of the instance.
      Returns:
      true if inside the interval otherwise false
    • isInfinite

      public boolean isInfinite()
      Returns true if the date range is fully open.
      Returns:
      true if the date range is open in both directions.
    • 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.
    • from

      public LocalDate from()
      Returns the value of the from record component.
      Returns:
      the value of the from record component
    • to

      public LocalDate to()
      Returns the value of the to record component.
      Returns:
      the value of the to record component