public final class Days extends PeriodField implements java.lang.Comparable<Days>, java.io.Serializable
Days is an immutable period that can only store days. It is a type-safe way of representing a number of days in an application.
Static factory methods allow you to construct instances. The number of days may be queried using getDays(). Basic mathematical operations are provided - plus(), minus(), multipliedBy(), dividedBy() and negated(), all of which return a new instance
Days is immutable and thread-safe.
| Modifier and Type | Field and Description |
|---|---|
static Days |
ZERO
A constant for zero days.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Days otherDays)
Compares the number of days in this instance to another instance.
|
Days |
dividedBy(int divisor)
Returns a new instance with the days divided by the specified divisor.
|
int |
getAmount()
Gets the number of days held in this period.
|
PeriodUnit |
getUnit()
Gets the unit defining the amount of time.
|
boolean |
isGreaterThan(Days otherDays)
Is the number of days in this instance greater than that in
another instance.
|
boolean |
isLessThan(Days otherDays)
Is the number of days in this instance less than that in
another instance.
|
Days |
minus(Days days)
Returns a new instance with the specified number of days taken away.
|
Days |
minus(int days)
Returns a new instance with the specified number of days taken away.
|
Days |
multipliedBy(int scalar)
Returns a new instance with the days multiplied by the specified scalar.
|
Days |
negated()
Returns a new instance with the days value negated.
|
static Days |
of(int days)
Obtains an instance of
Days. |
Days |
plus(Days days)
Returns a new instance with the specified number of days added.
|
Days |
plus(int days)
Returns a new instance with the specified number of days added.
|
java.lang.String |
toString()
Returns a string representation of the number of days.
|
Days |
withAmount(int amount)
Returns a new instance of the subclass with a different number of days.
|
equals, hashCode, toPeriodFieldspublic static final Days ZERO
public static Days of(int days)
Days.days - the number of days the instance will representpublic int getAmount()
getAmount in class PeriodFieldpublic Days withAmount(int amount)
withAmount in class PeriodFieldamount - the number of days to set in the new instance, may be negativepublic PeriodUnit getUnit()
getUnit in class PeriodFieldpublic Days plus(int days)
This instance is immutable and unaffected by this method call.
plus in class PeriodFielddays - the amount of days to add, may be negativejava.lang.ArithmeticException - if the result overflows an intpublic Days plus(Days days)
This instance is immutable and unaffected by this method call.
days - the amount of days to add, may be negative, not nulljava.lang.NullPointerException - if the days to add is nulljava.lang.ArithmeticException - if the result overflows an intpublic Days minus(int days)
This instance is immutable and unaffected by this method call.
minus in class PeriodFielddays - the amount of days to take away, may be negativejava.lang.ArithmeticException - if the result overflows an intpublic Days minus(Days days)
This instance is immutable and unaffected by this method call.
days - the amount of days to take away, may be negative, not nulljava.lang.NullPointerException - if the days to add is nulljava.lang.ArithmeticException - if the result overflows an intpublic Days multipliedBy(int scalar)
This instance is immutable and unaffected by this method call.
multipliedBy in class PeriodFieldscalar - the amount to multiply by, may be negativejava.lang.ArithmeticException - if the result overflows an intpublic Days dividedBy(int divisor)
This instance is immutable and unaffected by this method call.
dividedBy in class PeriodFielddivisor - the amount to divide by, may be negativejava.lang.ArithmeticException - if the divisor is zeropublic Days negated()
negated in class PeriodFieldjava.lang.ArithmeticException - if the result overflows an intpublic int compareTo(Days otherDays)
compareTo in interface java.lang.Comparable<Days>otherDays - the other number of days, not nulljava.lang.NullPointerException - if otherDays is nullpublic boolean isGreaterThan(Days otherDays)
otherDays - the other number of days, not nulljava.lang.NullPointerException - if otherDays is nullpublic boolean isLessThan(Days otherDays)
otherDays - the other number of days, not nulljava.lang.NullPointerException - if otherDays is nullpublic java.lang.String toString()
toString in class PeriodField