Record Class TimeWindow
java.lang.Object
java.lang.Record
com.inductiveautomation.historian.common.model.TimeWindow
- Record Components:
size- the size of the windowunit- the chronological unit of the window
Represents a window of time with a size and unit.
Provides conversion utilities between different time units.
-
Constructor Summary
ConstructorsConstructorDescriptionTimeWindow(long size, ChronoUnit unit) Creates a new TimeWindow with validation. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static TimeWindowof(long size, ChronoUnit unit) static TimeWindowCreates a TimeWindow from a Duration.static TimeWindowofDays(long size) static TimeWindowofHours(long size) static TimeWindowofMillis(long size) Factory methods for common time windows.static TimeWindowofMinutes(long size) static TimeWindowofMonths(long size) static TimeWindowofSeconds(long size) static TimeWindowofWeeks(long size) static TimeWindowofYears(long size) longsize()Returns the value of thesizerecord component.longtoDays()Converts this window to a Duration if possible.longtoHours()longtoMillis()Conversion methods to different time units.longlongtoMonths()longtoString()Returns a string representation of this record class.longtoWeeks()longtoYears()unit()Returns the value of theunitrecord component.withUnit(ChronoUnit newUnit) Creates a new TimeWindow with a different unit.
-
Constructor Details
-
TimeWindow
Creates a new TimeWindow with validation.
-
-
Method Details
-
ofMillis
Factory methods for common time windows. -
ofSeconds
-
ofMinutes
-
ofHours
-
ofDays
-
ofWeeks
-
ofMonths
-
ofYears
-
of
-
of
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
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
Creates a new TimeWindow with a different unit. -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
size
public long size()Returns the value of thesizerecord component.- Returns:
- the value of the
sizerecord component
-
unit
Returns the value of theunitrecord component.- Returns:
- the value of the
unitrecord component
-