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>
public final class TimeDuration extends Object implements Comparable<TimeDuration>, Serializable
Model class with bean validation for a duration. Consists of a value and a unit of time.- Since:
- 8.1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTimeDuration.durationCustom label for thegetDuration()property.static interfaceTimeDuration.unitCustom label for thegetUnit()property.
-
Constructor Summary
Constructors Constructor Description TimeDuration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(TimeDuration that)booleanequals(Object obj)LonggetDuration()Gets the duration, interpreted according to the configured unit of time.ETimeUnitgetUnit()Gets the unit of time for the duration.inthashCode()static TimeDurationof(Long duration, ETimeUnit unit)Creates 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 TimeDurationofEmpty(ETimeUnit unit)Creates 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.voidsetUnit(ETimeUnit unit)Sets the unit of time for the duration.longto(ETimeUnit targetUnit)Converts the duration to the given unit of time.longtoDays()Gets the duration in days.DurationtoDuration()Converts this duration to aDuration.longtoHours()Gets the duration in hours.longtoMicroseconds()Gets the duration in microseconds.longtoMilliseconds()Gets the duration in milliseconds.longtoMinutes()Gets the duration in minutes.longtoNanoseconds()Gets the duration in nanoseconds.longtoSeconds()Gets the duration in seconds.longtoWeeks()Gets the duration in weeks.
-
-
-
Method Detail
-
compareTo
public int compareTo(TimeDuration that)
- Specified by:
compareToin interfaceComparable<TimeDuration>
-
getDuration
@Nullable public Long 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
public void setDuration(@Nullable Long duration)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
public ETimeUnit getUnit()
Gets the unit of time for the duration.- Returns:
- The unit of time for the duration.
-
setUnit
public void setUnit(ETimeUnit unit)
Sets the unit of time for the duration.- Parameters:
unit- The unit of time for the duration.
-
to
public long to(ETimeUnit targetUnit)
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
public Duration 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
public static TimeDuration of(Long duration, ETimeUnit unit)
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
public static TimeDuration ofDays(long duration)
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
public static TimeDuration ofEmpty(ETimeUnit unit)
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
public static TimeDuration ofHours(long duration)
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
public static TimeDuration ofMicroseconds(long duration)
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
public static TimeDuration ofMilliseconds(long duration)
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
public static TimeDuration ofMinutes(long duration)
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
public static TimeDuration ofNanoseconds(long duration)
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
public static TimeDuration ofSeconds(long duration)
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
public static TimeDuration ofWeeks(long duration)
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.
-
-