Class CurrencyType

java.lang.Object
com.infinitekind.moneydance.model.MoneydanceSyncableItem
com.infinitekind.moneydance.model.CurrencyType
All Implemented Interfaces:
com.infinitekind.tiksync.SyncableItem

public final class CurrencyType
extends MoneydanceSyncableItem
A structure that represents a single type of currency, identified by the three digit currency code. A stock or security in Moneydance is represented as a currency as it is a unit of value that is relative to some other value (ie the base currency)
  • Field Details

  • Constructor Details

  • Method Details

    • itemWasUpdated

      public void itemWasUpdated()
      Description copied from class: MoneydanceSyncableItem
      This is called after an item is updated by calling itemWasUpdated(SyncRecord). This can occur from the syncing process or from being loaded locally. Override this method to be notified.
      Overrides:
      itemWasUpdated in class MoneydanceSyncableItem
    • itemWillSync

      public void itemWillSync()
      Description copied from class: MoneydanceSyncableItem
      This is called just before an item will be stored and/or synced when itemWillSync(SyncRecord) is called. Override this method to be notified or if you'd like to store anything into the info record to be synced.
      Overrides:
      itemWillSync in class MoneydanceSyncableItem
    • getSyncItemType

      public final java.lang.String getSyncItemType()
      Description copied from class: MoneydanceSyncableItem
      Subclasses should override this to return a static string identifying their type of object
      Specified by:
      getSyncItemType in interface com.infinitekind.tiksync.SyncableItem
      Overrides:
      getSyncItemType in class MoneydanceSyncableItem
    • getID

      public int getID()
    • deleteItem

      public boolean deleteItem()
      Deletes this item and and all of the snapshots and splits that reference it. Use with caution!
      Overrides:
      deleteItem in class MoneydanceSyncableItem
    • getEffectiveDateInt

      public final int getEffectiveDateInt()
      Returns the int value (where the decimal form equals YYYYMMDD) representing the first date that this currency is active. This usually only pertains to securities.
    • getCurrencyType

      public final CurrencyType.Type getCurrencyType()
    • setCurrencyType

      public void setCurrencyType​(CurrencyType.Type newType)
    • getIDString

      public final java.lang.String getIDString()
    • getName

      public final java.lang.String getName()
    • getPrefix

      public final java.lang.String getPrefix()
    • getSuffix

      public final java.lang.String getSuffix()
    • getDecimalPlaces

      public final int getDecimalPlaces()
    • getTickerSymbol

      public final java.lang.String getTickerSymbol()
    • setDecimalPlaces

      public final void setDecimalPlaces​(int newDecimalPlaces)
    • getTable

      public CurrencyTable getTable()
      Returns the currency table that this currency is a part of. Note: This is only available as of build 281.
    • getDoubleValue

      public final double getDoubleValue​(long longVal)
      Get the 64 bit floating point representation of the given integer amount of this currency
    • getLongValue

      public final long getLongValue​(double doubleVal)
    • setIDString

      public final void setIDString​(java.lang.String newIDString)
    • getRelativeCurrency

      public final CurrencyType getRelativeCurrency()
      Returns the currency to which this item's rates are relative. Note: Only securities are permitted to have a relative currency that is not the base currency.
      Since:
      Moneydance 2019 (build 1800)
    • setRelativeCurrency

      public final void setRelativeCurrency​(CurrencyType newRelativeCurrency)
      Sets the currency to which this item's rates are relative. Note: Only securities are permitted to have a relative currency that is not equal to the base currency.
      Since:
      Moneydance 2019.1 (build 1852)
    • setDailyVolume

      public final void setDailyVolume​(long vol)
    • getDailyVolume

      public final long getDailyVolume()
    • setDailyChange

      public final void setDailyChange​(double change)
    • getDailyChange

      public final double getDailyChange()
    • setTickerSymbol

      public final void setTickerSymbol​(java.lang.String newTickerSymbol)
    • setName

      public final void setName​(java.lang.String newName)
    • getRawRate

      public final double getRawRate()
      Deprecated.
      please use the non-raw rate methods and static functions in CurrencyUtil
      Get the rate of this currency relative to the base currency in a value that can be multiplied or divided by the 'long' amount values to get a 'long' value in the other currency.
    • setRawRate

      public void setRawRate​(double newRawRate, boolean adjustRelativeSecurities)
      Deprecated.
      please use setRelativeRate() or setRate() with non-decimal-adjusted rate values
      Set the rate relative to the base currency *already adjusted* for differences in decimal places between this currency and the base currency.
    • setUserRate

      public final void setUserRate​(double newRate)
      Deprecated.
      please use setRelativeRate() or setRate(double, CurrencyType) to set the rate
      Set the price or rate for this currency using the normal decimal placement, not the decimal place adjusted values used when setting raw rates. Note: if there is a relative currency for this currency, then the given rate is assumed to be relative to that currency.
    • setUserRate

      public final void setUserRate​(double newRate, CurrencyType relativeCurr)
      Deprecated.
      please use setRate(newRate, relativeCurrency)
      Set the new user (not raw) rate to the given value relative to the given currency.
      Since:
      Moneydance build 616
    • setRate

      public final void setRate​(double newRate, CurrencyType relativeCurr)
      Set the new user (not raw) rate to the given value relative to the given currency. If relativeCurr is null then the given rate is considered to be relative to the base currency.
      Since:
      Moneydance build 616
    • setRelativeRate

      public final void setRelativeRate​(double newRate)
      Set the rate in terms of the relative currency. If there is no relative currency then the rate is stored relative to the base currency of the file
      Since:
      Moneydance 2019 (build 1800)
    • setBaseRate

      public final void setBaseRate​(double newRate)
      Set the rate in terms of the base currency.
      Since:
      Moneydance 2019 (build 1800)
    • getRelativeRate

      public final double getRelativeRate()
      Get the rate in terms of the relative currency. If there is no relative currency then this returns the rate in terms of the base currency.
      Since:
      Moneydance 2019 (build 1800)
    • getRelativeRate

      public final double getRelativeRate​(int asOfDate)
      Get the rate in terms of the relative currency as of the given date. If there is no relative currency then this returns the rate in terms of the base currency.
      Since:
      Moneydance 2019.1 (build 1851)
    • getBaseRate

      public final double getBaseRate()
      Get the rate in terms of the base currency.
      Since:
      Moneydance 2019 (build 1800)
    • getUserRate

      public final double getUserRate()
      Deprecated.
      this has been deprecated in favor of getRate(CurrencyType relativeToCurrency) or getRelativeRate()
      Get the rate relative to the base currency
    • getRate

      public final double getRate​(CurrencyType relativeToCurrency)
      Get the rate of this currency relative to the given currency. If relativeToCurrency is null then the rate is returned in terms of the base currency.
    • getRate

      public final double getRate​(CurrencyType relativeTo, int asOfDate)
      Get the rate of this currency relative to the given currency as of the given date. If relativeToCurrency is null then the rate is returned in terms of the base currency.
    • setPrefix

      public final void setPrefix​(java.lang.String newPrefix)
    • setSuffix

      public final void setSuffix​(java.lang.String newSuffix)
    • convertValue

      public final long convertValue​(long baseCurrencyAmount)
      Convert the given baseCurrencyAmount value to it's value in this currency.
    • invertValue

      public final long invertValue​(long currencyAmount)
      Convert the given currencyAmount value in this currency to a value in the base currency.
    • isDirty

      public final boolean isDirty()
    • resetDirtyFlags

      public final void resetDirtyFlags()
    • addStockSplit

      public final CurrencySplit addStockSplit​(long date, double splitRatio, int oldShares, int newShares)
      Deprecated.
      use the addStockSplit method that takes an int date instead
      Add a stock split.
    • addStockSplitInt

      public final CurrencySplit addStockSplitInt​(int date, double splitRatio, int oldShares, int newShares)
      Add a stock split with the given ratio (which should match the old/new shares) on the given date (which decimal form is YYYYMMDD)
    • adjustValueForSplits

      public final long adjustValueForSplits​(long txnDate, long val)
      Deprecated.
      use adjustValueForSplitsInt(int, long) instead
      Given a number of currency units on the given day, return the equivalent number of units in todays currency value. This is intended to be used mainly for stock splits.
    • adjustValueForSplitsInt

      public final long adjustValueForSplitsInt​(int txnDate, long val)
      Given a number of currency units on the given day, return the equivalent number of units in todays currency value. This is intended to be used mainly for stock splits.
    • adjustValueForSplitsInt

      public final long adjustValueForSplitsInt​(int txnDate, long val, int endDate)
      Given a number of currency units on the given day, return the equivalent number of units in the endDate's currency value. This is intended to be used mainly for stock splits.
    • unadjustValueForSplitsInt

      public final long unadjustValueForSplitsInt​(int asofDate, long todayVal, int today)
      Given a number of currency units as of today, return the equivalent number of units in the asofDate's currency value, which must be a previous date. This is intended to be used mainly for stock splits.
      Parameters:
      asofDate - The older date.
      todayVal - The value as of the today date.
      today - Today's date (or at least a date more current than asofDate).
      Returns:
      The value as of the given asofDate, un-adjusted for any splits.
    • adjustRateForSplitsInt

      public final double adjustRateForSplitsInt​(int date, double rate)
      Given a value for this currency at the specified day, return the equivalent value in the currency today after adjusting for splits.
    • adjustRateForSplitsInt

      public final double adjustRateForSplitsInt​(int date, double rate, int endDate)
      Given a rate for this currency at the specified day, return the equivalent rate in the currency at endDate after adjusting for splits.
    • getSplits

      public java.util.List<CurrencySplit> getSplits()
    • sortStockSplits

      public final void sortStockSplits()
    • sortSnapshots

      public final void sortSnapshots()
    • setSnapshotInt

      public final CurrencySnapshot setSnapshotInt​(int date, double userRate)
      If a snapshot exists for the specified date, set the rate and return it. Otherwise create a new snapshot on that date with the given rate and return the new snapshot.
    • setSnapshotInt

      public final CurrencySnapshot setSnapshotInt​(int date, double userRate, CurrencyType relativeCurr)
      If a snapshot exists for the specified date, set the rate and return it. Otherwise create a new snapshot on that date with the given rate and return the new snapshot. If relativeCurr is non-null then the price is first converted to the base price by getting the price of the given currency on the given date.
      Since:
      Moneydance build 616
    • addSnapshotInt

      @Deprecated public final CurrencySnapshot addSnapshotInt​(int date, double userRate)
      Deprecated.
      please use addSnapshotInt(date, userRate, relativeCurrency)
      Create a new snapshot with the given date and (base currency) rate and return the result after adding it to the snapshot list.
    • addSnapshotInt

      public final CurrencySnapshot addSnapshotInt​(int date, double userRate, CurrencyType relativeCurrency)
      Create a new snapshot with the given date and rate and return the result after adding it to the snapshot list.
    • getSnapshots

      public java.util.List<CurrencySnapshot> getSnapshots()
    • getSnapshotForDate

      public CurrencySnapshot getSnapshotForDate​(int date)
      This finds the best historical price entry (aka snapshot) to use for the value of this currency or security on the given date. The best entry should be the latest entry on or before the given date. If that doesn't exist, then the earliest entry after that date. If that doesn't exist then this returns null, in which case the caller should use the current rate or price rather than a snapshot.
      Parameters:
      date -
      Returns:
      the best historical prsice entry for the given date, if any
      Since:
      Moneydance 2017.7 build 1664
    • getRawRateByDateInt

      @Deprecated public final double getRawRateByDateInt​(int dt)
      Deprecated.
      Get the last known raw rate for this currency at the given time. Deprecated: please use getSnapshotForDate(date) and getRawRate()
    • getRateByDate

      @Deprecated public final double getRateByDate​(int dt, CurrencyType relativeCurrency)
      Deprecated.
      Return the user rate as of the given date. Deprecated: please use getRate(date, relativeCurrency)
    • getUserRateByDateInt

      @Deprecated public final double getUserRateByDateInt​(int dt)
      Deprecated.
      Return the user rate as of the given date. Deprecated: please use getSnapshotForDate(date) and getRate(relativeCurrency)
    • setHideInUI

      public final void setHideInUI​(boolean hideInUI)
      Set a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists. Note: This is only available as of build 326
    • getHideInUI

      public final boolean getHideInUI()
      Get a boolean flag indicating whether or not this currency should be displayed in user-friendly currency lists. Note: This is only available as of build 326
    • getIDForScheme

      public java.lang.String getIDForScheme​(java.lang.String idScheme)
      Returns the security/currency ID that was set for this CurrencyType using the given ID scheme. Returns null if no ID was set using the given scheme.
      Since:
      Moneydance build 366
    • setIDForScheme

      public void setIDForScheme​(java.lang.String idScheme, java.lang.String newID)
      Sets the security/currency ID for the given ID scheme.
      Since:
      Moneydance build 366
    • toString

      public final java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • formatFancy

      public final java.lang.String formatFancy​(long amt, char decimalChar, boolean includeDecimals)
      Format the given value with the format <prefix> N,NNN.NN <suffix>
      Since:
      Moneydance 2017
    • formatFancy

      public final java.lang.String formatFancy​(long amt, char decimalChar)
      Format the given value with the format <prefix> N,NNN.NN <suffix>
    • formatSemiFancy

      public final java.lang.String formatSemiFancy​(long amt, char decimalChar)
      Format the given value with the format N,NNN.NN
    • formatNoDecimals

      public final java.lang.String formatNoDecimals​(long amt)
      Format the given value with the format NNNN
    • format

      public final java.lang.String format​(long amt, char decimalChar)
      Format the given value with the format NNNN.NN
    • parse

      public final long parse​(java.lang.String str, char decimalChar)
    • parse

      public final long parse​(java.lang.String str, char decimalChar, boolean quickDecimal)
      Parse the given amount string given the provided decimal character. If quickDecimal is true and getDecimalPlaces() is 2 then a decimal point will be inserted into the string so that "1234" will be parsed as if the user entered "12.34"
    • parseRaw

      public static final long parseRaw​(java.lang.String str)
      Parse a raw currency string, assuming there are enough decimal places. This allows us to parse currency values into long integers without having a currency object because we assume that there are enough decimal places represented in the string. This lets us simply strip out decimal/comma characters are parse the raw integer result.
    • compareToCurrency

      public int compareToCurrency​(CurrencyType curr)
      Return an integer indicating whether this currency is less than, equal to, or greater than the given currency when sorting by type, name, and ID. This method was added in build 600 (Moneydance 2008)
    • currencyFromFields

      public static final CurrencyType currencyFromFields​(int id, java.lang.String idString, java.lang.String name, double rate, int decimalPlaces, java.lang.String prefix, java.lang.String suffix, java.lang.String tickerSymbol, int effectiveDate, int currencyType, CurrencyTable table)
      Construct a CurrencyType object.