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