Package com.storedobject.core
Class LedgerWindow
java.lang.Object
com.storedobject.core.LedgerWindow
Representation of a "window" of entries (instances of
LedgerEntry
) of the "Transaction Ledger".
A List
must be provided to
keep the entries and this class will maintain that list by adding/removing entries to/from it when the "window" is
moved forward/backward. When the instance is initialized with an Account
, it will automatically
load entries corresponding to the latest transactions.
Note: Please note that this class doesn't support generic ledger entries of external systems unless you override
methods: getLedger(Date, Date)
, getMaxDate(Date)
, getMinDate(Date)
. However, there is
a provision to append additional entries (could be un-posted ones). Override the getUnposted()
method for
returning the unposted entries. All the entries in the unposted entry list must have the same date, and it will be
automatically fixed as the upper date boundary.
- Author:
- Syam
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.LedgerWindow
(int windowSize) Constructor.LedgerWindow
(int windowSize, List<LedgerEntry> entries) Constructor.LedgerWindow
(List<LedgerEntry> entries) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Can we move backward?boolean
Can we move forward?Get the account for which entries are loaded.Get the list containing the ledger entries.Get the ledger entries for the given period for the account.getMaxDate
(Date upperBoundary) Get the date of the most recent transaction within the upper boundary.getMinDate
(Date lowerBoundary) Get the date of the first transaction available for the current account.protected List
<LedgerEntry> Override this method to return any unposted entries to be appended.boolean
isError()
Check if any DB error occurred while loading entries or not.boolean
Move the window backward.boolean
Move the window forward.void
Move window to the beginning.void
Move window to the end.void
setAccount
(Account account) Set the account for which ledger entries need to be loaded.void
setAccount
(Account account, Date date) Set the account for which ledger entries need to be loaded.void
Set the starting date from which ledger entries to be loaded.void
setErrorLogger
(ErrorLogger errorLogger) Set the error logger to capture the errors while generating the ledger entries.
-
Constructor Details
-
LedgerWindow
public LedgerWindow()Constructor. Default window size is 10. -
LedgerWindow
Constructor. Default window size is 10.- Parameters:
entries
- List where ledger entries need to be maintained. Ifnull
is passed, a new list will be created.
-
LedgerWindow
public LedgerWindow(int windowSize) Constructor.- Parameters:
windowSize
- Window size of the ledger entries.
-
LedgerWindow
Constructor.- Parameters:
windowSize
- Window size of the ledger entries.entries
- List where ledger entries need to be maintained. Ifnull
is passed, a new list will be created.
-
-
Method Details
-
getEntries
Get the list containing the ledger entries. The list returned by this method should not be altered externally. If altered, further method calls may not work properly.- Returns:
- List.
-
getAccount
-
setAccount
Set the account for which ledger entries need to be loaded. Ledger entries for the most recent transactions will be loaded.- Parameters:
account
- Account.
-
setAccount
-
setDate
Set the starting date from which ledger entries to be loaded. If enough entries are not found to fill up the window-size, it will try to load more entries from the following dates until window-size can be full-filled. If there are no entries in the following dates to full-fill the window-size, it will try load entries from the preceding dates to full-fill the window-size. Ifnull
is passed, the entries corresponding to the latest transactions are loaded.- Parameters:
date
- Starting date.
-
canMoveBackward
public boolean canMoveBackward()Can we move backward?- Returns:
- True/false.
-
canMoveForward
public boolean canMoveForward()Can we move forward?- Returns:
- True/false.
-
moveToBeginning
public void moveToBeginning()Move window to the beginning. -
moveToEnd
public void moveToEnd()Move window to the end. -
moveBackward
public boolean moveBackward()Move the window backward.- Returns:
- True if moved and false if no further ledger entries found.
-
moveForward
public boolean moveForward()Move the window forward.- Returns:
- True if moved and false if no further ledger entries found.
-
isError
public boolean isError()Check if any DB error occurred while loading entries or not.- Returns:
- True or false.
-
getUnposted
Override this method to return any unposted entries to be appended.- Returns:
- Unposted entries.
-
setErrorLogger
Set the error logger to capture the errors while generating the ledger entries.- Parameters:
errorLogger
- Error logger.
-
getMinDate
Get the date of the first transaction available for the current account. Override this method if you overridegetLedger(Date, Date)
to bring entries from an external system.- Parameters:
lowerBoundary
- Lower boundary. If not null, the date returned should be greater than or equal to this. Null can be returned if no transactions found.- Returns:
- Date of the first transaction available.
-
getMaxDate
Get the date of the most recent transaction within the upper boundary. Override this method if you overridegetLedger(Date, Date)
to bring entries from an external system.- Parameters:
upperBoundary
- Upper boundary. If not null, the date returned should be less than this. Null can be returned if no transactions found.- Returns:
- Most recent transaction date.
-
getLedger
Get the ledger entries for the given period for the account. This method is invoked to obtain ledger entries from the system. You may override this method to return entries from external systems.- Parameters:
from
- From date.to
- To date.- Returns:
- Ledger.
-