T
- the type of the token, for example Currency.public class Amount<T>
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.
Amounts of different tokens do not mix and attempting to add or subtract two amounts of different currencies will throw IllegalArgumentException. Amounts may not be negative. Amounts are represented internally using a signed 64 bit value, therefore, the maximum expressable amount is 2^63 - 1 == Long.MAX_VALUE. Addition, subtraction and multiplication are overflow checked and will throw ArithmeticException if the operation would have caused integer overflow.
TODO: It may make sense to replace this with convenience extensions over the JSR 354 MonetaryAmount interface, in particular for use during calculations. This may also resolve... TODO: Think about how positive-only vs positive-or-negative amounts can be represented in the type system. TODO: Add either a scaling factor, or a variant for use in calculations.
Modifier and Type | Class and Description |
---|---|
static class |
Amount.Companion |
Modifier and Type | Field and Description |
---|---|
static Amount.Companion |
Companion |
Constructor and Description |
---|
Amount(long quantity,
T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest
representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest
amount used in whatever underlying thing the amount represents.
|
Amount(java.math.BigDecimal quantity,
T token)
Construct the amount using the given decimal value as quantity. Any fractional part
is discarded. To convert and use the fractional part, see fromDecimal.
|
Amount(java.math.BigInteger quantity,
T token) |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Amount<T> other) |
long |
component1() |
T |
component2() |
Amount<T> |
copy(long quantity,
T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest
representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest
amount used in whatever underlying thing the amount represents.
|
Amount<T> |
div(long other) |
Amount<T> |
div(int other) |
boolean |
equals(java.lang.Object p) |
long |
getQuantity() |
T |
getToken() |
int |
hashCode() |
Amount<T> |
minus(Amount<T> other) |
Amount<T> |
plus(Amount<T> other) |
Amount<T> |
times(long other) |
Amount<T> |
times(int other) |
java.lang.String |
toString() |
public static Amount.Companion Companion
public Amount(long quantity, T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.
Amounts of different tokens do not mix and attempting to add or subtract two amounts of different currencies will throw IllegalArgumentException. Amounts may not be negative. Amounts are represented internally using a signed 64 bit value, therefore, the maximum expressable amount is 2^63 - 1 == Long.MAX_VALUE. Addition, subtraction and multiplication are overflow checked and will throw ArithmeticException if the operation would have caused integer overflow.
TODO: It may make sense to replace this with convenience extensions over the JSR 354 MonetaryAmount interface, in particular for use during calculations. This may also resolve... TODO: Think about how positive-only vs positive-or-negative amounts can be represented in the type system. TODO: Add either a scaling factor, or a variant for use in calculations.
public Amount(java.math.BigDecimal quantity, T token)
Construct the amount using the given decimal value as quantity. Any fractional part is discarded. To convert and use the fractional part, see fromDecimal.
public Amount(java.math.BigInteger quantity, T token)
public Amount<T> div(long other)
public Amount<T> times(long other)
public Amount<T> div(int other)
public Amount<T> times(int other)
public java.lang.String toString()
public int compareTo(Amount<T> other)
public long getQuantity()
public T getToken()
public long component1()
public T component2()
public Amount<T> copy(long quantity, T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.
Amounts of different tokens do not mix and attempting to add or subtract two amounts of different currencies will throw IllegalArgumentException. Amounts may not be negative. Amounts are represented internally using a signed 64 bit value, therefore, the maximum expressable amount is 2^63 - 1 == Long.MAX_VALUE. Addition, subtraction and multiplication are overflow checked and will throw ArithmeticException if the operation would have caused integer overflow.
TODO: It may make sense to replace this with convenience extensions over the JSR 354 MonetaryAmount interface, in particular for use during calculations. This may also resolve... TODO: Think about how positive-only vs positive-or-negative amounts can be represented in the type system. TODO: Add either a scaling factor, or a variant for use in calculations.
public int hashCode()
public boolean equals(java.lang.Object p)