Package de.xima.fc.common.bean_models
Class TimeDuration
java.lang.Object
de.xima.fc.common.bean_models.TimeDuration
- All Implemented Interfaces:
Serializable
,Comparable<TimeDuration>
Model class with bean validation for a duration. Consists of a value and a unit of time.
- Since:
- 8.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Custom label for thegetDuration()
property.static interface
Custom label for thegetUnit()
property. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(TimeDuration that) boolean
Gets the duration, interpreted according to the configured unit of time.getUnit()
Gets the unit of time for the duration.int
hashCode()
static TimeDuration
Creates a new instance ofTimeDuration
with the given duration and unit of time.static TimeDuration
ofDays
(long duration) Creates a new instance ofTimeDuration
with the given duration in days.static TimeDuration
Creates a new instance ofTimeDuration
with no duration and the given unit of time.static TimeDuration
ofHours
(long duration) Creates a new instance ofTimeDuration
with the given duration in hours.static TimeDuration
ofMicroseconds
(long duration) Creates a new instance ofTimeDuration
with the given duration in microseconds.static TimeDuration
ofMilliseconds
(long duration) Creates a new instance ofTimeDuration
with the given duration in milliseconds.static TimeDuration
ofMinutes
(long duration) Creates a new instance ofTimeDuration
with the given duration in minutes.static TimeDuration
ofNanoseconds
(long duration) Creates a new instance ofTimeDuration
with the given duration in nanoseconds.static TimeDuration
ofSeconds
(long duration) Creates a new instance ofTimeDuration
with the given duration in seconds.static TimeDuration
ofWeeks
(long duration) Creates a new instance ofTimeDuration
with the given duration in weeks.void
setDuration
(Long duration) Sets the duration, interpreted according to the configured unit of time.void
Sets the unit of time for the duration.long
Converts the duration to the given unit of time.long
toDays()
Gets the duration in days.Converts this duration to aDuration
.long
toHours()
Gets the duration in hours.long
Gets the duration in microseconds.long
Gets the duration in milliseconds.long
Gets the duration in minutes.long
Gets the duration in nanoseconds.long
Gets the duration in seconds.long
toWeeks()
Gets the duration in weeks.
-
Constructor Details
-
TimeDuration
public TimeDuration()
-
-
Method Details
-
compareTo
- Specified by:
compareTo
in interfaceComparable<TimeDuration>
-
equals
-
getDuration
Gets the duration, interpreted according to the configured unit of time. A value of0
means no restriction (unlimited), a value of-1
means the default system timeout.May be
null
if the duration is not set.- Returns:
- The duration.
-
setDuration
Sets the duration, interpreted according to the configured unit of time. A value of0
means no restriction (unlimited), a value of-1
means the default system timeout.May be
null
if the duration is not set.- Parameters:
duration
- The duration.
-
getUnit
Gets the unit of time for the duration.- Returns:
- The unit of time for the duration.
-
setUnit
Sets the unit of time for the duration.- Parameters:
unit
- The unit of time for the duration.
-
hashCode
public int hashCode() -
to
Converts the duration to the given unit of time.- Parameters:
targetUnit
- The target unit of time.- Returns:
- The duration in the target unit of time.
-
toDays
public long toDays()Gets the duration in days.- Returns:
- The duration in days.
-
toDuration
Converts this duration to aDuration
.- Returns:
- A
Duration
object representing the same duration.
-
toHours
public long toHours()Gets the duration in hours.- Returns:
- The duration in hours.
-
toMicroseconds
public long toMicroseconds()Gets the duration in microseconds.- Returns:
- The duration in microseconds.
-
toMilliseconds
public long toMilliseconds()Gets the duration in milliseconds.- Returns:
- The duration in milliseconds.
-
toMinutes
public long toMinutes()Gets the duration in minutes.- Returns:
- The duration in minutes.
-
toNanoseconds
public long toNanoseconds()Gets the duration in nanoseconds.- Returns:
- The duration in nanoseconds.
-
toSeconds
public long toSeconds()Gets the duration in seconds.- Returns:
- The duration in seconds.
-
toWeeks
public long toWeeks()Gets the duration in weeks.- Returns:
- The duration in weeks.
-
of
Creates a new instance ofTimeDuration
with the given duration and unit of time.- Parameters:
duration
- The duration, interpreted according to the given unit of time.unit
- The unit of time for the duration.- Returns:
- A new instance of
TimeDuration
with the given duration and unit of time.
-
ofDays
Creates a new instance ofTimeDuration
with the given duration in days.- Parameters:
duration
- The duration in days.- Returns:
- A new instance of
TimeDuration
with the given duration in days.
-
ofEmpty
Creates a new instance ofTimeDuration
with no duration and the given unit of time.- Parameters:
unit
- The unit of time for the duration.- Returns:
- A new instance of
TimeDuration
with no duration and the given unit of time.
-
ofHours
Creates a new instance ofTimeDuration
with the given duration in hours.- Parameters:
duration
- The duration in hours.- Returns:
- A new instance of
TimeDuration
with the given duration in hours.
-
ofMicroseconds
Creates a new instance ofTimeDuration
with the given duration in microseconds.- Parameters:
duration
- The duration in microseconds.- Returns:
- A new instance of
TimeDuration
with the given duration in microseconds.
-
ofMilliseconds
Creates a new instance ofTimeDuration
with the given duration in milliseconds.- Parameters:
duration
- The duration in milliseconds.- Returns:
- A new instance of
TimeDuration
with the given duration in milliseconds.
-
ofMinutes
Creates a new instance ofTimeDuration
with the given duration in minutes.- Parameters:
duration
- The duration in minutes.- Returns:
- A new instance of
TimeDuration
with the given duration in minutes.
-
ofNanoseconds
Creates a new instance ofTimeDuration
with the given duration in nanoseconds.- Parameters:
duration
- The duration in nanoseconds.- Returns:
- A new instance of
TimeDuration
with the given duration in nanoseconds.
-
ofSeconds
Creates a new instance ofTimeDuration
with the given duration in seconds.- Parameters:
duration
- The duration in seconds.- Returns:
- A new instance of
TimeDuration
with the given duration in seconds.
-
ofWeeks
Creates a new instance ofTimeDuration
with the given duration in weeks.- Parameters:
duration
- The duration in weeks.- Returns:
- A new instance of
TimeDuration
with the given duration in weeks.
-