net.corda.core.contracts

## Class Amount<T>

- net.corda.core.contracts.Amount<T>

- Type Parameters:
    `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.

  See Also:
    IllegalArgumentException, ArithmeticException

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Amount.Companion`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Amount.Companion` | `Companion`

  - ### Constructor Summary

    Constructors
    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)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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()`

- - ### Field Detail

    - #### Companion

          public static Amount.Companion Companion

  - ### Constructor Detail

    - #### Amount

          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.

      See Also:
        IllegalArgumentException, ArithmeticException

    - #### Amount

          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.

    - #### Amount

          public Amount(java.math.BigInteger quantity,
                        T token)

  - ### Method Detail

    - #### plus

          public Amount<T> plus(Amount<T> other)

    - #### minus

          public Amount<T> minus(Amount<T> other)

    - #### div

          public Amount<T> div(long other)

    - #### times

          public Amount<T> times(long other)

    - #### div

          public Amount<T> div(int other)

    - #### times

          public Amount<T> times(int other)

    - #### toString

          public java.lang.String toString()

    - #### compareTo

          public int compareTo(Amount<T> other)

    - #### getQuantity

          public long getQuantity()

    - #### getToken

          public T getToken()

    - #### component1

          public long component1()

    - #### component2

          public T component2()

    - #### copy

          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.

      See Also:
        IllegalArgumentException, ArithmeticException

    - #### hashCode

          public int hashCode()

    - #### equals

          public boolean equals(java.lang.Object p)