Package eu.woolplatform.utils.schedule
Class TimeUnit
- java.lang.Object
-
- eu.woolplatform.utils.schedule.TimeUnit
-
public class TimeUnit extends Object
A time unit is a unit for time durations at a precision of milliseconds. The known time units are defined as constants of this class.- See Also:
TimeDuration
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetDuration(int n)Returns the duration in milliseconds for the specified number of this time unit.StringgetDurationString(int n)Returns a time duration string for the specified number of this time unit.static TimeUnit[]getTimeUnits(TimeUnit min, TimeUnit max)Returns the known time units between the specified smallest and largest time unit.static TimeUnitparse(String s, TimeUnit min, TimeUnit max)Parses a time unit string.StringtoString()
-
-
-
Method Detail
-
getDurationString
public String getDurationString(int n)
Returns a time duration string for the specified number of this time unit. For example, if this time unit isMINUTEand you setnto 30, this method will return "30 minutes".- Parameters:
n- the number of time units- Returns:
- the time duration string
-
getDuration
public long getDuration(int n)
Returns the duration in milliseconds for the specified number of this time unit.- Parameters:
n- the number of time units- Returns:
- the duration in milliseconds
-
parse
public static TimeUnit parse(String s, TimeUnit min, TimeUnit max) throws IllegalArgumentException
Parses a time unit string. The string can be a singular or plural form of the time unit. You can specify the smallest and largest allowed time unit.- Parameters:
s- the stringmin- the smallest allowed time unit. You can set this to null for the smallest known time unit.max- the largest allowed time unit. You can set this to null for the largest known time unit.- Returns:
- the time unit
- Throws:
IllegalArgumentException- if the string is invalid
-
getTimeUnits
public static TimeUnit[] getTimeUnits(TimeUnit min, TimeUnit max)
Returns the known time units between the specified smallest and largest time unit.- Parameters:
min- the smallest time unit to return. You can set this to null for the smallest known time unit.max- the largest time unit to return. You can set this to null for the largest known time unit.- Returns:
- the time units
-
-