jgnash.engine
Class Transaction

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

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

Base class for transactions

Version:
$Id$
Author:
Craig Cavanaugh
See Also:
Serialized Form

Field Summary
private  java.util.Date date
           
private  java.util.Date dateEntered
          Date transaction was created
private static java.lang.String EMPTY
           
private  java.lang.String fitid
          Financial Institute Transaction ID.
private  java.util.concurrent.locks.ReadWriteLock lock
          ReadWrite lock
private  java.lang.String memo
          Transaction memo
private  java.lang.String number
          Transaction number
private  java.lang.String payee
          Transaction payee
private static long serialVersionUID
           
(package private)  java.util.List<TransactionEntry> transactionEntries
          Transaction entries
 
Constructor Summary
Transaction()
          Public constructor
 
Method Summary
 void addTransactionEntries(java.util.Collection<TransactionEntry> entries)
           
 void addTransactionEntry(TransactionEntry entry)
          Returns the balance of the transaction amount with respect to the supplied account.
 java.lang.Object clone()
           
 int compareTo(Transaction tran)
          Compares two Transactions for ordering.
 boolean equalsIgnoreDate(Transaction tran)
          Compares this transaction against another for equality.
 java.util.Set<Account> getAccounts()
          Returns a set of accounts this transaction effects
 java.math.BigDecimal getAmount(Account account)
          Calculates the amount of the transaction relative to the supplied account
 Account getCommonAccount()
          Search for a common account for all entries
 java.util.Date getDate()
           
 java.util.Date getDateEntered()
           
 java.lang.String getFitid()
           
(package private)  java.util.concurrent.locks.ReadWriteLock getLock()
           
 java.lang.String getMemo()
           
 java.lang.String getNumber()
          Return the number for this transaction
 java.lang.String getPayee()
          Return the payee for this transaction
 ReconciledState getReconciled(Account account)
           
 java.util.List<TransactionEntry> getTransactionEntries()
           
(package private)  java.util.List<TransactionEntry> getTransactionEntriesByTag(TransactionTag tag)
          Return a list of transaction entries with the given tag
 TransactionType getTransactionType()
           
protected  java.lang.Object readResolve()
           
 void removeTransactionEntry(TransactionEntry entry)
           
 void setDate(java.util.Date date)
           
 void setDateEntered(java.util.Date dateEntered)
           
 void setFitid(java.lang.String fitid)
           
 void setMemo(java.lang.String memo)
           
 void setNumber(java.lang.String number)
          Sets the number for this transaction
 void setPayee(java.lang.String payee)
          Sets the payee for this transaction
 void setReconciled(Account account, ReconciledState state)
           
 void setReconciled(ReconciledState state)
           
 int size()
          Returns the number of TransctionEntry(s) this transaction contains.
 java.lang.String toString()
           
 
Methods inherited from class jgnash.engine.StoredObject
equals, getUuid, hashCode, 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

EMPTY

private static final transient java.lang.String EMPTY
See Also:
Constant Field Values

date

private java.util.Date date

dateEntered

private java.util.Date dateEntered
Date transaction was created


number

private java.lang.String number
Transaction number


payee

private java.lang.String payee
Transaction payee


fitid

private java.lang.String fitid
Financial Institute Transaction ID. Typically used for OFX import FITID


memo

private java.lang.String memo
Transaction memo


transactionEntries

java.util.List<TransactionEntry> transactionEntries
Transaction entries


lock

private transient java.util.concurrent.locks.ReadWriteLock lock
ReadWrite lock

Constructor Detail

Transaction

public Transaction()
Public constructor

Method Detail

getLock

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

getAccounts

public java.util.Set<Account> getAccounts()
Returns a set of accounts this transaction effects

Returns:
set of accounts
See Also:
Account

getCommonAccount

public Account getCommonAccount()
Search for a common account for all entries

Returns:
the common Account
See Also:
Account

addTransactionEntry

public void addTransactionEntry(TransactionEntry entry)
Returns the balance of the transaction amount with respect to the supplied account. Value will be positive or negative depending if the transaction debits or credits the account.

Parameters:
entry - new TransactionEntry to add
See Also:
TransactionEntry

removeTransactionEntry

public void removeTransactionEntry(TransactionEntry entry)

size

public int size()
Returns the number of TransctionEntry(s) this transaction contains. A read lock is obtained before determining the size.

Returns:
the number of TransactionEntry(s)
See Also:
TransactionEntry

setDate

public void setDate(java.util.Date date)

getDate

public java.util.Date getDate()

setPayee

public void setPayee(java.lang.String payee)
Sets the payee for this transaction

Parameters:
payee - the transaction payee

getPayee

public java.lang.String getPayee()
Return the payee for this transaction

Returns:
the transaction payee. Guaranteed to not return null

setNumber

public void setNumber(java.lang.String number)
Sets the number for this transaction

Parameters:
number - the transaction number

getNumber

public java.lang.String getNumber()
Return the number for this transaction

Returns:
the transaction number. Guaranteed to not return null

getAmount

public java.math.BigDecimal getAmount(Account account)
Calculates the amount of the transaction relative to the supplied account

Parameters:
account - reference account
Returns:
Amount of this transaction relative to the supplied account

compareTo

public int compareTo(Transaction tran)
Compares two Transactions for ordering. Equality is checked for at the reference level. If a comparison cannot be determined, the hashCode is used

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

equalsIgnoreDate

public boolean equalsIgnoreDate(Transaction tran)
Compares this transaction against another for equality. The date the transaction is created is ignored. The voucher date is still tested.

Parameters:
tran - Transaction to compare against
Returns:
true if Transactions are equal

getTransactionEntries

public java.util.List<TransactionEntry> getTransactionEntries()

getTransactionEntriesByTag

java.util.List<TransactionEntry> getTransactionEntriesByTag(TransactionTag tag)
Return a list of transaction entries with the given tag

Parameters:
tag - TransactionTag to filter for
Returns:
List of entries with the given tag. An empty list will be returned if none are found

addTransactionEntries

public void addTransactionEntries(java.util.Collection<TransactionEntry> entries)

getDateEntered

public java.util.Date getDateEntered()

setDateEntered

public void setDateEntered(java.util.Date dateEntered)

getTransactionType

public TransactionType getTransactionType()

getMemo

public java.lang.String getMemo()

setMemo

public void setMemo(java.lang.String memo)

getFitid

public java.lang.String getFitid()

setFitid

public void setFitid(java.lang.String fitid)

setReconciled

public void setReconciled(Account account,
                          ReconciledState state)

setReconciled

public void setReconciled(ReconciledState state)

getReconciled

public ReconciledState getReconciled(Account account)

clone

public java.lang.Object clone()
Overrides:
clone in class StoredObject

readResolve

protected java.lang.Object readResolve()

toString

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