jfreerails.world.top
Class TransactionAggregator

java.lang.Object
  extended by jfreerails.world.top.TransactionAggregator
Direct Known Subclasses:
FinancialDataGatherer, ItemsTransactionAggregator, NetWorthCalculator

public abstract class TransactionAggregator
extends java.lang.Object

Adds up the value of transactions. Implements GoF Template Method pattern. Subclasses that aggregate a monetary sum should only override the method condition(int); subclasses that aggregate a non-monetary sum should override all 4 protected methods.

Author:
Luke

Field Summary
private  GameTime[] DEFAULT_INTERVAL
           
protected  Money[] monetaryTotals
           
protected  FreerailsPrincipal principal
           
protected  int runningTotal
           
private  GameTime[] timeValues
           
protected  ReadOnlyWorld w
           
 
Constructor Summary
TransactionAggregator(ReadOnlyWorld w, FreerailsPrincipal principal)
           
 
Method Summary
 Money calculateValue()
          Returns the sum of the appropriate transactions.
 Money[] calculateValues()
          Returns the sum of the appropriate transactions up to (inclusive) each of the specified times.
protected abstract  boolean condition(int transactionID)
          Returns true if we should count the specified transactions.
 GameTime[] getTimes()
           
protected  void incrementRunningTotal(int transactionID)
           
 void setTimes(GameTime[] times)
           
protected  void setTotalsArrayLength(int length)
          Creates a new array with the specified length to store monetary totals and sets the running total to zero.
protected  void storeRunningTotal(int timeIndex)
          Stores the current running total in the totals array at the specified position.
private  void storeTotalIfAppropriate(int timeIndex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

w

protected final ReadOnlyWorld w

principal

protected final FreerailsPrincipal principal

monetaryTotals

protected Money[] monetaryTotals

runningTotal

protected int runningTotal

DEFAULT_INTERVAL

private final GameTime[] DEFAULT_INTERVAL

timeValues

private GameTime[] timeValues
Constructor Detail

TransactionAggregator

public TransactionAggregator(ReadOnlyWorld w,
                             FreerailsPrincipal principal)
Method Detail

getTimes

public GameTime[] getTimes()

setTimes

public void setTimes(GameTime[] times)

calculateValue

public final Money calculateValue()
Returns the sum of the appropriate transactions. Do not override.


calculateValues

public final Money[] calculateValues()
Returns the sum of the appropriate transactions up to (inclusive) each of the specified times. Do not override.


storeTotalIfAppropriate

private void storeTotalIfAppropriate(int timeIndex)

setTotalsArrayLength

protected void setTotalsArrayLength(int length)
Creates a new array with the specified length to store monetary totals and sets the running total to zero. Subclasses that aggregate other quantities should override this method and create the appropriate arrays.


incrementRunningTotal

protected void incrementRunningTotal(int transactionID)

storeRunningTotal

protected void storeRunningTotal(int timeIndex)
Stores the current running total in the totals array at the specified position.


condition

protected abstract boolean condition(int transactionID)
Returns true if we should count the specified transactions.