Package com.norconex.commons.lang.time
Enum Class DurationUnit
- All Implemented Interfaces:
Serializable,Comparable<DurationUnit>,Constable
Duration unit. These units are best used with a general estimation is
acceptable. The quantities for each units are fixed, and never change
according to a specific era or moment in time. For instance a year is
a fixed average of approximately 365.2425 days.
- Since:
- 2.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic DurationUnitfrom(long duration) Gets the largest unit fitting in the provided duration.static DurationUnitGets the DurationUnit matching the provided string (case insensitive) ornullif there are no units matching.static DurationUnitGets the largest unit fitting in the provided duration.static DurationUnitfrom(TemporalUnit temporalUnit) intGets ordinal value in reverse order.static DurationUnit[]Returns all units from the highest (year), to the smallest (milliseconds).longtoDays()longtoDays(long amount) longtoHours()longtoHours(long amount) longlongtoMilliseconds(long amount) longlongtoMinutes(long amount) longtoMonths()longtoMonths(long amount) longlongtoSeconds(long amount) longtoUnit(DurationUnit targetUnit, long amount) longtoWeeks()longtoWeeks(long amount) longtoYears()longtoYears(long amount) static DurationUnitReturns the enum constant of this class with the specified name.static DurationUnit[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
MILLISECOND
-
SECOND
-
MINUTE
-
HOUR
-
DAY
-
WEEK
-
MONTH
-
YEAR
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
toTemporalUnit
-
toDuration
-
toMilliseconds
public long toMilliseconds() -
toMilliseconds
public long toMilliseconds(long amount) -
toSeconds
public long toSeconds() -
toSeconds
public long toSeconds(long amount) -
toMinutes
public long toMinutes() -
toMinutes
public long toMinutes(long amount) -
toHours
public long toHours() -
toHours
public long toHours(long amount) -
toDays
public long toDays() -
toDays
public long toDays(long amount) -
toWeeks
public long toWeeks() -
toWeeks
public long toWeeks(long amount) -
toMonths
public long toMonths() -
toMonths
public long toMonths(long amount) -
toYears
public long toYears() -
toYears
public long toYears(long amount) -
toUnit
-
from
Gets the largest unit fitting in the provided duration. If the duration isnull, zero, or less,nullis returned.- Parameters:
duration- duration in milliseconds- Returns:
- duration unit
-
from
Gets the largest unit fitting in the provided duration. If the duration is zero or less,nullis returned.- Parameters:
duration- duration in milliseconds- Returns:
- duration unit
-
from
Gets the DurationUnit matching the provided string (case insensitive) ornullif there are no units matching.- Parameters:
unit- unit name- Returns:
- duration unit
-
from
-
reverseValues
Returns all units from the highest (year), to the smallest (milliseconds).- Returns:
- duration units
-
reverseOrdinal
public int reverseOrdinal()Gets ordinal value in reverse order.- Returns:
- ordinal value
-