Record Class DateRange

java.lang.Object
java.lang.Record
limn.components.date.DateRange
Record Components:
start - the first day of the period, included
end - the last day of the period, included; never before start

public record DateRange(LocalDate start, LocalDate end) extends Record
A period between two days, both ends included.

Normalized on construction, so start() is never after end(): a range is a span of days rather than a record of which end the user clicked first, and a widget that let the two disagree would make every reader of a range write the same three-line swap.

A half-made range is not one. While a person is picking a period the calendar holds an anchor and a preview, and neither is a DateRange; CalendarView.selectedRange() answers null until the second end is chosen. That is the whole reason both components here are non-null: a type whose end may be missing is a type every caller has to null-check for a state that is never published.

  • Constructor Details

    • DateRange

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

    • of

      public static DateRange of(LocalDate a, LocalDate b)
      The period between two days, in whichever order they arrive. This is what a calendar builds from an anchor and the day the second click landed on, and dragging a selection backwards is ordinary rather than an error.
      Parameters:
      a - one end
      b - the other
      Returns:
      the period covering both, ends included
    • ofDay

      public static DateRange ofDay(LocalDate day)
      A period of one day.
    • contains

      public boolean contains(@Nullable LocalDate day)
      Parameters:
      day - a day, or null
      Returns:
      whether it falls inside this period, both ends included; false for null, so a caller holding an unset value needs no guard of its own
    • days

      public long days()
      Returns:
      how many days the period covers, counting both ends; never less than 1
    • 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.
    • start

      public LocalDate start()
      Returns the value of the start record component.
      Returns:
      the value of the start record component
    • end

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