org.shapelogic.calculation
Class BaseAccumulator<In,Out>

java.lang.Object
  extended by org.shapelogic.calculation.BaseAccumulator<In,Out>
Type Parameters:
In -
Out -
All Implemented Interfaces:
java.util.Iterator<Out>, Accumulator<In,Out>, CalcValue<Out>, LazyCalc<Out>
Direct Known Subclasses:
MaxAccumulator, SumAccumulator

public abstract class BaseAccumulator<In,Out>
extends java.lang.Object
implements Accumulator<In,Out>

BaseAccumulator accumulator. For use with Streams and Iterators.

Author:
Sami Badawi

Field Summary
protected  boolean _dirty
           
protected  java.util.Iterator<In> _input
           
protected  In _inputElement
           
protected  In _previousInputElement
           
protected  Out _previousValue
           
protected  Out _value
           
 
Constructor Summary
BaseAccumulator(java.util.Iterator<In> input)
           
 
Method Summary
abstract  Out accumulate(In element, Out out)
          return element + out;
 java.util.Iterator<In> getInput()
           
 Out getPreviousValue()
          Not sure if this should be a lazy calculation too.
 Out getValue()
          Starts a lazy calculation.
 boolean hasNext()
           
 boolean isDirty()
          When dirty is false that means that the calculated value can be used
 Out next()
           
 void remove()
           
 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

_input

protected java.util.Iterator<In> _input

_dirty

protected boolean _dirty

_value

protected Out _value

_previousValue

protected Out _previousValue

_inputElement

protected In _inputElement

_previousInputElement

protected In _previousInputElement
Constructor Detail

BaseAccumulator

public BaseAccumulator(java.util.Iterator<In> input)
Method Detail

accumulate

public abstract Out accumulate(In element,
                               Out out)
Description copied from interface: Accumulator
return element + out;

Specified by:
accumulate in interface Accumulator<In,Out>

getInput

public java.util.Iterator<In> getInput()
Specified by:
getInput in interface Accumulator<In,Out>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<Out>

next

public Out next()
Specified by:
next in interface java.util.Iterator<Out>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<Out>

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<Out>

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<Out>

getValue

public Out 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<Out>

getPreviousValue

public Out getPreviousValue()
Not sure if this should be a lazy calculation too. This might be moved into the interface.

Specified by:
getPreviousValue in interface Accumulator<In,Out>


Copyright © 2009. All Rights Reserved.