Class CurrencyUtil


  • public abstract class CurrencyUtil
    extends java.lang.Object
    Miscellaneous currency functions (mostly conversion).
    • Field Detail

      • CURRENCY_NAME_COMPARATOR

        public static final java.util.Comparator<CurrencyType> CURRENCY_NAME_COMPARATOR
      • CURRENCY_TYPENAME_COMPARATOR

        public static final java.util.Comparator<CurrencyType> CURRENCY_TYPENAME_COMPARATOR
    • Constructor Detail

      • CurrencyUtil

        public CurrencyUtil()
    • Method Detail

      • getRawRate

        public static double getRawRate​(CurrencyType fromCurrency,
                                        CurrencyType toCurrency,
                                        int effectiveDate)
        Get the raw (adjusted for decimal place differences) rate between the two currencies. The rate that is used is the one effective on the given date.
      • getUserRate

        public static double getUserRate​(CurrencyType fromCurrency,
                                         CurrencyType toCurrency,
                                         int effectiveDate)
        Get the raw (adjusted for decimal place differences) rate between the two currencies. The rate that is used is the one effective on the given date.
      • getRawRate

        public static double getRawRate​(CurrencyType fromCurrency,
                                        CurrencyType toCurrency)
        Get the raw (adjusted for decimal place differences) rate between the two currencies.
      • convertToBasePrice

        public static double convertToBasePrice​(double priceFromCurr,
                                                CurrencyType curr,
                                                int date)
        Convert the given price (in terms of the given currency) to a price in terms of the base currency.
      • getRawRate

        public static double getRawRate​(CurrencyType fromCurrency,
                                        CurrencyType toCurrency,
                                        double userRate)
        Convert the given user-identifiable rate to the 'raw' rate used to exchange amounts between the given two currencies.
      • getUserRate

        public static double getUserRate​(CurrencyType fromCurrency,
                                         CurrencyType toCurrency,
                                         double rawRate)
        Convert the given raw rate to the user-identifiable rate used to exchange amounts between the given two currencies.
      • getUserRate

        public static double getUserRate​(CurrencyType fromCurrency,
                                         CurrencyType toCurrency)
        Get the current user-identifiable rate from fromCurrency to toCurrency.
      • convertValue

        public static long convertValue​(long value,
                                        CurrencyType fromCurrency,
                                        CurrencyType toCurrency)
        Return the amount of toCurrency that the given value of fromCurrency is currently worth.
      • convertValue

        public static long convertValue​(long value,
                                        CurrencyType fromCurrency,
                                        CurrencyType toCurrency,
                                        double userRate)
        Return the amount of 'toCurrency' obtained by exchanging 'value' of 'fromCurrency' at the rate 'rate'
      • convertValue

        public static long convertValue​(long value,
                                        CurrencyType fromCurrency,
                                        CurrencyType toCurrency,
                                        int effectiveDate)
        Return the amount of toCurrency that the given value of fromCurrency was worth on the given date.
      • getSplitAdjustedRelativeUserPrice

        public static double getSplitAdjustedRelativeUserPrice​(CurrencyType curr1,
                                                               CurrencyType curr2,
                                                               int date)
        Get the price (going rate) for currency curr1 in terms of curr2 on the given date. This adjusts the price to be in terms of splits in either currency so that the price is in terms of today's units of each currency (but the price is from the given date, not today's prices).
      • parseCurrencyExpression

        public static final long parseCurrencyExpression​(java.lang.String str,
                                                         char dec,
                                                         CurrencyType toCurr,
                                                         CurrencyTable currTable)
                                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseCurrencyExpression

        public static final long parseCurrencyExpression​(java.lang.String str,
                                                         char dec,
                                                         CurrencyType toCurr,
                                                         CurrencyTable currTable,
                                                         boolean insertDecimal)
                                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • main

        public static void main​(java.lang.String[] argv)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createDefaultTable

        public static CurrencyTable createDefaultTable​(AccountBook book,
                                                       java.lang.String primaryCurrency)