Class Duration.Builder
Builder class for constructing a duration conforming to ISO-8601 which consists of years, months, days and any wall time units.
The week unit is not possible in builder because this unit should
be stand-alone according to ISO-8601. A week-based duration can be
created by expression Duration.of(amount, CalendarUnit.WEEKS)
however.
A builder instance must be created by Duration.ofPositive()
or Duration.ofNegative()
. Note that the builder is only be
designed for single-thread-environments that is always creating a
new builder instance per thread.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates a new duration conforming to ISO-8601.days(int num)
Adds a day item.hours(int num)
Adds a hour item.micros(int num)
Adds a microsecond item.millis(int num)
Adds a millisecond item.minutes(int num)
Adds a minute item.months(int num)
Adds a month item.nanos(int num)
Adds a nanosecond item.seconds(int num)
Adds a second item.years(int num)
Adds a year item.
-
Method Details
-
years
Adds a year item.
- Parameters:
num
- count of years>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
CalendarUnit.YEARS
-
months
Adds a month item.
- Parameters:
num
- count of months>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
CalendarUnit.MONTHS
-
days
Adds a day item.
- Parameters:
num
- count of days>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
CalendarUnit.DAYS
-
hours
Adds a hour item.
- Parameters:
num
- count of hours>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
ClockUnit.HOURS
-
minutes
Adds a minute item.
- Parameters:
num
- count of minutes>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
ClockUnit.MINUTES
-
seconds
Adds a second item.
- Parameters:
num
- count of seconds>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
ClockUnit.SECONDS
-
millis
Adds a millisecond item.
The argument will automatically be normalized to nanoseconds.
- Parameters:
num
- count of milliseconds>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called
-
micros
Adds a microsecond item.
The argument will automatically be normalized to nanoseconds.
- Parameters:
num
- count of microseconds>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called
-
nanos
Adds a nanosecond item.
- Parameters:
num
- count of nanoseconds>= 0
- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if the argument is negativeIllegalStateException
- if already called- See Also:
ClockUnit.NANOS
-
build
Creates a new duration conforming to ISO-8601.
- Returns:
- new
Duration
-