public class Duration extends java.lang.Object implements java.lang.Comparable<Duration>, IStringRepresentation
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_FORMAT |
static long |
MILLIS_PER_DAY |
static long |
MILLIS_PER_HOUR |
static long |
MILLIS_PER_MINUTE |
static long |
MILLIS_PER_SECOND |
Modifier | Constructor and Description |
---|---|
protected |
Duration(long fullDurationInMillis) |
Modifier and Type | Method and Description |
---|---|
long |
asMilliseconds()
Returns the full duration as milliseconds.
|
java.lang.String |
asString()
Returns the duration as a string using english text labels as suffix after each value.
|
java.lang.String |
asString(java.lang.String daysText,
java.lang.String hoursText,
java.lang.String minutesText,
java.lang.String secondsText,
java.lang.String millisText)
Returns the duration as a string using the given text labels as suffix after each value.
|
int |
compareTo(Duration other) |
static Duration |
create(int milliseconds)
Creates a new instance based on the given milliseconds.
|
static Duration |
create(int seconds,
int milliseconds)
Creates a new instance based on the given values.
|
static Duration |
create(int minutes,
int seconds,
int milliseconds)
Creates a new instance based on the given values.
|
static Duration |
create(int hours,
int minutes,
int seconds,
int milliseconds)
Creates a new instance based on the given values.
|
static Duration |
create(long days,
int hours,
int minutes,
int seconds,
int milliseconds)
Creates a new instance based on the given values.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
format(java.lang.String template)
Formats the duration into a string utilizing the given template.
|
long |
getDays()
Returns the number of days.
|
protected long |
getFullDurationInMillis() |
int |
getHours()
Returns the number of hours.
|
int |
getMilliseconds()
Returns the number of milliseconds.
|
int |
getMinutes()
Returns the number of minutes.
|
int |
getSeconds()
Returns the number of seconds.
|
int |
hashCode() |
boolean |
isInDaysRange()
Returns true if the duration is not under a day.
|
boolean |
isInHoursRange()
Returns true if the duration is not under an hour.
|
boolean |
isInMinutesRange()
Returns true if the duration is not under a minute.
|
boolean |
isInSecondsRange()
Returns true if the duration is not under a second.
|
protected java.lang.String |
replacePlaceholder(java.lang.String string,
java.lang.String placeholder,
boolean isInRange,
long value) |
java.lang.String |
toString() |
static Duration |
valueOf(long fullDurationInMillis)
Creates a new instance based on the given milliseconds.
|
public static final long MILLIS_PER_SECOND
public static final long MILLIS_PER_MINUTE
public static final long MILLIS_PER_HOUR
public static final long MILLIS_PER_DAY
public static final java.lang.String DEFAULT_FORMAT
public static Duration valueOf(long fullDurationInMillis)
fullDurationInMillis
- The duration in milliseconds.public static Duration create(int milliseconds)
valueOf(long)
instead!milliseconds
- The number of milliseconds - must be a value in the range of 0..999.java.lang.IllegalArgumentException
- if any of the given values is outside the allowed range.public static Duration create(int seconds, int milliseconds)
seconds
- The number of seconds - must be a value in the range of 0..59.milliseconds
- The number of milliseconds - must be a value in the range of 0..999.java.lang.IllegalArgumentException
- if any of the given values is outside the allowed range.public static Duration create(int minutes, int seconds, int milliseconds)
minutes
- The number of minutes - must be a value in the range of 0..59.seconds
- The number of seconds - must be a value in the range of 0..59.milliseconds
- The number of milliseconds - must be a value in the range of 0..999.java.lang.IllegalArgumentException
- if any of the given values is outside the allowed range.public static Duration create(int hours, int minutes, int seconds, int milliseconds)
hours
- The number of hours - must be a value in the range of 0..24.minutes
- The number of minutes - must be a value in the range of 0..59.seconds
- The number of seconds - must be a value in the range of 0..59.milliseconds
- The number of milliseconds - must be a value in the range of 0..999.java.lang.IllegalArgumentException
- if any of the given values is outside the allowed range.public static Duration create(long days, int hours, int minutes, int seconds, int milliseconds)
days
- The number of days - must be a value in the range of 0..106751991166.hours
- The number of hours - must be a value in the range of 0..24.minutes
- The number of minutes - must be a value in the range of 0..59.seconds
- The number of seconds - must be a value in the range of 0..59.milliseconds
- The number of milliseconds - must be a value in the range of 0..999.java.lang.IllegalArgumentException
- if any of the given values is outside the allowed range.public long getDays()
public int getHours()
public int getMinutes()
public int getSeconds()
public int getMilliseconds()
public long asMilliseconds()
public boolean isInDaysRange()
public boolean isInHoursRange()
public boolean isInMinutesRange()
public boolean isInSecondsRange()
public java.lang.String asString()
asString
in interface IStringRepresentation
public java.lang.String asString(java.lang.String daysText, java.lang.String hoursText, java.lang.String minutesText, java.lang.String secondsText, java.lang.String millisText)
public java.lang.String format(java.lang.String template)
template
- The template with placeholders to be used for formatting (must not be null).public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int compareTo(Duration other)
compareTo
in interface java.lang.Comparable<Duration>
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String replacePlaceholder(java.lang.String string, java.lang.String placeholder, boolean isInRange, long value)
protected long getFullDurationInMillis()