public final class MoneyToken extends Object implements ScalarToken, Comparable<MoneyToken>
MoneyValued
object.Modifier and Type | Field and Description |
---|---|
static MoneyToken |
NULL
A null valued
MoneyToken |
static MoneyToken |
ZERO
A zero valued
MoneyToken |
static long |
ZERO_VALUE
The money zero value,
0.00 . |
MAX_INFINITY, MIN_INFINITY
Constructor and Description |
---|
MoneyToken(double value)
Constructs a new token with the given non-null
money value.
|
MoneyToken(float value)
Constructs a new token with the given non-null
money value.
|
MoneyToken(long value)
Constructs a new token with the given non-null
money value.
|
MoneyToken(MoneyValued value)
Constructs a new token with the money
value in the given container.
|
Modifier and Type | Method and Description |
---|---|
BigDecimal |
asBigDecimal()
Gets the contained numeric value.
|
long |
asCents()
Gets the contained cents value as a long
|
double |
asDouble()
Gets the contained double value.
|
float |
asFloat()
Gets the contained float value.
|
int |
compareTo(MoneyToken that) |
boolean |
equals(Object obj)
Indicates whether another object is equal to this token.
|
ScalarTokenType |
getType()
Gets the data type of the token.
|
int |
hashCode()
Returns a hash code for the token.
|
boolean |
isNull()
Indicates whether the token is null valued.
|
boolean |
isZero()
Indicates whether the value is the zero value
for the type.
|
static MoneyToken |
parse(String value)
Converts a string representation of a money value into
a token.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getType, isZero
isNull
public static final MoneyToken NULL
MoneyToken
public static final long ZERO_VALUE
0.00
.public static final MoneyToken ZERO
MoneyToken
public MoneyToken(MoneyValued value)
value
- a MoneyValued
containing the
desired valuepublic MoneyToken(long value)
NULL
.value
- the money value of the token in centspublic MoneyToken(float value)
NULL
.value
- the money value of the tokenpublic MoneyToken(double value)
NULL
.value
- the money value of the tokenpublic int compareTo(MoneyToken that)
compareTo
in interface Comparable<MoneyToken>
public boolean equals(Object obj)
DataToken
TokenComparator.equal(TokenValued,TokenValued)
but makes it possible to store DataToken
s in Map
s.public int hashCode()
DataToken
TokenConverter.asHashCode(TokenValued)
.public static MoneyToken parse(String value)
value
- a string value to interpret as money;
see BigDecimal#valueOf(String)
public final ScalarTokenType getType()
TokenValued
getType
in interface ScalarValued
getType
in interface TokenValued
getType
in interface ScalarTyped
getType
in interface TokenTyped
public final BigDecimal asBigDecimal()
NumericValued
asBigDecimal
in interface NumericValued
java.math.BigDecimal
.
If null valued, as indicated by TokenValued.isNull()
, null
is returned.public final double asDouble()
DoubleValued
asDouble
in interface DoubleValued
double
. If null valued,
as indicated by TokenValued.isNull()
, Double.NaN
is returned.public final float asFloat()
FloatValued
asFloat
in interface FloatValued
float
. If null valued,
as indicated by TokenValued.isNull()
, Float.NaN
is returned.public final long asCents()
MoneyValued
asCents
in interface MoneyValued
long
. If null valued,
as indicated by TokenValued.isNull()
, 0
is returned.public final boolean isZero()
ScalarValued
isZero
in interface ScalarValued
true
if the value is the zero value,
false
otherwise.public final boolean isNull()
TokenValued
isNull
in interface TokenValued
true
if the token is null valued,
false
otherwiseCopyright © 2024 Actian Corporation. All rights reserved.