Package com.norconex.commons.lang.time
Enum DurationUnit
- java.lang.Object
-
- java.lang.Enum<DurationUnit>
-
- com.norconex.commons.lang.time.DurationUnit
-
- All Implemented Interfaces:
Serializable
,Comparable<DurationUnit>
public enum DurationUnit extends Enum<DurationUnit>
Duration Unit.- Since:
- 2.0.0
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DurationUnit
from(long duration)
Gets the largest unit fitting in the provided duration.static DurationUnit
from(String unit)
Gets the DurationUnit matching the provided string (case insensitive) ornull
if there are no units matching.static DurationUnit
from(Duration duration)
Gets the largest unit fitting in the provided duration.static DurationUnit
from(TemporalUnit temporalUnit)
int
reverseOrdinal()
Gets ordinal value in reverse order.static DurationUnit[]
reverseValues()
Returns all units from the highest (year), to the smallest (milliseconds).long
toDays()
long
toDays(long amount)
Duration
toDuration()
long
toHours()
long
toHours(long amount)
long
toMilliseconds()
long
toMilliseconds(long amount)
long
toMinutes()
long
toMinutes(long amount)
long
toMonths()
long
toMonths(long amount)
long
toSeconds()
long
toSeconds(long amount)
ChronoUnit
toTemporalUnit()
long
toUnit(DurationUnit targetUnit, long amount)
long
toWeeks()
long
toWeeks(long amount)
long
toYears()
long
toYears(long amount)
static DurationUnit
valueOf(String name)
Returns the enum constant of this type with the specified name.static DurationUnit[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
MILLISECOND
public static final DurationUnit MILLISECOND
-
SECOND
public static final DurationUnit SECOND
-
MINUTE
public static final DurationUnit MINUTE
-
HOUR
public static final DurationUnit HOUR
-
DAY
public static final DurationUnit DAY
-
WEEK
public static final DurationUnit WEEK
-
MONTH
public static final DurationUnit MONTH
-
YEAR
public static final DurationUnit YEAR
-
-
Method Detail
-
values
public static DurationUnit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DurationUnit c : DurationUnit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DurationUnit valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
-
toTemporalUnit
public ChronoUnit toTemporalUnit()
-
toDuration
public Duration 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
public long toUnit(DurationUnit targetUnit, long amount)
-
from
public static DurationUnit from(Duration duration)
Gets the largest unit fitting in the provided duration. If the duration isnull
, zero, or less,null
is returned.- Parameters:
duration
- duration in milliseconds- Returns:
- duration unit
-
from
public static DurationUnit from(long duration)
Gets the largest unit fitting in the provided duration. If the duration is zero or less,null
is returned.- Parameters:
duration
- duration in milliseconds- Returns:
- duration unit
-
from
public static DurationUnit from(String unit)
Gets the DurationUnit matching the provided string (case insensitive) ornull
if there are no units matching.- Parameters:
unit
- unit name- Returns:
- duration unit
-
from
public static DurationUnit from(TemporalUnit temporalUnit)
-
reverseValues
public static DurationUnit[] 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
-
-