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