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