public class Amount<T>
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.
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.
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,
java.math.BigDecimal displayTokenSize,
T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest
representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize.
The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used
when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.

Amount(long tokenQuantity,
T token)
Automatic conversion constructor from number of tokens to an Amount using getDisplayTokenSize to determine
the displayTokenSize.

Modifier and Type  Method and Description 

long 
component1()
the number of tokens as a Long value.

java.math.BigDecimal 
component2()
the nominal display unit size of a single token,

T 
component3()
an instance of type T,

Amount<T> 
copy(long quantity,
java.math.BigDecimal displayTokenSize,
T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest
representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize.
The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used
when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.

boolean 
equals(java.lang.Object p) 
static <T> Amount<T> 
fromDecimal(java.math.BigDecimal displayQuantity,
T token,
java.math.RoundingMode rounding)
Build an Amount from a decimal representation. For example, with an input of "12.34 GBP",
returns an amount with a quantity of "1234" tokens. The displayTokenSize as determined via
getDisplayTokenSize is used to determine the conversion scaling.
e.g. Bonds might be in nominal amounts of 100, currencies in 0.01 penny units.

static <T> Amount<T> 
fromDecimal(java.math.BigDecimal displayQuantity,
T token)
Build an Amount from a decimal representation. For example, with an input of "12.34 GBP",
returns an amount with a quantity of "1234" tokens. The displayTokenSize as determined via
getDisplayTokenSize is used to determine the conversion scaling.
e.g. Bonds might be in nominal amounts of 100, currencies in 0.01 penny units.

java.math.BigDecimal 
getDisplayTokenSize()
the nominal display unit size of a single token,

static java.math.BigDecimal 
getDisplayTokenSize(java.lang.Object token)
Determines the representation of one Token quantity in BigDecimal. For Currency and Issued
the definitions is taken from Currency defaultFractionDigits property e.g. 2 for USD, or 0 for JPY
so that the automatic token size is the conventional minimum penny amount.
For other possible token types the asset token should implement TokenizableAssetInfo to
correctly report the designed nominal amount.

long 
getQuantity()
the number of tokens as a Long value.

T 
getToken()
an instance of type T,

int 
hashCode() 
Amount<T> 
minus(Amount<T> other)
A checked addition operator is supported to simplify netting of Amounts.
If this leads to the Amount going negative this will throw IllegalArgumentException.
Mixing nonidentical token types will throw IllegalArgumentException.

static Amount<java.util.Currency> 
parseCurrency(java.lang.String input)
Returns an amount that is equal to the given currency amount in text. Examples of what is supported:

Amount<T> 
plus(Amount<T> other)
A checked addition operator is supported to simplify aggregation of Amounts.
Mixing nonidentical token types will throw IllegalArgumentException.

java.util.List<net.corda.core.contracts.Amount> 
splitEvenly(int partitions)
This method provides a token conserving divide mechanism.

static <T> Amount<T> 
sumOrNull(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver)
If the given iterable of
class Amount s yields any elements, sum them, throwing an IllegalArgumentException if
any of the token types are mismatched; if the iterator yields no elements, return null. 
static <T> Amount<T> 
sumOrThrow(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver)
Sums the amounts yielded by the given iterable, throwing an IllegalArgumentException if any of the token
types are mismatched.

static <T> Amount<T> 
sumOrZero(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver,
T token)
If the given iterable of
class Amount s yields any elements, sum them, throwing an IllegalArgumentException if
any of the token types are mismatched; if the iterator yields no elements, return a zero amount of the given
token type. 
Amount<T> 
times(long other)
The multiplication operator is supported to allow easy calculation for multiples of a primitive Amount.
Note this is not a conserving operation, so it may not always be correct modelling of proper token behaviour.
N.B. Division is not supported as fractional tokens are not representable by an Amount.

Amount<T> 
times(int other)
The multiplication operator is supported to allow easy calculation for multiples of a primitive Amount.
Note this is not a conserving operation, so it may not always be correct modelling of proper token behaviour.
N.B. Division is not supported as fractional tokens are not representable by an Amount.

java.math.BigDecimal 
toDecimal()
Convert a currency
class Amount to a decimal representation. For example, with an amount with a quantity
of "1234" GBP, returns "12.34". The precise representation is controlled by the displayTokenSize,
which determines the size of a single token and controls the trailing decimal places via it's scale property. 
java.lang.String 
toString()
Convert a currency
class Amount to a display string representation. 
static <T> Amount<T> 
zero(T token)
For a particular token returns a zero sized Amount

public static Amount.Companion Companion
public Amount(long quantity, java.math.BigDecimal displayTokenSize, T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.
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.
quantity
 the number of tokens as a Long value.displayTokenSize
 the nominal display unit size of a single token, potentially with trailing decimal display places if the scale parameter is nonzero.token
 an instance of type T, usually a singleton.public Amount(long tokenQuantity, T token)
Automatic conversion constructor from number of tokens to an Amount using getDisplayTokenSize to determine the displayTokenSize.
tokenQuantity
 the number of tokens represented.token
 the type of the token, for example a Currency object.public Amount<T> plus(Amount<T> other)
A checked addition operator is supported to simplify aggregation of Amounts. Mixing nonidentical token types will throw IllegalArgumentException.
public Amount<T> minus(Amount<T> other)
A checked addition operator is supported to simplify netting of Amounts. If this leads to the Amount going negative this will throw IllegalArgumentException. Mixing nonidentical token types will throw IllegalArgumentException.
public Amount<T> times(long other)
The multiplication operator is supported to allow easy calculation for multiples of a primitive Amount. Note this is not a conserving operation, so it may not always be correct modelling of proper token behaviour. N.B. Division is not supported as fractional tokens are not representable by an Amount.
public Amount<T> times(int other)
The multiplication operator is supported to allow easy calculation for multiples of a primitive Amount. Note this is not a conserving operation, so it may not always be correct modelling of proper token behaviour. N.B. Division is not supported as fractional tokens are not representable by an Amount.
public java.util.List<net.corda.core.contracts.Amount> splitEvenly(int partitions)
This method provides a token conserving divide mechanism.
partitions
 the number of amounts to divide the current quantity into.public java.math.BigDecimal toDecimal()
Convert a currency class Amount
to a decimal representation. For example, with an amount with a quantity
of "1234" GBP, returns "12.34". The precise representation is controlled by the displayTokenSize,
which determines the size of a single token and controls the trailing decimal places via it's scale property.
class Amount
public java.lang.String toString()
Convert a currency class Amount
to a display string representation.
For example, with an amount with a quantity of "1234" GBP, returns "12.34 GBP". The result of fromDecimal is used to control the numerical formatting and the token specifier appended is taken from token.toString.
class Amount
public long getQuantity()
the number of tokens as a Long value.
public java.math.BigDecimal getDisplayTokenSize()
the nominal display unit size of a single token,
potentially with trailing decimal display places if the scale parameter is nonzero.
public T getToken()
an instance of type T,
usually a singleton.
public long component1()
the number of tokens as a Long value.
public java.math.BigDecimal component2()
the nominal display unit size of a single token,
potentially with trailing decimal display places if the scale parameter is nonzero.
public T component3()
an instance of type T,
usually a singleton.
public Amount<T> copy(long quantity, java.math.BigDecimal displayTokenSize, T token)
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.
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.
public int hashCode()
public boolean equals(java.lang.Object p)
public static <T> Amount<T> fromDecimal(java.math.BigDecimal displayQuantity, T token, java.math.RoundingMode rounding)
Build an Amount from a decimal representation. For example, with an input of "12.34 GBP", returns an amount with a quantity of "1234" tokens. The displayTokenSize as determined via getDisplayTokenSize is used to determine the conversion scaling. e.g. Bonds might be in nominal amounts of 100, currencies in 0.01 penny units.
class Amount
public static <T> Amount<T> fromDecimal(java.math.BigDecimal displayQuantity, T token)
Build an Amount from a decimal representation. For example, with an input of "12.34 GBP", returns an amount with a quantity of "1234" tokens. The displayTokenSize as determined via getDisplayTokenSize is used to determine the conversion scaling. e.g. Bonds might be in nominal amounts of 100, currencies in 0.01 penny units.
class Amount
public static <T> Amount<T> zero(T token)
For a particular token returns a zero sized Amount
public static java.math.BigDecimal getDisplayTokenSize(java.lang.Object token)
Determines the representation of one Token quantity in BigDecimal. For Currency and Issued the definitions is taken from Currency defaultFractionDigits property e.g. 2 for USD, or 0 for JPY so that the automatic token size is the conventional minimum penny amount. For other possible token types the asset token should implement TokenizableAssetInfo to correctly report the designed nominal amount.
public static <T> Amount<T> sumOrNull(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver)
If the given iterable of class Amount
s yields any elements, sum them, throwing an IllegalArgumentException if
any of the token types are mismatched; if the iterator yields no elements, return null.
class Amount
,
IllegalArgumentExceptionpublic static <T> Amount<T> sumOrThrow(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver)
Sums the amounts yielded by the given iterable, throwing an IllegalArgumentException if any of the token types are mismatched.
public static <T> Amount<T> sumOrZero(java.lang.Iterable<net.corda.core.contracts.Amount> $receiver, T token)
If the given iterable of class Amount
s yields any elements, sum them, throwing an IllegalArgumentException if
any of the token types are mismatched; if the iterator yields no elements, return a zero amount of the given
token type.
class Amount
,
IllegalArgumentExceptionpublic static Amount<java.util.Currency> parseCurrency(java.lang.String input)
Returns an amount that is equal to the given currency amount in text. Examples of what is supported:
12 USD
14.50 USD
10 USD
30 CHF
$10.24
£13
€5000
Note this method does NOT respect internationalisation rules: it ignores commas and uses . as the decimal point separator, always. It also ignores the users locale:
$ is always USD,
£ is always GBP
€ is always the Euro
¥ is always Japanese Yen.
₽ is always the Russian ruble.
Thus an input of $12 expecting some other countries dollar will not work. Do your own parsing if you need correct handling of currency amounts with localesensitive handling.