public final class Period extends Object
Use a PeriodFormatter to convert a Period to a String.
Periods are immutable. Mutating operations return the new result leaving the original unchanged.
Example:
Period p1 = Period.at(3, WEEK).and(2, DAY).inFuture(); Period p2 = p1.and(12, HOUR);
| Modifier and Type | Method and Description |
|---|---|
Period |
and(float count,
TimeUnit unit)
Set the given unit to have the given count.
|
Period |
at()
Mark the duration as being at the defined duration.
|
static Period |
at(float count,
TimeUnit unit)
Constructs a Period representing a duration of
count units extending into the past.
|
boolean |
equals(Object rhs)
Returns true if rhs extends Period and
the two Periods are equal.
|
boolean |
equals(Period rhs)
Returns true if the same units are defined with
the same counts, both extend into the future or both into the
past, and if the limits (at, more than, less than) are the same.
|
float |
getCount(TimeUnit unit)
Returns the count for the specified unit.
|
int |
hashCode()
Returns the hashCode.
|
Period |
inFuture()
Mark the time as being in the future.
|
Period |
inFuture(boolean future)
Mark the duration as extending into the future if
future is true, and into the past otherwise.
|
Period |
inPast()
Mark the duration as extending into the past.
|
Period |
inPast(boolean past)
Mark the duration as extending into the past if
past is true, and into the future otherwise.
|
boolean |
isInFuture()
Returns true if this represents a
duration into the future.
|
boolean |
isInPast()
Returns true if this represents a
duration into the past
|
boolean |
isLessThan()
Returns true if this represents a duration
less than the defined duration.
|
boolean |
isMoreThan()
Returns true if this represents a duration in
excess of the defined duration.
|
boolean |
isSet()
Returns true if any unit is set.
|
boolean |
isSet(TimeUnit unit)
Returns true if the given unit is set.
|
Period |
lessThan()
Mark the duration as being less than the defined duration.
|
static Period |
lessThan(float count,
TimeUnit unit)
Constructs a Period representing a duration
less than count units extending into the past.
|
Period |
moreThan()
Mark the duration as being more than the defined duration.
|
static Period |
moreThan(float count,
TimeUnit unit)
Constructs a Period representing a duration more than
count units extending into the past.
|
Period |
omit(TimeUnit unit)
Mark the given unit as not being set.
|
public static Period at(float count, TimeUnit unit)
count - the number of units, must be non-negativeunit - the unitpublic static Period moreThan(float count, TimeUnit unit)
count - the number of units. must be non-negativeunit - the unitpublic static Period lessThan(float count, TimeUnit unit)
count - the number of units. must be non-negativeunit - the unitpublic Period and(float count, TimeUnit unit)
count - the number of units. must be non-negativeunit - the unitpublic Period omit(TimeUnit unit)
unit - the unit to unsetpublic Period at()
public Period moreThan()
public Period lessThan()
public Period inFuture()
public Period inPast()
public Period inFuture(boolean future)
future - true if the time is in the futurepublic Period inPast(boolean past)
past - true if the time is in the pastpublic boolean isSet()
public boolean isSet(TimeUnit unit)
unit - the unit to testpublic float getCount(TimeUnit unit)
unit - the unit to testpublic boolean isInFuture()
public boolean isInPast()
public boolean isMoreThan()
public boolean isLessThan()
public boolean equals(Object rhs)
public boolean equals(Period rhs)
rhs - the period to compare to