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 int
compareTo(Duration other)
static Duration
days(long count)
Constructs a newDuration
object representing the specified amount of days.boolean
equals(Object obj)
long
getQuantity()
Gets the quantity of the currentDuration
object.TimeUnit
getUnit()
int
hashCode()
static Duration
hours(long count)
Constructs a newDuration
object representing the specified amount of hours.static Duration
microseconds(long count)
Constructs a newDuration
object representing the specified amount of microseconds.static Duration
milliseconds(long count)
Constructs a newDuration
object representing the specified amount of milliseconds.static Duration
minutes(long count)
Constructs a newDuration
object representing the specified amount of minutes.static Duration
nanoseconds(long count)
Constructs a newDuration
object representing the specified amount of nanoseconds.static Duration
parse(String duration)
Parses a given input string to aDuration
.static Duration
seconds(long count)
Constructs a newDuration
object representing the specified amount of seconds.long
toDays()
Returns the quantity of the currentDuration
object in days.long
toHours()
Returns the quantity of the currentDuration
object in hours.Duration
toJavaDuration()
Constructs ajava.time.Duration
from the currentDuration
object.long
toMicroseconds()
Returns the quantity of the currentDuration
object in microseconds.long
toMilliseconds()
Returns the quantity of the currentDuration
object in milliseconds.long
toMinutes()
Returns the quantity of the currentDuration
object in minutes.long
toNanoseconds()
Returns the quantity of the currentDuration
object in nanoseconds.long
toSeconds()
Returns the quantity of the currentDuration
object in seconds.String
toString()
-
-
-
Method Detail
-
nanoseconds
public static Duration nanoseconds(long count)
Constructs a newDuration
object representing the specified amount of nanoseconds.- Parameters:
count
- the amount of nanoseconds- Returns:
- the newly created
Duration
object
-
microseconds
public static Duration microseconds(long count)
Constructs a newDuration
object representing the specified amount of microseconds.- Parameters:
count
- the amount of microseconds- Returns:
- the newly created
Duration
object
-
milliseconds
public static Duration milliseconds(long count)
Constructs a newDuration
object representing the specified amount of milliseconds.- Parameters:
count
- the amount of milliseconds- Returns:
- the newly created
Duration
object
-
seconds
public static Duration seconds(long count)
Constructs a newDuration
object representing the specified amount of seconds.- Parameters:
count
- the amount of seconds- Returns:
- the newly created
Duration
object
-
minutes
public static Duration minutes(long count)
Constructs a newDuration
object representing the specified amount of minutes.- Parameters:
count
- the amount of minutes- Returns:
- the newly created
Duration
object
-
hours
public static Duration hours(long count)
Constructs a newDuration
object representing the specified amount of hours.- Parameters:
count
- the amount of hours- Returns:
- the newly created
Duration
object
-
days
public static Duration days(long count)
Constructs a newDuration
object representing the specified amount of days.- Parameters:
count
- the amount of days- Returns:
- the newly created
Duration
object
-
parse
public static Duration parse(String duration)
Parses a given input string to aDuration
.- Parameters:
duration
- the string to parse- Returns:
- a valid
Duration
representing the parsed input string - Throws:
IllegalArgumentException
- if the given input string cannot be parsed correctly
-
getQuantity
public long getQuantity()
Gets the quantity of the currentDuration
object.- 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 currentDuration
object in nanoseconds.- Returns:
- the converted quantity
-
toMicroseconds
public long toMicroseconds()
Returns the quantity of the currentDuration
object in microseconds.- Returns:
- the converted quantity
-
toMilliseconds
public long toMilliseconds()
Returns the quantity of the currentDuration
object in milliseconds.- Returns:
- the converted quantity
-
toSeconds
public long toSeconds()
Returns the quantity of the currentDuration
object in seconds.- Returns:
- the converted quantity
-
toMinutes
public long toMinutes()
Returns the quantity of the currentDuration
object in minutes.- Returns:
- the converted quantity
-
toHours
public long toHours()
Returns the quantity of the currentDuration
object in hours.- Returns:
- the converted quantity
-
toDays
public long toDays()
Returns the quantity of the currentDuration
object in days.- Returns:
- the converted quantity
-
toJavaDuration
public Duration toJavaDuration()
Constructs ajava.time.Duration
from the currentDuration
object.- Returns:
- the
java.time.Duration
representation
-
compareTo
public int compareTo(Duration other)
- Specified by:
compareTo
in interfaceComparable<Duration>
-
-