Record Class TimeWindow

java.lang.Object
java.lang.Record
com.inductiveautomation.historian.common.model.TimeWindow
Record Components:
size - the size of the window
unit - the chronological unit of the window

public record TimeWindow(long size, ChronoUnit unit) extends Record
Represents a window of time with a size and unit. Provides conversion utilities between different time units.
  • Constructor Details

    • TimeWindow

      public TimeWindow(long size, ChronoUnit unit)
      Creates a new TimeWindow with validation.
  • Method Details

    • ofMillis

      public static TimeWindow ofMillis(long size)
      Factory methods for common time windows.
    • ofSeconds

      public static TimeWindow ofSeconds(long size)
    • ofMinutes

      public static TimeWindow ofMinutes(long size)
    • ofHours

      public static TimeWindow ofHours(long size)
    • ofDays

      public static TimeWindow ofDays(long size)
    • ofWeeks

      public static TimeWindow ofWeeks(long size)
    • ofMonths

      public static TimeWindow ofMonths(long size)
    • ofYears

      public static TimeWindow ofYears(long size)
    • of

      public static TimeWindow of(long size, ChronoUnit unit)
    • of

      public static TimeWindow of(Duration duration)
      Creates a TimeWindow from a Duration.
    • toMillis

      public long toMillis()
      Conversion methods to different time units.
    • toSeconds

      public long toSeconds()
    • toMinutes

      public long toMinutes()
    • toHours

      public long toHours()
    • toDays

      public long toDays()
    • toWeeks

      public long toWeeks()
    • toMonths

      public long toMonths()
    • toYears

      public long toYears()
    • toDuration

      public Duration toDuration()
      Converts this window to a Duration if possible.
      Returns:
      the duration representation of this window
      Throws:
      UnsupportedOperationException - if the unit is not time-based
    • withUnit

      public TimeWindow withUnit(ChronoUnit newUnit)
      Creates a new TimeWindow with a different unit.
    • toString

      public 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • size

      public long size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component
    • unit

      public ChronoUnit unit()
      Returns the value of the unit record component.
      Returns:
      the value of the unit record component