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 interfaceCustom label for thegetDuration()property.static interfaceCustom label for thegetUnit()property. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(TimeDuration that) booleanGets the duration, interpreted according to the configured unit of time.getUnit()Gets the unit of time for the duration.inthashCode()static TimeDurationCreates a new instance ofTimeDurationwith the given duration and unit of time.static TimeDurationofDays(long duration) Creates a new instance ofTimeDurationwith the given duration in days.static TimeDurationCreates a new instance ofTimeDurationwith no duration and the given unit of time.static TimeDurationofHours(long duration) Creates a new instance ofTimeDurationwith the given duration in hours.static TimeDurationofMicroseconds(long duration) Creates a new instance ofTimeDurationwith the given duration in microseconds.static TimeDurationofMilliseconds(long duration) Creates a new instance ofTimeDurationwith the given duration in milliseconds.static TimeDurationofMinutes(long duration) Creates a new instance ofTimeDurationwith the given duration in minutes.static TimeDurationofNanoseconds(long duration) Creates a new instance ofTimeDurationwith the given duration in nanoseconds.static TimeDurationofSeconds(long duration) Creates a new instance ofTimeDurationwith the given duration in seconds.static TimeDurationofWeeks(long duration) Creates a new instance ofTimeDurationwith the given duration in weeks.voidsetDuration(Long duration) Sets the duration, interpreted according to the configured unit of time.voidSets the unit of time for the duration.longConverts the duration to the given unit of time.longtoDays()Gets the duration in days.Converts this duration to aDuration.longtoHours()Gets the duration in hours.longGets the duration in microseconds.longGets the duration in milliseconds.longGets the duration in minutes.longGets the duration in nanoseconds.longGets the duration in seconds.longtoWeeks()Gets the duration in weeks.
-
Constructor Details
-
TimeDuration
public TimeDuration()
-
-
Method Details
-
compareTo
- Specified by:
compareToin interfaceComparable<TimeDuration>
-
equals
-
getDuration
Gets the duration, interpreted according to the configured unit of time. A value of0means no restriction (unlimited), a value of-1means the default system timeout.May be
nullif the duration is not set.- Returns:
- The duration.
-
setDuration
Sets the duration, interpreted according to the configured unit of time. A value of0means no restriction (unlimited), a value of-1means the default system timeout.May be
nullif 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
Durationobject 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 ofTimeDurationwith 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
TimeDurationwith the given duration and unit of time.
-
ofDays
Creates a new instance ofTimeDurationwith the given duration in days.- Parameters:
duration- The duration in days.- Returns:
- A new instance of
TimeDurationwith the given duration in days.
-
ofEmpty
Creates a new instance ofTimeDurationwith no duration and the given unit of time.- Parameters:
unit- The unit of time for the duration.- Returns:
- A new instance of
TimeDurationwith no duration and the given unit of time.
-
ofHours
Creates a new instance ofTimeDurationwith the given duration in hours.- Parameters:
duration- The duration in hours.- Returns:
- A new instance of
TimeDurationwith the given duration in hours.
-
ofMicroseconds
Creates a new instance ofTimeDurationwith the given duration in microseconds.- Parameters:
duration- The duration in microseconds.- Returns:
- A new instance of
TimeDurationwith the given duration in microseconds.
-
ofMilliseconds
Creates a new instance ofTimeDurationwith the given duration in milliseconds.- Parameters:
duration- The duration in milliseconds.- Returns:
- A new instance of
TimeDurationwith the given duration in milliseconds.
-
ofMinutes
Creates a new instance ofTimeDurationwith the given duration in minutes.- Parameters:
duration- The duration in minutes.- Returns:
- A new instance of
TimeDurationwith the given duration in minutes.
-
ofNanoseconds
Creates a new instance ofTimeDurationwith the given duration in nanoseconds.- Parameters:
duration- The duration in nanoseconds.- Returns:
- A new instance of
TimeDurationwith the given duration in nanoseconds.
-
ofSeconds
Creates a new instance ofTimeDurationwith the given duration in seconds.- Parameters:
duration- The duration in seconds.- Returns:
- A new instance of
TimeDurationwith the given duration in seconds.
-
ofWeeks
Creates a new instance ofTimeDurationwith the given duration in weeks.- Parameters:
duration- The duration in weeks.- Returns:
- A new instance of
TimeDurationwith the given duration in weeks.
-