jgnash.engine
Class Account

java.lang.Object
  extended by jgnash.engine.StoredObject
      extended by jgnash.engine.Account
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Account>
Direct Known Subclasses:
RootAccount

public class Account
extends StoredObject
implements java.lang.Comparable<Account>, java.lang.Cloneable

Abstract Account class

Version:
$Id$
Author:
Craig Cavanaugh, Jeff Prickett prickett@users.sourceforge.net
See Also:
Serialized Form

Field Summary
private  java.math.BigDecimal accountBalance
          Balance of the account
private  java.lang.String accountNumber
          User definable account number
private  java.lang.String accountType
           
private  java.lang.String bankId
          User definable bank id.
private  AccountType cachedAccountType
           
private  java.util.concurrent.locks.ReadWriteLock childLock
           
private  java.util.List<Account> children
           
private  CurrencyNode currencyNode
          CurrencyNode for this account
private  java.lang.String description
           
private  boolean locked
           
private static java.util.logging.Logger logger
           
private  java.lang.String name
           
private  java.lang.String notes
           
(package private)  Account parentAccount
           
private  boolean placeHolder
           
private  java.util.Map<java.lang.String,java.lang.Object> propertyMap
           
private  AccountProxy proxy
           
private  java.math.BigDecimal reconciledBalance
          Reconciled balance of the account
(package private)  java.util.List<SecurityNode> securities
           
private static long serialVersionUID
           
private  java.util.concurrent.locks.ReadWriteLock transactionLock
           
(package private)  java.util.List<Transaction> transactions
           
private  boolean visible
           
 
Constructor Summary
Account()
          No argument public constructor for reflection purposes.
Account(AccountType type, CurrencyNode node)
           
 
Method Summary
protected  boolean addChild(Account child)
          Add account child account given it's reference
 boolean addSecurity(SecurityNode node)
          Adds account commodity to the list and ensures duplicates are not added.
(package private)  boolean addTransaction(Transaction tran)
          Adds account transaction in chronological order
private  java.math.BigDecimal adjustForExchangeRate(java.math.BigDecimal amount, CurrencyNode node)
           
(package private)  void clearCachedBalances()
          Clear cached account balances so they will be recalculated
 java.lang.Object clone()
          When overridden, this should return account shallow copy only.
 int compareTo(Account acc)
          Compares two Account for ordering.
 boolean contains(Account account)
          Determine if the supplied account is a child of this account
 boolean contains(Transaction tran)
          Determines if the specified transaction is attach to this account
 boolean containsSecurity(SecurityNode node)
           
 boolean equals(java.lang.Object other)
          Default equals override
 java.lang.String getAccountNumber()
          Returns the account number.
private static java.lang.String getAccountSeparator()
           
 AccountType getAccountType()
           
 java.math.BigDecimal getBalance()
          The account balance is cached to improve performance and reduce thrashing of the GC system.
private  java.math.BigDecimal getBalance(CurrencyNode node)
          The account balance is cached to improve performance and reduce thrashing of the GC system.
 java.math.BigDecimal getBalance(java.util.Date date)
          Returns the account balance up to and inclusive of the supplied date
 java.math.BigDecimal getBalance(java.util.Date date, CurrencyNode node)
          Returns the account balance up to and inclusive of the supplied date.
 java.math.BigDecimal getBalance(java.util.Date start, java.util.Date end)
          Returns the balance of the transactions inclusive of the start and end dates.
 java.math.BigDecimal getBalance(java.util.Date startDate, java.util.Date endDate, CurrencyNode node)
          Returns the account balance up to and inclusive of the supplied date.
 java.math.BigDecimal getBalanceAt(int index)
          Get the account balance up to account specified index.
 java.lang.String getBankId()
           
 java.math.BigDecimal getCashBalance()
          Returns the cash balance of this account
 int getChildCount()
          Returns the number of children this account has
 java.util.List<Account> getChildren()
          Returns account list of the children
 CurrencyNode getCurrencyNode()
          Returns the commodity node for this account.
 int getDepth()
           
 java.lang.String getDescription()
           
 java.util.Date getFirstUnreconciledTransactionDate()
          Returns the date of the first unreconciled transaction
 java.math.BigDecimal getMarketValue()
          Returns the market value of this account
 java.lang.String getName()
           
 java.lang.String getNextTransactionNumber()
          Searches through the transactions and determines the next largest transaction number.
 java.lang.String getNotes()
          Returns the notes for this account
 java.math.BigDecimal getOpeningBalanceForReconcile()
          Get the default opening balance for reconciling the account
 Account getParent()
          Returns the parent account.
 java.lang.String getPathName()
           
 java.util.Set<AccountProperty> getProperties()
          Returns account Set of AccountProperties added to this account.
 java.lang.Object getProperty(AccountProperty key)
          Gets an account property
(package private)  AccountProxy getProxy()
           
 java.math.BigDecimal getReconciledBalance()
          The reconciled balance is cached to improve performance and reduce thrashing of the GC system.
private  java.math.BigDecimal getReconciledBalance(CurrencyNode node)
           
 java.math.BigDecimal getReconciledTreeBalance()
          Returns the reconciled balance of the account plus any child accounts.
private  java.math.BigDecimal getReconciledTreeBalance(CurrencyNode node)
          Returns the reconciled balance of the account plus any child accounts.
 java.util.Set<SecurityNode> getSecurities()
           
 Transaction getTransactionAt(int index)
          Returns the transaction at the specified index
 int getTransactionCount()
          Returns the number of transactions attached to this account.
(package private)  java.util.concurrent.locks.ReadWriteLock getTransactionLock()
           
 java.util.List<Transaction> getTransactions()
          Returns account shallow copy of the transaction array for this account
 java.util.List<Transaction> getTransactions(java.util.Date startDate, java.util.Date endDate)
          Returns an array of transactions that occur after account specified cut off date.
 java.math.BigDecimal getTreeBalance()
          Returns the balance of the account plus any child accounts
private  java.math.BigDecimal getTreeBalance(CurrencyNode node)
          Returns the balance of the account plus any child accounts.
 java.math.BigDecimal getTreeBalance(java.util.Date start, java.util.Date end)
          Returns the the balance of the account plus any child accounts inclusive of the start and end dates.
 java.math.BigDecimal getTreeBalance(java.util.Date start, java.util.Date end, CurrencyNode node)
          Returns the the balance of the account plus any child accounts inclusive of the start and end dates.
 java.util.Set<SecurityNode> getUsedSecurities()
          Returns a set of used SecurityNodes
 int hashCode()
          Override hashCode to use uuid
 int indexOf(Transaction tran)
          Returns the index of the specified Transaction within this Account.
 boolean instanceOf(AccountType type)
          Shortcut method to check account type
 boolean isLocked()
           
 boolean isParent()
          Determines is this account has any child accounts.
 boolean isPlaceHolder()
           
 boolean isVisible()
          Returns the visibility of the account
 boolean memberOf(AccountGroup group)
          Shortcut method to check account group membership
protected  java.lang.Object readResolve()
           
(package private)  boolean removeChild(Account child)
          Removes account child account.
protected  boolean removeProperty(AccountProperty key)
          Remove an AccountProperty from this account
(package private)  boolean removeSecurity(SecurityNode node)
          Remove a security
(package private)  boolean removeTransaction(Transaction tran)
          Removes the specified transaction from this account
 void setAccountNumber(java.lang.String account)
           
(package private)  void setAccountType(AccountType type)
           
 void setBankId(java.lang.String bankId)
           
(package private)  void setCurrencyNode(CurrencyNode node)
          Sets the commodity node for this account.
 void setDescription(java.lang.String desc)
           
 void setLocked(boolean locked)
           
 void setName(java.lang.String newName)
           
 void setNotes(java.lang.String notes)
          Sets the notes for this account
 boolean setParent(Account account)
          Sets the parent of this account
 void setPlaceHolder(boolean placeHolder)
           
 void setProperty(AccountProperty key, java.lang.Object value)
          Sets / Adds an AccountProperty
 void setVisible(boolean visible)
          Changes the visibility of the account
private  void sortChildren()
           
 java.lang.String toString()
           
 
Methods inherited from class jgnash.engine.StoredObject
getUuid, isMarkedForRemoval, setMarkedForRemoval
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

accountType

private java.lang.String accountType

cachedAccountType

private transient AccountType cachedAccountType

placeHolder

private boolean placeHolder

locked

private boolean locked

parentAccount

Account parentAccount

visible

private boolean visible

name

private java.lang.String name

description

private java.lang.String description

notes

private java.lang.String notes

currencyNode

private CurrencyNode currencyNode
CurrencyNode for this account


children

private java.util.List<Account> children

transactions

java.util.List<Transaction> transactions

securities

java.util.List<SecurityNode> securities

accountBalance

private java.math.BigDecimal accountBalance
Balance of the account


reconciledBalance

private java.math.BigDecimal reconciledBalance
Reconciled balance of the account


accountNumber

private java.lang.String accountNumber
User definable account number


bankId

private java.lang.String bankId
User definable bank id. Useful for OFX import


propertyMap

private java.util.Map<java.lang.String,java.lang.Object> propertyMap

transactionLock

private transient java.util.concurrent.locks.ReadWriteLock transactionLock

childLock

private transient java.util.concurrent.locks.ReadWriteLock childLock

proxy

private transient AccountProxy proxy

logger

private static final java.util.logging.Logger logger
Constructor Detail

Account

public Account()
No argument public constructor for reflection purposes. Do not use to create account new instance


Account

public Account(AccountType type,
               CurrencyNode node)
Method Detail

getTransactionLock

java.util.concurrent.locks.ReadWriteLock getTransactionLock()

getProxy

AccountProxy getProxy()

setAccountType

final void setAccountType(AccountType type)

setProperty

public void setProperty(AccountProperty key,
                        java.lang.Object value)
Sets / Adds an AccountProperty

Parameters:
key - AccountProperty
value - actual object to add or set

removeProperty

protected boolean removeProperty(AccountProperty key)
Remove an AccountProperty from this account

Parameters:
key - AccountProperty to remove
Returns:
true if this account contained the AccountProperty

getProperty

public java.lang.Object getProperty(AccountProperty key)
Gets an account property

Parameters:
key - AccountProperty to get
Returns:
not null if the account contained the property

getProperties

public java.util.Set<AccountProperty> getProperties()
Returns account Set of AccountProperties added to this account.

Returns:
Set of AccountProperties. An empty Set will be returned in none exist.

clearCachedBalances

void clearCachedBalances()
Clear cached account balances so they will be recalculated


addTransaction

boolean addTransaction(Transaction tran)
Adds account transaction in chronological order

Parameters:
tran - the Transaction to be added
Returns:
true the transaction was added successful false the transaction was already attached to this account

removeTransaction

boolean removeTransaction(Transaction tran)
Removes the specified transaction from this account

Parameters:
tran - the Transaction to be removed
Returns:
true the transaction removal was successful false the transaction could not be found within this account

contains

public boolean contains(Transaction tran)
Determines if the specified transaction is attach to this account

Parameters:
tran - the Transaction to look for
Returns:
true the transaction is attached to this account false the transaction is not attached to this account

contains

public boolean contains(Account account)
Determine if the supplied account is a child of this account

Parameters:
account - to check
Returns:
true if the supplied account is a child of this account

getTransactions

public java.util.List<Transaction> getTransactions()
Returns account shallow copy of the transaction array for this account

Returns:
List of transactions

getTransactionAt

public Transaction getTransactionAt(int index)
                             throws java.lang.IndexOutOfBoundsException
Returns the transaction at the specified index

Parameters:
index - the index of the transaction to return.
Returns:
the transaction at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of bounds

getTransactionCount

public int getTransactionCount()
Returns the number of transactions attached to this account.

Returns:
the number of transactions attached to this account.

getNextTransactionNumber

public java.lang.String getNextTransactionNumber()
Searches through the transactions and determines the next largest transaction number.

Returns:
The next check number; and empty String if numbers are not found

addChild

protected boolean addChild(Account child)
Add account child account given it's reference

Parameters:
child - The child account to add to this account.
Returns:
true if the account was added successfully, false otherwise.

removeChild

boolean removeChild(Account child)
Removes account child account. The reference to the parent(this) is left so that the parent can be discovered.

Parameters:
child - The child account to remove.
Returns:
true if the specific account was account child of this account, false otherwise.

sortChildren

private void sortChildren()

getChildren

public java.util.List<Account> getChildren()
Returns account list of the children

Returns:
List of children

indexOf

public int indexOf(Transaction tran)
Returns the index of the specified Transaction within this Account.

Parameters:
tran - the Transaction to look for
Returns:
The index of the Transaction, -1 if this Account does not contain the Transaction.

getChildCount

public int getChildCount()
Returns the number of children this account has

Returns:
the number of children this account has.

getParent

public Account getParent()
Returns the parent account.

Returns:
the parent of this account, null is this account is not account child

setParent

public boolean setParent(Account account)
Sets the parent of this account

Parameters:
account - The new parent account
Returns:
true is successful

isParent

public boolean isParent()
Determines is this account has any child accounts.

Returns:
true is this account has children, false otherwise.

getBalance

public java.math.BigDecimal getBalance()
The account balance is cached to improve performance and reduce thrashing of the GC system. The accountBalance is rest when transactions are added and removed and lazily recalculated.

Returns:
the balance of this account

getBalance

private java.math.BigDecimal getBalance(CurrencyNode node)
The account balance is cached to improve performance and reduce thrashing of the GC system. The accountBalance is rest when transactions are added and removed and lazily recalculated.

Parameters:
node - CurrencyNode to get balance against
Returns:
the balance of this account

getBalanceAt

public java.math.BigDecimal getBalanceAt(int index)
Get the account balance up to account specified index.

Parameters:
index - the balance of this account at the specified index.
Returns:
the balance of this account at the specified index.

getReconciledBalance

public java.math.BigDecimal getReconciledBalance()
The reconciled balance is cached to improve performance and reduce thrashing of the GC system. The reconciledBalance is reset when transactions are added and removed and lazily recalculated.

Returns:
the reconciled balance of this account

getReconciledBalance

private java.math.BigDecimal getReconciledBalance(CurrencyNode node)

adjustForExchangeRate

private java.math.BigDecimal adjustForExchangeRate(java.math.BigDecimal amount,
                                                   CurrencyNode node)

getFirstUnreconciledTransactionDate

public java.util.Date getFirstUnreconciledTransactionDate()
Returns the date of the first unreconciled transaction

Returns:
Date of first unreconciled transaction

getOpeningBalanceForReconcile

public java.math.BigDecimal getOpeningBalanceForReconcile()
Get the default opening balance for reconciling the account

Returns:
Opening balance for reconciling the account
See Also:
AccountProxy.getOpeningBalanceForReconcile()

getTreeBalance

public java.math.BigDecimal getTreeBalance()
Returns the balance of the account plus any child accounts

Returns:
the balance of this account including the balance of any child accounts.

getTreeBalance

private java.math.BigDecimal getTreeBalance(CurrencyNode node)
Returns the balance of the account plus any child accounts. The balance is adjusted to the current exchange rate of the supplied commodity if needed.

Parameters:
node - The commodity to convert balance to
Returns:
the balance of this account including the balance of any child accounts.

getReconciledTreeBalance

private java.math.BigDecimal getReconciledTreeBalance(CurrencyNode node)
Returns the reconciled balance of the account plus any child accounts. The balance is adjusted to the current exchange rate of the supplied commodity if needed.

Parameters:
node - The commodity to convert balance to
Returns:
the balance of this account including the balance of any child accounts.

getReconciledTreeBalance

public java.math.BigDecimal getReconciledTreeBalance()
Returns the reconciled balance of the account plus any child accounts.

Returns:
the balance of this account including the balance of any child accounts.

getBalance

public java.math.BigDecimal getBalance(java.util.Date start,
                                       java.util.Date end)
Returns the balance of the transactions inclusive of the start and end dates.

Parameters:
start - The inclusive start date
end - The inclusive end date
Returns:
The ending balance

getBalance

public java.math.BigDecimal getBalance(java.util.Date startDate,
                                       java.util.Date endDate,
                                       CurrencyNode node)
Returns the account balance up to and inclusive of the supplied date. The returned balance is converted to the specified commodity.

Parameters:
startDate - start date
endDate - end date
node - The commodity to convert balance to
Returns:
the account balance

getTreeBalance

public java.math.BigDecimal getTreeBalance(java.util.Date start,
                                           java.util.Date end)
Returns the the balance of the account plus any child accounts inclusive of the start and end dates.

Parameters:
start - Start date inclusive
end - End date inclusive
Returns:
recursive account balance

getTreeBalance

public java.math.BigDecimal getTreeBalance(java.util.Date start,
                                           java.util.Date end,
                                           CurrencyNode node)
Returns the the balance of the account plus any child accounts inclusive of the start and end dates.

Parameters:
start - start date
end - end date
node - CurrencyNode to use for balance
Returns:
account balance

getBalance

public java.math.BigDecimal getBalance(java.util.Date date)
Returns the account balance up to and inclusive of the supplied date

Parameters:
date - The inclusive ending date
Returns:
The ending balance

getBalance

public java.math.BigDecimal getBalance(java.util.Date date,
                                       CurrencyNode node)
Returns the account balance up to and inclusive of the supplied date. The returned balance is converted to the specified commodity.

Parameters:
node - The commodity to convert balance to
date - The inclusive ending date
Returns:
The ending balance

getTransactions

public java.util.List<Transaction> getTransactions(java.util.Date startDate,
                                                   java.util.Date endDate)
Returns an array of transactions that occur after account specified cut off date. The returned array is inclusive of the specified dates.

Parameters:
startDate - starting cut off date
endDate - ending cut off date
Returns:
the array of transactions that occurred between the specified dates

setCurrencyNode

final void setCurrencyNode(CurrencyNode node)
Sets the commodity node for this account.

Parameters:
node - The new commodity node for this account.

getCurrencyNode

public final CurrencyNode getCurrencyNode()
Returns the commodity node for this account.

Returns:
the commodity node for this account.

isLocked

public boolean isLocked()

setLocked

public void setLocked(boolean locked)

isPlaceHolder

public boolean isPlaceHolder()

setPlaceHolder

public void setPlaceHolder(boolean placeHolder)

getDescription

public java.lang.String getDescription()

setDescription

public void setDescription(java.lang.String desc)

getName

public java.lang.String getName()

setName

public void setName(java.lang.String newName)

getPathName

public java.lang.String getPathName()

getAccountSeparator

private static java.lang.String getAccountSeparator()

getAccountType

public AccountType getAccountType()

isVisible

public boolean isVisible()
Returns the visibility of the account

Returns:
boolean is this account is visible, false otherwise

setVisible

public void setVisible(boolean visible)
Changes the visibility of the account

Parameters:
visible - the new account visibility

setNotes

public void setNotes(java.lang.String notes)
Sets the notes for this account

Parameters:
notes - the notes for this account

getNotes

public java.lang.String getNotes()
Returns the notes for this account

Returns:
the notes for this account

compareTo

public int compareTo(Account acc)
Compares two Account for ordering. The ID of the account is used as account comparison if the accounts have equal names. It would be bad if compareTo would tag the Accounts as equal when they really are not

Specified by:
compareTo in interface java.lang.Comparable<Account>
Parameters:
acc - the Account to be compared.
Returns:
the value 0 if the argument Account is equal to this Account; account value less than 0 if this Account is before the Account argument; and account value greater than 0 if this Account is after the Account argument.

toString

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

equals

public boolean equals(java.lang.Object other)
Description copied from class: StoredObject
Default equals override

Overrides:
equals in class StoredObject
Parameters:
other - object to compare
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Description copied from class: StoredObject
Override hashCode to use uuid

Overrides:
hashCode in class StoredObject
See Also:
Object.hashCode()

setAccountNumber

public void setAccountNumber(java.lang.String account)

getAccountNumber

public java.lang.String getAccountNumber()
Returns the account number. A non-null value is guaranteed

Returns:
the account number

addSecurity

public boolean addSecurity(SecurityNode node)
Adds account commodity to the list and ensures duplicates are not added. The list is sorted according to numeric code

Parameters:
node - SecurityNode to add
Returns:
true if successful

removeSecurity

boolean removeSecurity(SecurityNode node)
Remove a security

Parameters:
node - SecurityNode to remove
Returns:
true if successful, false if used by a transaction

containsSecurity

public boolean containsSecurity(SecurityNode node)

getMarketValue

public java.math.BigDecimal getMarketValue()
Returns the market value of this account

Returns:
market value of the account

getSecurities

public java.util.Set<SecurityNode> getSecurities()

getUsedSecurities

public java.util.Set<SecurityNode> getUsedSecurities()
Returns a set of used SecurityNodes

Returns:
a set of used SecurityNodes

getCashBalance

public java.math.BigDecimal getCashBalance()
Returns the cash balance of this account

Returns:
Cash balance of the account

getDepth

public int getDepth()

instanceOf

public final boolean instanceOf(AccountType type)
Shortcut method to check account type

Parameters:
type - AccountType to compare against
Returns:
true if supplied AccountType match

memberOf

public final boolean memberOf(AccountGroup group)
Shortcut method to check account group membership

Parameters:
group - AccountGroup to compare against
Returns:
true if this account belongs to the supplied group

getBankId

public java.lang.String getBankId()

setBankId

public void setBankId(java.lang.String bankId)

readResolve

protected java.lang.Object readResolve()

clone

public java.lang.Object clone()
When overridden, this should return account shallow copy only. Does not include transactions or child accounts

Overrides:
clone in class StoredObject
Returns:
clone of this account