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