org.shapelogic.calculation
Class BaseCalcInContext<K,V>

java.lang.Object
  extended by org.shapelogic.calculation.BaseCalcInContext<K,V>
Type Parameters:
K - Input type for calculation
V - Output type for calculation
All Implemented Interfaces:
CalcInContext<K,V>, CalcValue<V>, LazyCalc<V>

public abstract class BaseCalcInContext<K,V>
extends java.lang.Object
implements CalcInContext<K,V>

BaseCalcInContext normal base class for CalcInContext.

Author:
Sami Badawi

Field Summary
protected  boolean _dirty
           
protected  K _key
           
protected  QueryCalc<K,V> _query
           
protected  int _topLevelUsed
           
protected  V _value
           
 
Constructor Summary
BaseCalcInContext(K key)
           
 
Method Summary
 V calc(RecursiveContext<K> recursiveContext)
          This a convenience method that set the calculated value in the right context.
 V getValue()
          Starts a lazy calculation.
abstract  V invoke(RecursiveContext<K> contextArray)
          This is the method that the user should override.
 boolean isDirty()
          When dirty is false that means that the calculated value can be used
 void setup()
          Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dirty

protected boolean _dirty

_key

protected K _key

_value

protected V _value

_query

protected QueryCalc<K,V> _query

_topLevelUsed

protected int _topLevelUsed
Constructor Detail

BaseCalcInContext

public BaseCalcInContext(K key)
Method Detail

invoke

public abstract V invoke(RecursiveContext<K> contextArray)
Description copied from interface: CalcInContext
This is the method that the user should override.

Specified by:
invoke in interface CalcInContext<K,V>
Returns:

calc

public V calc(RecursiveContext<K> recursiveContext)
Description copied from interface: CalcInContext
This a convenience method that set the calculated value in the right context.

Specified by:
calc in interface CalcInContext<K,V>
Returns:

isDirty

public boolean isDirty()
Description copied from interface: LazyCalc
When dirty is false that means that the calculated value can be used

Specified by:
isDirty in interface LazyCalc<V>

setup

public void setup()
Description copied from interface: LazyCalc
Currently not super well define used for 2 purposes: Reset: called from the outside if you want to reuse it init: Called from the inside when calculation start to have everything setup maybe the semantic could work for both? TODO: This should be separated better.

Specified by:
setup in interface LazyCalc<V>

getValue

public V getValue()
Description copied from interface: CalcValue
Starts a lazy calculation. If dirty do calc() else return cached value. This should maybe be moved up in the hierarchy

Specified by:
getValue in interface CalcValue<V>


Copyright © 2009. All Rights Reserved.