Package io.dropwizard.util
Class Duration
- java.lang.Object
-
- io.dropwizard.util.Duration
-
- All Implemented Interfaces:
Serializable,Comparable<Duration>
public class Duration extends Object implements Comparable<Duration>, Serializable
This class provides helper methods for parsing human-readable duration values.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Duration other)static Durationdays(long count)Constructs a newDurationobject representing the specified amount of days.booleanequals(Object obj)longgetQuantity()Gets the quantity of the currentDurationobject.TimeUnitgetUnit()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 Durationparse(String duration)Parses 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.DurationtoJavaDuration()Constructs ajava.time.Durationfrom the currentDurationobject.longtoMicroseconds()Returns the quantity of the currentDurationobject in microseconds.longtoMilliseconds()Returns the quantity of the currentDurationobject in milliseconds.longtoMinutes()Returns the quantity of the currentDurationobject in minutes.longtoNanoseconds()Returns the quantity of the currentDurationobject in nanoseconds.longtoSeconds()Returns the quantity of the currentDurationobject in seconds.StringtoString()
-
-
-
Method Detail
-
nanoseconds
public static Duration nanoseconds(long count)
Constructs a newDurationobject representing the specified amount of nanoseconds.- Parameters:
count- the amount of nanoseconds- Returns:
- the newly created
Durationobject
-
microseconds
public static Duration microseconds(long count)
Constructs a newDurationobject representing the specified amount of microseconds.- Parameters:
count- the amount of microseconds- Returns:
- the newly created
Durationobject
-
milliseconds
public static Duration milliseconds(long count)
Constructs a newDurationobject representing the specified amount of milliseconds.- Parameters:
count- the amount of milliseconds- Returns:
- the newly created
Durationobject
-
seconds
public static Duration seconds(long count)
Constructs a newDurationobject representing the specified amount of seconds.- Parameters:
count- the amount of seconds- Returns:
- the newly created
Durationobject
-
minutes
public static Duration minutes(long count)
Constructs a newDurationobject representing the specified amount of minutes.- Parameters:
count- the amount of minutes- Returns:
- the newly created
Durationobject
-
hours
public static Duration hours(long count)
Constructs a newDurationobject representing the specified amount of hours.- Parameters:
count- the amount of hours- Returns:
- the newly created
Durationobject
-
days
public static Duration days(long count)
Constructs a newDurationobject representing the specified amount of days.- Parameters:
count- the amount of days- Returns:
- the newly created
Durationobject
-
parse
public static Duration parse(String duration)
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
public TimeUnit 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
public Duration toJavaDuration()
Constructs ajava.time.Durationfrom the currentDurationobject.- Returns:
- the
java.time.Durationrepresentation
-
compareTo
public int compareTo(Duration other)
- Specified by:
compareToin interfaceComparable<Duration>
-
-