Class Currency

java.lang.Object
org.knowm.xchange.currency.Currency
All Implemented Interfaces:
Serializable, Comparable<Currency>

public class Currency
extends Object
implements Comparable<Currency>, Serializable
A Currency class roughly modeled after Currency. Each object retains the code it was acquired with -- so getInstance(java.lang.String)("BTC").getCurrencyCode()() will always be "BTC", even though the proposed ISO 4217 code is "XBT"
See Also:
Serialized Form
  • Field Details

  • Constructor Details

    • Currency

      public Currency​(String code)
      Public constructor. Links to an existing currency.
  • Method Details

    • getAvailableCurrencies

      public static SortedSet<Currency> getAvailableCurrencies()
      Gets the set of available currencies.
    • getAvailableCurrencyCodes

      public static SortedSet<String> getAvailableCurrencyCodes()
      Gets the set of available currency codes.
    • getInstance

      public static Currency getInstance​(String currencyCode)
      Returns a Currency instance for the given currency code.
    • getInstanceNoCreate

      public static Currency getInstanceNoCreate​(String currencyCode)
      Returns the Currency instance for the given currency code only if one already exists.
    • getCurrencyCode

      public String getCurrencyCode()
      Gets the currency code originally used to acquire this object.
    • getCodeCurrency

      public Currency getCodeCurrency​(String code)
      Gets the equivalent object with the passed code.

      This is useful in case some currencies share codes, such that getInstance(String) may return the wrong currency.

      Parameters:
      code - The code the returned object will evaluate to
      Returns:
      A Currency representing the same currency but having the passed currency code
      Throws:
      IllegalArgumentException - if the passed code is not listed for this currency
    • getIso4217Currency

      public Currency getIso4217Currency()
      Gets the equivalent object with an ISO 4217 code, or if none a code which looks ISO compatible (starts with an X), or the constructed currency code if neither exist.
    • getCommonlyUsedCurrency

      public Currency getCommonlyUsedCurrency()
      Gets the equivalent object that was created with the "commonly used" code.
    • getCurrencyCodes

      public Set<String> getCurrencyCodes()
      Gets the set of all currency codes associated with this currency.
    • getSymbol

      public String getSymbol()
      Gets the unicode symbol of this currency.
    • getDisplayName

      public String getDisplayName()
      Gets the name that is suitable for displaying this currency.
    • toString

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals​(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo​(Currency o)
      Specified by:
      compareTo in interface Comparable<Currency>