Package io.dropwizard.util
Class Duration
java.lang.Object
io.dropwizard.util.Duration
- All Implemented Interfaces:
Serializable,Comparable<Duration>
This class provides helper methods for parsing human-readable duration values.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintstatic Durationdays(long count) Constructs a newDurationobject representing the specified amount of days.booleanlongGets the quantity of the currentDurationobject.getUnit()inthashCode()static Durationhours(long count) Constructs a newDurationobject representing the specified amount of hours.static Durationmicroseconds(long count) Constructs a newDurationobject representing the specified amount of microseconds.static Durationmilliseconds(long count) Constructs a newDurationobject representing the specified amount of milliseconds.static Durationminutes(long count) Constructs a newDurationobject representing the specified amount of minutes.static Durationnanoseconds(long count) Constructs a newDurationobject representing the specified amount of nanoseconds.static DurationParses a given input string to aDuration.static Durationseconds(long count) Constructs a newDurationobject representing the specified amount of seconds.longtoDays()Returns the quantity of the currentDurationobject in days.longtoHours()Returns the quantity of the currentDurationobject in hours.Constructs ajava.time.Durationfrom the currentDurationobject.longReturns the quantity of the currentDurationobject in microseconds.longReturns the quantity of the currentDurationobject in milliseconds.longReturns the quantity of the currentDurationobject in minutes.longReturns the quantity of the currentDurationobject in nanoseconds.longReturns the quantity of the currentDurationobject in seconds.toString()
-
Method Details
-
nanoseconds
Constructs a newDurationobject representing the specified amount of nanoseconds.- Parameters:
count- the amount of nanoseconds- Returns:
- the newly created
Durationobject
-
microseconds
Constructs a newDurationobject representing the specified amount of microseconds.- Parameters:
count- the amount of microseconds- Returns:
- the newly created
Durationobject
-
milliseconds
Constructs a newDurationobject representing the specified amount of milliseconds.- Parameters:
count- the amount of milliseconds- Returns:
- the newly created
Durationobject
-
seconds
Constructs a newDurationobject representing the specified amount of seconds.- Parameters:
count- the amount of seconds- Returns:
- the newly created
Durationobject
-
minutes
Constructs a newDurationobject representing the specified amount of minutes.- Parameters:
count- the amount of minutes- Returns:
- the newly created
Durationobject
-
hours
Constructs a newDurationobject representing the specified amount of hours.- Parameters:
count- the amount of hours- Returns:
- the newly created
Durationobject
-
days
Constructs a newDurationobject representing the specified amount of days.- Parameters:
count- the amount of days- Returns:
- the newly created
Durationobject
-
parse
Parses a given input string to aDuration.- Parameters:
duration- the string to parse- Returns:
- a valid
Durationrepresenting the parsed input string - Throws:
IllegalArgumentException- if the given input string cannot be parsed correctly
-
getQuantity
public long getQuantity()Gets the quantity of the currentDurationobject.- Returns:
- the quantity of the current duration
-
getUnit
- Returns:
- the unit of the current duration
-
toNanoseconds
public long toNanoseconds()Returns the quantity of the currentDurationobject in nanoseconds.- Returns:
- the converted quantity
-
toMicroseconds
public long toMicroseconds()Returns the quantity of the currentDurationobject in microseconds.- Returns:
- the converted quantity
-
toMilliseconds
public long toMilliseconds()Returns the quantity of the currentDurationobject in milliseconds.- Returns:
- the converted quantity
-
toSeconds
public long toSeconds()Returns the quantity of the currentDurationobject in seconds.- Returns:
- the converted quantity
-
toMinutes
public long toMinutes()Returns the quantity of the currentDurationobject in minutes.- Returns:
- the converted quantity
-
toHours
public long toHours()Returns the quantity of the currentDurationobject in hours.- Returns:
- the converted quantity
-
toDays
public long toDays()Returns the quantity of the currentDurationobject in days.- Returns:
- the converted quantity
-
toJavaDuration
Constructs ajava.time.Durationfrom the currentDurationobject.- Returns:
- the
java.time.Durationrepresentation
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<Duration>
-