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 boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.static TimeWindow
of
(long size, ChronoUnit unit) static TimeWindow
Creates a TimeWindow from a Duration.static TimeWindow
ofDays
(long size) static TimeWindow
ofHours
(long size) static TimeWindow
ofMillis
(long size) Factory methods for common time windows.static TimeWindow
ofMinutes
(long size) static TimeWindow
ofMonths
(long size) static TimeWindow
ofSeconds
(long size) static TimeWindow
ofWeeks
(long size) static TimeWindow
ofYears
(long size) long
size()
Returns the value of thesize
record component.long
toDays()
Converts this window to a Duration if possible.long
toHours()
long
toMillis()
Conversion methods to different time units.long
long
toMonths()
long
toString()
Returns a string representation of this record class.long
toWeeks()
long
toYears()
unit()
Returns the value of theunit
record 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 thesize
record component.- Returns:
- the value of the
size
record component
-
unit
Returns the value of theunit
record component.- Returns:
- the value of the
unit
record component
-