Class ZephyrBalance

java.lang.Object
zephyr.wallet.model.ZephyrBalance

public class ZephyrBalance extends Object
Balances per asset: a map from asset name to amount in atomic units. The JSON form is the plain object {asset: amount} that the core emits. The asset is an open string (see ZephyrAssets).
  • Constructor Details

    • ZephyrBalance

      public ZephyrBalance()
      Constructs an empty balance.
    • ZephyrBalance

      public ZephyrBalance(Map<String,BigInteger> balances)
      Constructs a balance from a map of asset to amount.
      Parameters:
      balances - maps asset name to amount in atomic units (copied)
  • Method Details

    • get

      public BigInteger get(String assetType)
      Returns the amount of one asset.
      Parameters:
      assetType - is the asset name
      Returns:
      the amount in atomic units, BigInteger.ZERO when the asset is absent, never null
    • set

      public ZephyrBalance set(String assetType, BigInteger amount)
      Sets the amount of one asset.
      Parameters:
      assetType - is the asset name
      amount - is the amount in atomic units
      Returns:
      this balance for chaining
    • getAssetTypes

      public Set<String> getAssetTypes()
      Returns the asset names present in this balance.
      Returns:
      the asset names, sorted (unmodifiable)
    • toMap

      public Map<String,BigInteger> toMap()
      Returns the balances as a map; this is also the JSON form.
      Returns:
      the map of asset name to amount, sorted by asset (unmodifiable)
    • isEmpty

      public boolean isEmpty()
      Indicates whether this balance has no asset entries.
      Returns:
      true if there are no asset entries, false otherwise
    • copy

      public ZephyrBalance copy()
      Returns a copy of this balance.
      Returns:
      the copy
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(int indent)
      Returns one line per asset.
      Parameters:
      indent - indents the lines
      Returns:
      the human-friendly string
    • hashCode

      public int hashCode()
      Returns a hash code consistent with equals(Object): entries with a zero amount do not contribute, so a balance that lists an asset at zero hashes like one that omits it.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Compares two balances per asset. An asset that is absent from one balance counts as zero, so the wallet-level balance (which lists every asset, zeros included) equals an account or subaddress balance (which lists only the assets it holds) when the amounts agree.
      Overrides:
      equals in class Object
      Parameters:
      obj - is the object to compare with
      Returns:
      true if obj is a ZephyrBalance with the same amount for every asset