Package eu.woolplatform.utils.schedule
Class TimeDuration
- java.lang.Object
-
- eu.woolplatform.utils.schedule.TimeDuration
-
public class TimeDuration extends Object
This class specifies a duration with a precision of milliseconds. It consists of a number and a time unit. For example: 30 minutes or 2 hours.
-
-
Constructor Summary
Constructors Constructor Description TimeDuration(int count, TimeUnit unit)Constructs a new time duration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)intgetCount()Returns the number of time units that defines this duration.longgetDuration()Returns the duration in milliseconds.TimeUnitgetUnit()Returns the time unit that, together with the number returned bygetCount(), defines this duration.inthashCode()static TimeDurationparse(String s, TimeUnit min, TimeUnit max)Parses a time duration from a string.StringtoString()
-
-
-
Constructor Detail
-
TimeDuration
public TimeDuration(int count, TimeUnit unit)Constructs a new time duration.- Parameters:
count- the number of time unitsunit- the time unit
-
-
Method Detail
-
getCount
public int getCount()
Returns the number of time units that defines this duration. The time unit is obtained withgetUnit().- Returns:
- the number of time units
-
getUnit
public TimeUnit getUnit()
Returns the time unit that, together with the number returned bygetCount(), defines this duration.- Returns:
- the time unit
-
getDuration
public long getDuration()
Returns the duration in milliseconds.- Returns:
- the duration in milliseconds
-
parse
public static TimeDuration parse(String s, TimeUnit min, TimeUnit max) throws ParseException
Parses a time duration from a string. The string should consist of a number and a time unit, separated by white space. 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 duration
- Throws:
ParseException- if the string is invalid
-
-