Class MoneydanceSyncableItem

java.lang.Object
com.infinitekind.moneydance.model.MoneydanceSyncableItem
All Implemented Interfaces:
com.infinitekind.tiksync.SyncableItem
Direct Known Subclasses:
AbstractTxn, Account, AddressBookEntry, Budget, BudgetItem, CurrencySnapshot, CurrencySplit, CurrencyType, OnlineMailList, OnlinePayeeList, OnlinePaymentList, OnlineService, OnlineTxnList, Reminder, ReportSpec

public class MoneydanceSyncableItem
extends java.lang.Object
implements com.infinitekind.tiksync.SyncableItem
Created by sreilly - 2014.07.01 19:45
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected AccountBook book  
    protected com.infinitekind.tiksync.SyncRecord info  
    static java.lang.String SECURITY_SUBTYPES_ITEM_TYPE  

    Fields inherited from interface com.infinitekind.tiksync.SyncableItem

    ITEM_KEY_ID, ITEM_KEY_TIMESTAMP, ITEM_TYPE_KEY
  • Constructor Summary

    Constructors 
    Constructor Description
    MoneydanceSyncableItem()  
    MoneydanceSyncableItem​(AccountBook book)  
  • Method Summary

    Modifier and Type Method Description
    void addParameters​(java.util.Map<java.lang.String,​java.lang.String> additionalParams)
    Add/merge all parameters from the given map that don't already have a key in the internal map
    void addTags​(java.util.Map<java.lang.String,​java.lang.String> newTags)
    Set the TagSet associated with this object.
    protected boolean autoSyncsChanges()
    Return true if any changes to this object are automatically synced
    static java.util.List<java.lang.String> decodeKeywordList​(java.lang.String keywordString)  
    boolean deleteItem()
    Deletes this item and writes a remove-item entry to the syncing system.
    boolean doesParameterExist​(java.lang.String parameterName)  
    MoneydanceSyncableItem duplicate()
    Return a clone of this object with the same backing info
    static java.lang.String encodeKeywordList​(java.util.List<java.lang.String> keywords)  
    boolean equals​(java.lang.Object obj)  
    Account getAccountParameter​(java.lang.String acctNumKey, java.lang.String acctIDKey, Account defaultValue)
    Lookup and return an account that was referenced by this object using one of the given parameter names.
    AddressBookEntry getAddress()  
    AddressBookEntry getAddressParameter​(java.lang.String addressNumKey, java.lang.String addressIDKey, AddressBookEntry defaultValue)
    Lookup and return an address book entry that was referenced by this object using one of the given parameter names.
    AccountBook getBook()  
    boolean getBooleanParameter​(java.lang.String parameterName, boolean defaultVal)
    Get the specified parameter as a boolean.
    CurrencyType getCurrencyParameter​(java.lang.String parameterName, CurrencyType defaultValue)
    Lookup and return the currency referenced by this object using the given parameter key
    CurrencyType getCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, CurrencyType defaultValue)
    Lookup and return a currency that was referenced by this object using one of the given parameter names.
    CurrencyType getCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, java.lang.String currencyIDString, CurrencyType defaultValue)
    Lookup and return a currency that was referenced by this object using one of the given parameter names.
    double getDoubleParameter​(java.lang.String parameterName, double defaultVal)
    Get the specified parameter as a double (64 bit) float.
    int getIntParameter​(java.lang.String parameterName, int defaultVal)
    Get the specified parameter as an integer.
    java.util.List<java.lang.String> getKeywords()  
    long getLongParameter​(java.lang.String parameterName, long defaultVal)
    Get the specified parameter as a long.
    MoneydanceSyncableItem getOriginalItem()  
    java.lang.String getParameter​(java.lang.String parameterName)  
    java.lang.String getParameter​(java.lang.String parameterName, java.lang.String defaultStr)
    Get the specified parameter name.
    int getParameterCount()
    Get an enumeration of the keys of this object's parameters
    java.util.Set<java.lang.String> getParameterKeys()  
    java.lang.String getPreference​(java.lang.String key, java.lang.String defaultValue)
    Returns the String value associated with the given key in the local data file-specific preferences
    boolean getPreferenceBoolean​(java.lang.String key, boolean defaultValue)
    Returns the boolean value associated with the given key in the local data file-specific preferences
    double getPreferenceDouble​(java.lang.String key, double defaultValue)
    Returns the double value associated with the given key in the local data file-specific preferences
    int getPreferenceInt​(java.lang.String key, int defaultValue)
    Returns the integer value associated with the given key in the local data file-specific preferences
    int[] getPreferenceIntArray​(java.lang.String key)
    Returns an array of integers from in the local data file-specific preferences that were stored using setPreference(String, int[])
    long getPreferenceLong​(java.lang.String key, long defaultValue)
    Returns the long value associated with the given key in the local data file-specific preferences
    java.util.List<java.lang.String> getPreferenceStringList​(java.lang.String key)
    Return a list of string values that were stored with setPreference(key, ...) (ie in the local data file-specific preferences)
    java.util.List<com.infinitekind.tiksync.SyncRecord> getPreferenceSublist​(java.lang.String prefix)
    Returns a list of SyncRecord objects which were stored with setPreference(key, ...) in the local data file-specific preferences.
    com.infinitekind.tiksync.SyncRecord getPreferenceSubset​(java.lang.String prefix)
    Returns a new SyncRecord with the key-value pairs for which the keys have the given prefix in the local data file-specific preferences.
    java.util.List<java.lang.String> getStringListParameter​(java.lang.String key)
    Return a list of string values that were stored with setPreference(key, ...) (ie in the local data file-specific preferences)
    com.infinitekind.tiksync.SyncRecord getSyncInfo()
    save this item to a new SyncRecord and return it.
    java.lang.String getSyncItemType()
    Subclasses should override this to return a static string identifying their type of object
    long getSyncTimestamp()
    The timestamp is handled in the loading/syncing code
    java.lang.String getUUID()
    Return the unique identifier for this object
    boolean hasBeenSynced()
    Returns true if this object has already been recorded as part of this data set.
    int hashCode()  
    boolean hasKeywordSubstring​(java.lang.String matchString, boolean caseSensitive)  
    protected void initialize​(AccountBook book)  
    protected boolean isInEditingMode()  
    protected boolean isSyncable()  
    protected void itemWasUpdated()
    This is called after an item is updated by calling itemWasUpdated(SyncRecord).
    void itemWasUpdated​(com.infinitekind.tiksync.SyncRecord syncInfo)
    Is called when this item was synced from the net so that the object can be made aware of new values
    protected void itemWillSync()
    This is called just before an item will be stored and/or synced when itemWillSync(SyncRecord) is called.
    void itemWillSync​(com.infinitekind.tiksync.SyncRecord syncInfo)
    Called just before this item is synced to the net so that the object can store its values into the given map.
    static MoneydanceSyncableItem makeSyncableItem​(AccountBook accountBook, com.infinitekind.tiksync.SyncRecord itemInfo)  
    void removeParameter​(java.lang.String parameterName)
    Remove the parameter with the given name.
    void setAccountParameter​(java.lang.String acctNumKey, java.lang.String acctIDKey, Account acct)
    Store a reference to acct in this object using the given keys.
    void setAddress​(AddressBookEntry address)  
    void setAddressParameter​(java.lang.String oldAddressIDKey, java.lang.String addressIDKey, AddressBookEntry address)
    Store a reference to address in this account using the keys.
    void setCurrencyParameter​(java.lang.String parameterName, CurrencyType currency)
    Store a reference to the given currency in this object using the given parameter key.
    void setCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, CurrencyType curr)
    Store a reference to currency in this object using the given keys.
    void setCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, java.lang.String currencyIDStringKey, CurrencyType curr)
    Store a reference to currency in this object using the given keys.
    protected void setDirty()
    Marks this object as needing saving and puts it in a buffer for objects needing syncing
    void setEditingMode()
    Put the object into "editing mode" in which no changes will be automatically saved until you call syncItem() on this.
    void setKeywords​(java.util.List<java.lang.String> newKeywords)
    Store a reference to the given keywords (aka tags) in this object.
    void setParameter​(java.lang.String parameterName, boolean parameterValue)
    Set the given parameter name to the given boolean value
    void setParameter​(java.lang.String parameterName, double parameterValue)
    Set the given parameter name to the given double value
    void setParameter​(java.lang.String parameterName, int parameterValue)
    Set the given parameter name to the given integer value
    void setParameter​(java.lang.String parameterName, long parameterValue)
    Set the given parameter name to the given long value
    void setParameter​(java.lang.String name, java.lang.String val)  
    void setParameter​(java.lang.String name, java.util.List value)  
    void setParameter​(java.lang.String name, java.util.Map value)  
    void setParameterNoNotify​(java.lang.String parameterName, java.lang.String parameterValue)
    Set the given parameter name to the given value but don't notify listeners of changes!
    void setPreference​(java.lang.String parameterName, boolean parameterValue)
    Set the given parameter name to the given boolean value, without sending an account-changed event, or recording the account as dirty.
    void setPreference​(java.lang.String parameterName, int parameterValue)
    Set the given parameter name to the given integer value, without sending an account-changed event, or recording the account as dirty.
    void setPreference​(java.lang.String parameterName, java.lang.String parameterValue)
    Set the given preference name to the given value and associate it with this object in _local storage_.
    boolean syncItem()
    Call this to tell the storage that this item was changed and needs to be synced Please don't call this when either of the itemWasUpdated(..) methods are invoked unless you enjoy infinite loops as well as wasting bandwidth and disk space.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • initialize

      protected void initialize​(AccountBook book)
    • getBook

      public final AccountBook getBook()
    • setEditingMode

      public void setEditingMode()
      Put the object into "editing mode" in which no changes will be automatically saved until you call syncItem() on this. Note that calling duplicate() will put the new duplicate into editing mode automatically
    • isInEditingMode

      protected boolean isInEditingMode()
    • syncItem

      public boolean syncItem()
      Call this to tell the storage that this item was changed and needs to be synced Please don't call this when either of the itemWasUpdated(..) methods are invoked unless you enjoy infinite loops as well as wasting bandwidth and disk space.
    • deleteItem

      public boolean deleteItem()
      Deletes this item and writes a remove-item entry to the syncing system. Use with caution!
    • autoSyncsChanges

      protected boolean autoSyncsChanges()
      Return true if any changes to this object are automatically synced
    • setDirty

      protected void setDirty()
      Marks this object as needing saving and puts it in a buffer for objects needing syncing
    • itemWasUpdated

      protected void itemWasUpdated()
      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.
    • itemWasUpdated

      public final void itemWasUpdated​(com.infinitekind.tiksync.SyncRecord syncInfo)
      Description copied from interface: com.infinitekind.tiksync.SyncableItem
      Is called when this item was synced from the net so that the object can be made aware of new values
      Specified by:
      itemWasUpdated in interface com.infinitekind.tiksync.SyncableItem
    • itemWillSync

      protected void itemWillSync()
      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.
    • itemWillSync

      public final void itemWillSync​(com.infinitekind.tiksync.SyncRecord syncInfo)
      Description copied from interface: com.infinitekind.tiksync.SyncableItem
      Called just before this item is synced to the net so that the object can store its values into the given map.
      Specified by:
      itemWillSync in interface com.infinitekind.tiksync.SyncableItem
    • isSyncable

      protected boolean isSyncable()
    • hasBeenSynced

      public boolean hasBeenSynced()
      Returns true if this object has already been recorded as part of this data set. This can often be used to tell whether we're creating a new object or editing an existing one, for example in a transaction or account editor form.
      Since:
      Moneydance build 1511
    • getUUID

      public final java.lang.String getUUID()
      Description copied from interface: com.infinitekind.tiksync.SyncableItem
      Return the unique identifier for this object
      Specified by:
      getUUID in interface com.infinitekind.tiksync.SyncableItem
    • getSyncInfo

      public final com.infinitekind.tiksync.SyncRecord getSyncInfo()
      save this item to a new SyncRecord and return it. This is a shortcut to SyncRecord r = new SyncRecord(); itemWillSync(r); return r;
    • getSyncTimestamp

      public final long getSyncTimestamp()
      The timestamp is handled in the loading/syncing code
      Specified by:
      getSyncTimestamp in interface com.infinitekind.tiksync.SyncableItem
    • getSyncItemType

      public java.lang.String getSyncItemType()
      Subclasses should override this to return a static string identifying their type of object
      Specified by:
      getSyncItemType in interface com.infinitekind.tiksync.SyncableItem
    • duplicate

      public MoneydanceSyncableItem duplicate()
      Return a clone of this object with the same backing info
    • getOriginalItem

      public final MoneydanceSyncableItem getOriginalItem()
    • doesParameterExist

      public final boolean doesParameterExist​(java.lang.String parameterName)
    • getParameter

      public final java.lang.String getParameter​(java.lang.String parameterName)
    • getParameter

      public final java.lang.String getParameter​(java.lang.String parameterName, java.lang.String defaultStr)
      Get the specified parameter name. If the given parameter does not have a value, return the given defaultStr
    • getStringListParameter

      public java.util.List<java.lang.String> getStringListParameter​(java.lang.String key)
      Return a list of string values that were stored with setPreference(key, ...) (ie in the local data file-specific preferences)
      Since:
      build 1570 (Moneydance 2017)
    • getIntParameter

      public final int getIntParameter​(java.lang.String parameterName, int defaultVal)
      Get the specified parameter as an integer. If the given parameter does not have a value, or if it is not an integer, return the given defaul value
    • getLongParameter

      public final long getLongParameter​(java.lang.String parameterName, long defaultVal)
      Get the specified parameter as a long. If the given parameter does not have a value, or if it is not a long, return the given defaul value. This method was created as of build 254.
    • getDoubleParameter

      public double getDoubleParameter​(java.lang.String parameterName, double defaultVal)
      Get the specified parameter as a double (64 bit) float. If the given parameter does not have a value, or if it is not an double, return the given defaul value
    • getBooleanParameter

      public final boolean getBooleanParameter​(java.lang.String parameterName, boolean defaultVal)
      Get the specified parameter as a boolean. If the given parameter does not have a value, or if it is not a boolean, return the given default value
    • setParameter

      public final void setParameter​(java.lang.String parameterName, boolean parameterValue)
      Set the given parameter name to the given boolean value
    • setParameter

      public final void setParameter​(java.lang.String parameterName, int parameterValue)
      Set the given parameter name to the given integer value
    • setParameter

      public final void setParameter​(java.lang.String parameterName, long parameterValue)
      Set the given parameter name to the given long value
    • setParameter

      public final void setParameter​(java.lang.String parameterName, double parameterValue)
      Set the given parameter name to the given double value
    • setPreference

      public final void setPreference​(java.lang.String parameterName, boolean parameterValue)
      Set the given parameter name to the given boolean value, without sending an account-changed event, or recording the account as dirty.
    • setPreference

      public final void setPreference​(java.lang.String parameterName, int parameterValue)
      Set the given parameter name to the given integer value, without sending an account-changed event, or recording the account as dirty.
    • setPreference

      public final void setPreference​(java.lang.String parameterName, java.lang.String parameterValue)
      Set the given preference name to the given value and associate it with this object in _local storage_. This will not be synced and neither will it result in any modification notifications being triggered.
    • setParameter

      public final void setParameter​(java.lang.String name, java.lang.String val)
    • addParameters

      public void addParameters​(java.util.Map<java.lang.String,​java.lang.String> additionalParams)
      Add/merge all parameters from the given map that don't already have a key in the internal map
    • addTags

      public final void addTags​(java.util.Map<java.lang.String,​java.lang.String> newTags)
      Set the TagSet associated with this object. This should only be called when initially constructing this object from old data files. In other words, DON'T USE THIS!
    • setParameter

      public final void setParameter​(java.lang.String name, java.util.Map value)
    • setParameter

      public final void setParameter​(java.lang.String name, java.util.List value)
    • getPreferenceSubset

      public com.infinitekind.tiksync.SyncRecord getPreferenceSubset​(java.lang.String prefix)
      Returns a new SyncRecord with the key-value pairs for which the keys have the given prefix in the local data file-specific preferences.
    • getPreferenceStringList

      public java.util.List<java.lang.String> getPreferenceStringList​(java.lang.String key)
      Return a list of string values that were stored with setPreference(key, ...) (ie in the local data file-specific preferences)
    • getPreferenceSublist

      public java.util.List<com.infinitekind.tiksync.SyncRecord> getPreferenceSublist​(java.lang.String prefix)
      Returns a list of SyncRecord objects which were stored with setPreference(key, ...) in the local data file-specific preferences.
    • getPreferenceInt

      public int getPreferenceInt​(java.lang.String key, int defaultValue)
      Returns the integer value associated with the given key in the local data file-specific preferences
    • getPreferenceIntArray

      public int[] getPreferenceIntArray​(java.lang.String key)
      Returns an array of integers from in the local data file-specific preferences that were stored using setPreference(String, int[])
    • getPreferenceLong

      public long getPreferenceLong​(java.lang.String key, long defaultValue)
      Returns the long value associated with the given key in the local data file-specific preferences
    • getPreferenceDouble

      public double getPreferenceDouble​(java.lang.String key, double defaultValue)
      Returns the double value associated with the given key in the local data file-specific preferences
    • getPreferenceBoolean

      public boolean getPreferenceBoolean​(java.lang.String key, boolean defaultValue)
      Returns the boolean value associated with the given key in the local data file-specific preferences
    • getPreference

      public java.lang.String getPreference​(java.lang.String key, java.lang.String defaultValue)
      Returns the String value associated with the given key in the local data file-specific preferences
    • setParameterNoNotify

      public final void setParameterNoNotify​(java.lang.String parameterName, java.lang.String parameterValue)
      Set the given parameter name to the given value but don't notify listeners of changes!
    • removeParameter

      public final void removeParameter​(java.lang.String parameterName)
      Remove the parameter with the given name.
    • getParameterCount

      public final int getParameterCount()
      Get an enumeration of the keys of this object's parameters
    • getAccountParameter

      public Account getAccountParameter​(java.lang.String acctNumKey, java.lang.String acctIDKey, Account defaultValue)
      Lookup and return an account that was referenced by this object using one of the given parameter names. Priority is given to acctIDKey which should reference the UUID of the account being referenced. If the acctIDKey lookup is not successfull then a lookup is done using the acctNumKey which references the integer account ID that is returned by getAccountNum() on the referenced account. If either acctNumKey or acctIDKey is null then that key is not checked for an account reference.
    • setAccountParameter

      public void setAccountParameter​(java.lang.String acctNumKey, java.lang.String acctIDKey, Account acct)
      Store a reference to acct in this object using the given keys. The acctNumKey, if non-null, refers to the number returned by acct.getAccountNum(). The acctIDKey, if non-null, refers to the string returned by acct.getUUID() and will generally be more reliable and have a faster lookup time. If not storing references to accounts that have been migrated from before Moneydance 2015 then please only use the acctIDKey to store references.
    • getCurrencyParameter

      public CurrencyType getCurrencyParameter​(java.lang.String parameterName, CurrencyType defaultValue)
      Lookup and return the currency referenced by this object using the given parameter key
      Since:
      build 1800 (Moneydance 2018)
    • setCurrencyParameter

      public void setCurrencyParameter​(java.lang.String parameterName, CurrencyType currency)
      Store a reference to the given currency in this object using the given parameter key.
      Since:
      build 1800 (Moneydance 2018)
    • getCurrencyParameter

      public CurrencyType getCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, CurrencyType defaultValue)
      Lookup and return a currency that was referenced by this object using one of the given parameter names. Priority is given to currIDKey which should reference the UUID of the currency being referenced. If the currIDKey lookup is not successfull then a lookup is done using the currNumKey which references the integer account ID that is returned by getID() method on the referenced currency. If either currNumKey or currIDKey is null then that key is not checked for a currency reference.
    • getCurrencyParameter

      public CurrencyType getCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, java.lang.String currencyIDString, CurrencyType defaultValue)
      Lookup and return a currency that was referenced by this object using one of the given parameter names. Priority is given to currIDKey which should reference the UUID of the currency being referenced. If the currIDKey lookup is not successfull then a lookup is done using the currNumKey which references the integer account ID that is returned by getID() method on the referenced currency. If no currency has been found then the parameter value associated with the currencyIDString key is checked for a currency ID string (usually the three character ISO currency ID). Any of the parameters currNumKey, currIDKey, or currencyIDString can be null in which case that parameter is not checked for a currency reference.
      Since:
      build 1664 (Moneydance 2017.7)
    • setCurrencyParameter

      public void setCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, CurrencyType curr)
      Store a reference to currency in this object using the given keys. The currNumKey, if non-null, refers to the number returned by curr.getID(). The currIDKey, if non-null, refers to the string returned by curr.getUUID() and will generally be more reliable and have a faster lookup time. If not storing references to accounts that have been migrated from before Moneydance 2015 then please only use the acctIDKey to store references.
    • setCurrencyParameter

      public void setCurrencyParameter​(java.lang.String currNumKey, java.lang.String currIDKey, java.lang.String currencyIDStringKey, CurrencyType curr)
      Store a reference to currency in this object using the given keys. The currNumKey, if non-null, refers to the number returned by curr.getID(). The currIDKey, if non-null, refers to the string returned by curr.getUUID() and will generally be more reliable and have a faster lookup time. If not storing references to accounts that have been migrated from before Moneydance 2015 then please only use the acctIDKey to store references.
    • getAddressParameter

      public AddressBookEntry getAddressParameter​(java.lang.String addressNumKey, java.lang.String addressIDKey, AddressBookEntry defaultValue)
      Lookup and return an address book entry that was referenced by this object using one of the given parameter names. Priority is given to addressIDKey which should reference the UUID of the address being referenced. If the addressIDKey lookup is not successfull then a lookup is done using the addressNumKey which references the integer address ID that is returned by getID() on the referenced account. If either addressNumKey or addressIDKey is null then that key is not checked for an account reference.
    • setAddress

      public void setAddress​(AddressBookEntry address)
    • getAddress

      public AddressBookEntry getAddress()
    • setAddressParameter

      public void setAddressParameter​(java.lang.String oldAddressIDKey, java.lang.String addressIDKey, AddressBookEntry address)
      Store a reference to address in this account using the keys. The acctNumKey, if non-null, refers to the number returned by address.getAccountNum(). The acctIDKey, if non-null, refers to the string returned by address.getUUID() and will generally be more reliable and have a faster lookup time. If not storing references to accounts that have been migrated from before Moneydance 2015 then please only use the acctIDKey to store references.
    • setKeywords

      public void setKeywords​(java.util.List<java.lang.String> newKeywords)
      Store a reference to the given keywords (aka tags) in this object. Note this removes any tab characters
    • getKeywords

      public java.util.List<java.lang.String> getKeywords()
    • hasKeywordSubstring

      public boolean hasKeywordSubstring​(java.lang.String matchString, boolean caseSensitive)
    • encodeKeywordList

      public static java.lang.String encodeKeywordList​(java.util.List<java.lang.String> keywords)
    • decodeKeywordList

      public static java.util.List<java.lang.String> decodeKeywordList​(java.lang.String keywordString)
    • getParameterKeys

      public final java.util.Set<java.lang.String> getParameterKeys()
    • makeSyncableItem

      public static MoneydanceSyncableItem makeSyncableItem​(AccountBook accountBook, com.infinitekind.tiksync.SyncRecord itemInfo)
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object