com.moneydance.apps.md.model
Class AccountUtil

java.lang.Object
  extended by com.moneydance.apps.md.model.AccountUtil

public abstract class AccountUtil
extends java.lang.Object

Miscellaneous functions


Field Summary
static int ACCOUNT
          sort by account (this is always 'other' acct - the first split's account).
static java.util.Comparator<Account> ACCOUNT_NAME_COMPARATOR
          Compare two accounts by name, for sorting a list by account name.
static int ACTION
           
static int AMOUNT
           
static java.util.Comparator<Txn> AMOUNT_COMPARATOR
           
static int CATEGORY
          Sort by category account.
static int CHECKNUM
           
static int CHECKNUM_INT
           
static int CHECKNUM_PARENT
          Sort by check#, but only check the parent's check# and ignore the split's.
static int DATE
           
static int DATE_ENTERED
           
static java.util.Comparator<Txn> DATE_ENTERED_COMPARATOR
          Comparator for sorting transactions by date-entered.
static int DATE_THEN_AMOUNT
           
static java.util.Comparator<Txn> DATE_THEN_AMOUNT_COMPARATOR
           
static int DATE_THEN_CHECKNUM
           
static int DATE_THEN_STATUS
           
static int DESCRIPTION
           
static int NOT_CATEGORY
          Sort by non-category account.
static int STATUS_THEN_CKNUM
           
static int STATUS_THEN_DATE
           
static int TAXDATE_THEN_CHECKNUM
          Sort by tax date then by check#.
 
Constructor Summary
AccountUtil()
           
 
Method Summary
static int compAccountDateEntered(AbstractTxn t1, AbstractTxn t2)
           
static long compAmount(AbstractTxn t1, AbstractTxn t2)
           
static int compCategoryDateEntered(AbstractTxn t1, AbstractTxn t2, boolean shouldBeCat)
          Compare the category or non-category account first, and if it is the same, then compare the date for two transactions.
static int compCategoryOrAccount(AbstractTxn t1, AbstractTxn t2, boolean shouldBeCat)
          Compare the category or non-category account for two transactions.
static int compCheckIntId(AbstractTxn t1, AbstractTxn t2)
           
static int compCheckNumAmt(AbstractTxn t1, AbstractTxn t2)
          Compare the two transactions based on their check number and then their amount if the check numbers are the same.
static int compCheckNumBoth(AbstractTxn t1, AbstractTxn t2)
          Compare the check number field for both numeric only and also text values.
static int compCheckNumBoth(AbstractTxn t1, AbstractTxn t2, boolean forceUseParent)
          Compare the check number field for both numeric only and also text values.
static int compCheckNumId(AbstractTxn t1, AbstractTxn t2)
           
static int compCheckNumParent(AbstractTxn t1, AbstractTxn t2)
          Compare the check number field, but only use the parent transaction's check number, do not use the check number for a split.
static int compDate(AbstractTxn t1, AbstractTxn t2)
          Compare the transaction date of two transactions.
static int compDateCheckNum(AbstractTxn t1, AbstractTxn t2, boolean useTaxDate)
          Compare two transactions by date.
static int compDateDateEntered(AbstractTxn t1, AbstractTxn t2)
           
static int compDateEntered(AbstractTxn t1, AbstractTxn t2)
           
static long compDateThenAmount(AbstractTxn t1, AbstractTxn t2)
           
static int compDateThenStatus(AbstractTxn t1, AbstractTxn t2)
           
static int compDescription(AbstractTxn t1, AbstractTxn t2)
          Compare the description, or 'payee', of two transactions.
static int compDescriptionDate(AbstractTxn t1, AbstractTxn t2)
           
static int compDescriptionDateEntered(AbstractTxn t1, AbstractTxn t2)
           
static int compId(AbstractTxn t1, AbstractTxn t2)
           
static int compStatus(AbstractTxn t1, AbstractTxn t2)
           
static int compStatusChecknum(AbstractTxn t1, AbstractTxn t2)
           
static int compTaxDate(AbstractTxn t1, AbstractTxn t2)
          Compare the tax date of two transactions.
static java.util.List<java.lang.Integer> getAccountIdsOfType(RootAccount rootAccount, int accountType)
          Get all account IDs of a particular type.
static java.util.Iterator<Account> getAccountIterator(Account account)
          Return an iterator for all of the accounts that are under the given account.
static long getBalanceAsOfDate(RootAccount rootAccount, Account account, int asofDate)
          Get a single account's balance as of a given date.
static long getBalanceAsOfDate(RootAccount rootAccount, Account account, int asofDate, boolean outOfDateAsZero)
          Get a single account's balance as of a given date.
static long[] getBalancesAsOfDates(RootAccount rootAccount, Account account, int[] asofDates)
          Get a single account's balance as of a list of given dates.
static long[] getBalancesAsOfDates(RootAccount rootAccount, Account account, int[] asofDates, boolean outOfDateAsZero)
          Get a single account's balance as of a list of given dates.
static Account getCategoryFromTxn(AbstractTxn txn)
          Return the category account from a transaction.
static Account getDefaultCategoryForAcct(Account acct)
          Get the default category for use transactions in the given account.
static Account getDefaultTransferAcct(Account acct)
          Get the default transfer account for transaction in the given account.
static Account getNonCategoryFromTxn(AbstractTxn txn)
          Return the non-category account from a transaction.
static int insertSortedTransaction(TxnSet transactions, AbstractTxn t, int sortedBy)
          Inserts the given transaction into the specified array in sorted order.
static boolean isCompatibleWith(OnlineAccountInfo olAcct, Account acct)
          Returns true iff the given online account can be associated with the given local account.
static boolean isTransactionSorted(int index, AbstractTxn t, TxnSet transactions, int sortedBy)
           
static void sortTransactions(TxnSet transactions, int sortField)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE

public static final int DATE
See Also:
Constant Field Values

DATE_ENTERED

public static final int DATE_ENTERED
See Also:
Constant Field Values

DESCRIPTION

public static final int DESCRIPTION
See Also:
Constant Field Values

AMOUNT

public static final int AMOUNT
See Also:
Constant Field Values

STATUS_THEN_DATE

public static final int STATUS_THEN_DATE
See Also:
Constant Field Values

ACCOUNT

public static final int ACCOUNT
sort by account (this is always 'other' acct - the first split's account).

See Also:
Constant Field Values

DATE_THEN_STATUS

public static final int DATE_THEN_STATUS
See Also:
Constant Field Values

DATE_THEN_AMOUNT

public static final int DATE_THEN_AMOUNT
See Also:
Constant Field Values

DATE_THEN_CHECKNUM

public static final int DATE_THEN_CHECKNUM
See Also:
Constant Field Values

CHECKNUM

public static final int CHECKNUM
See Also:
Constant Field Values

ACTION

public static final int ACTION
See Also:
Constant Field Values

CHECKNUM_INT

public static final int CHECKNUM_INT
See Also:
Constant Field Values

STATUS_THEN_CKNUM

public static final int STATUS_THEN_CKNUM
See Also:
Constant Field Values

CATEGORY

public static final int CATEGORY
Sort by category account. Only use this when sorting splits.

See Also:
Constant Field Values

NOT_CATEGORY

public static final int NOT_CATEGORY
Sort by non-category account. Only use this when sorting splits.

See Also:
Constant Field Values

TAXDATE_THEN_CHECKNUM

public static final int TAXDATE_THEN_CHECKNUM
Sort by tax date then by check#.

See Also:
Constant Field Values

CHECKNUM_PARENT

public static final int CHECKNUM_PARENT
Sort by check#, but only check the parent's check# and ignore the split's.

See Also:
Constant Field Values

ACCOUNT_NAME_COMPARATOR

public static final java.util.Comparator<Account> ACCOUNT_NAME_COMPARATOR
Compare two accounts by name, for sorting a list by account name. Uses the full name so that sub-accounts are kept with their parent accounts.


DATE_ENTERED_COMPARATOR

public static final java.util.Comparator<Txn> DATE_ENTERED_COMPARATOR
Comparator for sorting transactions by date-entered.

Since:
build 744

AMOUNT_COMPARATOR

public static final java.util.Comparator<Txn> AMOUNT_COMPARATOR

DATE_THEN_AMOUNT_COMPARATOR

public static final java.util.Comparator<Txn> DATE_THEN_AMOUNT_COMPARATOR
Constructor Detail

AccountUtil

public AccountUtil()
Method Detail

getDefaultCategoryForAcct

public static final Account getDefaultCategoryForAcct(Account acct)
Get the default category for use transactions in the given account. This is guaranteed to return a non-null value.

Since:
build 410

getDefaultTransferAcct

public static final Account getDefaultTransferAcct(Account acct)
Get the default transfer account for transaction in the given account.

Since:
build 565

getAccountIterator

public static java.util.Iterator<Account> getAccountIterator(Account account)
Return an iterator for all of the accounts that are under the given account. If the RootAccount is provided, all accounts will be included in the iterator.


isCompatibleWith

public static boolean isCompatibleWith(OnlineAccountInfo olAcct,
                                       Account acct)
Returns true iff the given online account can be associated with the given local account.


insertSortedTransaction

public static int insertSortedTransaction(TxnSet transactions,
                                          AbstractTxn t,
                                          int sortedBy)
Inserts the given transaction into the specified array in sorted order.


compAmount

public static long compAmount(AbstractTxn t1,
                              AbstractTxn t2)

compDateThenAmount

public static long compDateThenAmount(AbstractTxn t1,
                                      AbstractTxn t2)

compDateThenStatus

public static int compDateThenStatus(AbstractTxn t1,
                                     AbstractTxn t2)

compStatus

public static int compStatus(AbstractTxn t1,
                             AbstractTxn t2)

compStatusChecknum

public static int compStatusChecknum(AbstractTxn t1,
                                     AbstractTxn t2)

compDescriptionDateEntered

public static int compDescriptionDateEntered(AbstractTxn t1,
                                             AbstractTxn t2)

compDescriptionDate

public static int compDescriptionDate(AbstractTxn t1,
                                      AbstractTxn t2)

compDescription

public static int compDescription(AbstractTxn t1,
                                  AbstractTxn t2)
Compare the description, or 'payee', of two transactions.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compDateCheckNum

public static int compDateCheckNum(AbstractTxn t1,
                                   AbstractTxn t2,
                                   boolean useTaxDate)
Compare two transactions by date.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
useTaxDate - True if comparing tax dates, false if transaction date.
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compDate

public static int compDate(AbstractTxn t1,
                           AbstractTxn t2)
Compare the transaction date of two transactions.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compTaxDate

public static int compTaxDate(AbstractTxn t1,
                              AbstractTxn t2)
Compare the tax date of two transactions.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compDateDateEntered

public static int compDateDateEntered(AbstractTxn t1,
                                      AbstractTxn t2)

compAccountDateEntered

public static int compAccountDateEntered(AbstractTxn t1,
                                         AbstractTxn t2)

compCategoryDateEntered

public static int compCategoryDateEntered(AbstractTxn t1,
                                          AbstractTxn t2,
                                          boolean shouldBeCat)
Compare the category or non-category account first, and if it is the same, then compare the date for two transactions.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
shouldBeCat - True if comparing category accounts, false if comparing non-category accounts.
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compCategoryOrAccount

public static int compCategoryOrAccount(AbstractTxn t1,
                                        AbstractTxn t2,
                                        boolean shouldBeCat)
Compare the category or non-category account for two transactions.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
shouldBeCat - True if comparing category accounts, false if comparing non-category accounts.
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

getCategoryFromTxn

public static Account getCategoryFromTxn(AbstractTxn txn)
Return the category account from a transaction. If there is no category account on either side of the transaction, or if there is more than one potential split that could match, return null. Expense types are typically more numerous than income accounts, so check them first.

Parameters:
txn - The transaction to check.
Returns:
The category account for the transaction, or null.

getNonCategoryFromTxn

public static Account getNonCategoryFromTxn(AbstractTxn txn)
Return the non-category account from a transaction. If there is only category accounts on both sides of the transaction, or if it is in a category account with more than one split, return null.

Parameters:
txn - The transaction to check.
Returns:
The non-category account for the transaction, or null.

compDateEntered

public static final int compDateEntered(AbstractTxn t1,
                                        AbstractTxn t2)

compCheckNumBoth

public static int compCheckNumBoth(AbstractTxn t1,
                                   AbstractTxn t2)
Compare the check number field for both numeric only and also text values.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compCheckNumBoth

public static int compCheckNumBoth(AbstractTxn t1,
                                   AbstractTxn t2,
                                   boolean forceUseParent)
Compare the check number field for both numeric only and also text values.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
forceUseParent - True if always getting the check# from the parent, false otherwise.
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compCheckNumId

public static int compCheckNumId(AbstractTxn t1,
                                 AbstractTxn t2)

compCheckNumParent

public static int compCheckNumParent(AbstractTxn t1,
                                     AbstractTxn t2)
Compare the check number field, but only use the parent transaction's check number, do not use the check number for a split. This is used for sorting transactions for display to the user. At this time the user may not specify a check number for a split, so it is irrelevant and messes up the sort order.

Parameters:
t1 - First transaction to compare (left hand side).
t2 - Second transaction to compare (right hand side).
Returns:
0 if they are the same, < 0 if left is less than right, > 0 otherwise.

compCheckNumAmt

public static int compCheckNumAmt(AbstractTxn t1,
                                  AbstractTxn t2)
Compare the two transactions based on their check number and then their amount if the check numbers are the same. @since build 566


compCheckIntId

public static final int compCheckIntId(AbstractTxn t1,
                                       AbstractTxn t2)

compId

public static int compId(AbstractTxn t1,
                         AbstractTxn t2)

isTransactionSorted

public static boolean isTransactionSorted(int index,
                                          AbstractTxn t,
                                          TxnSet transactions,
                                          int sortedBy)

sortTransactions

public static void sortTransactions(TxnSet transactions,
                                    int sortField)

getAccountIdsOfType

public static java.util.List<java.lang.Integer> getAccountIdsOfType(RootAccount rootAccount,
                                                                    int accountType)
Get all account IDs of a particular type.

Parameters:
rootAccount - The root account object.
accountType - The type of account to get a list for.
Returns:
A list of all account IDs of the specified type.

getBalanceAsOfDate

public static long getBalanceAsOfDate(RootAccount rootAccount,
                                      Account account,
                                      int asofDate)
Get a single account's balance as of a given date. Transactions for that date will be included, so it is the balance as of the end of the given date. The balance will be in the account's currency type.

This method will return 0 if the account did not exist as of the given date.

Parameters:
rootAccount - The root account for all transactions.
account - Account to obtain the balance for.
asofDate - The date to obtain the balance for.
Returns:
The balance (in the account's currency) of the given account as of the end of the given date.

getBalanceAsOfDate

public static long getBalanceAsOfDate(RootAccount rootAccount,
                                      Account account,
                                      int asofDate,
                                      boolean outOfDateAsZero)
Get a single account's balance as of a given date. Transactions for that date will be included, so it is the balance as of the end of the given date. The balance will be in the account's currency type.

Parameters:
rootAccount - The root account for all transactions.
account - Account to obtain the balance for.
asofDate - The date to obtain the balance for.
outOfDateAsZero - True if out-of-date returns a zero balance, false if it returns a Long.MIN_VALUE if the account did not exist.
Returns:
The balance (in the account's currency) of the given account as of the end of the given date.

getBalancesAsOfDates

public static long[] getBalancesAsOfDates(RootAccount rootAccount,
                                          Account account,
                                          int[] asofDates)
Get a single account's balance as of a list of given dates. The balances will be in the account's currency type. This method returns a zero balance if the given dates are before the earliest transaction and the account's start date.

Parameters:
rootAccount - The root account for all transactions.
account - Account to obtain the balance for.
asofDates - The dates to obtain the balance for.
Returns:
The balances (in the account's currency) of the given account as of the end of the corresponding given dates in asofDates.

getBalancesAsOfDates

public static long[] getBalancesAsOfDates(RootAccount rootAccount,
                                          Account account,
                                          int[] asofDates,
                                          boolean outOfDateAsZero)
Get a single account's balance as of a list of given dates. The balances will be in the account's currency type. If a given date is prior to both the earliest transaction and the account's start date, then return Long.MIN_VALUE for the balance. Transactions for the given date will be included, so it is the balance as of the end of the given date. If outOfDateAsZero is true, this is overridden and 0 is returned even if the date is too early.

Parameters:
rootAccount - The root account for all transactions.
account - Account to obtain the balance for.
asofDates - The dates to obtain the balance for.
outOfDateAsZero - True if out-of-date returns a zero balance, false if it returns a Long.MIN_VALUE if the account did not exist.
Returns:
The balances (in the account's currency) of the given account as of the end of the corresponding given dates in asofDates.