org.shapelogic.streams
Class BaseCommonNumberedStream<E>

java.lang.Object
  extended by org.shapelogic.streams.BaseCommonStream<E>
      extended by org.shapelogic.streams.BaseCommonNumberedStream<E>
All Implemented Interfaces:
java.util.Iterator<E>, CalcValue<E>, ContextGettable, LazyCalc<E>, RecursiveContext, NumberedStream<E>, Stream<E>, StreamProperties
Direct Known Subclasses:
BaseNumberedStream1, NaturalNumberStream, NumericTruthTableStream

public abstract class BaseCommonNumberedStream<E>
extends BaseCommonStream<E>

Implementation of ListStream.
Close to
1: a lazy stream.
2: a UNIX pipe.

This is close to org.apache.commons.collections.list.LazyList, but that takes a factory to calculate next element, and that works badly here. How should a step work?
Normally call the hasNext, in order for this to work it would have to do the calculation.

So _current should be the last element that has been returned.

So when you call hasNext it will add that element to the list. When you call next it will bump the counter up one element if goes too high then do the calculation. At the end it will get to a point where the calculation fails. At that point last will be set to the current element. I will ignore synchronization to begin with. I think that there could be a _nextElement that is calculated when hasNext() is called. When next is called check if this exist and return it. After that set it to null.

Author:
Sami Badawi

Field Summary
 
Fields inherited from class org.shapelogic.streams.BaseCommonStream
_context, _current, _dirty, _last, _maxLast, _name, _nullLegalValue, _parentContext, _query, _value
 
Constructor Summary
BaseCommonNumberedStream()
           
 
Method Summary
protected  boolean calcAddNext()
          Try to calculate one more, independent of the _current.
 E get(int inputIndex)
          Get next element without advancing _current.
 boolean hasNext()
           
 boolean hasNextBase()
           
abstract  E invokeIndex(int index)
          Calculate the value at an index.
 boolean isCached()
          If there is a list that contains all the results.
 boolean isRandomAccess()
          If you can calculate 1 element independent of other elements.
 E next()
          Get next element and advance _current.
protected  void setLast(int index)
           
 
Methods inherited from class org.shapelogic.streams.BaseCommonStream
getContext, getInContext, getIndex, getLast, getMaxLast, getName, getParentContext, getValue, isDeterministic, isDirty, isNullLegalValue, remove, setLastFromInput, setMaxLast, setNullLegalValue, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseCommonNumberedStream

public BaseCommonNumberedStream()
Method Detail

invokeIndex

public abstract E invokeIndex(int index)
Calculate the value at an index.
So it gets the needed input value and call the appropriate invoke function.
Can this be used for a filter call?
The index does not make sense for a filter since you do not know where the input is coming from. So maybe just ignore it.
This is a little messy but less messy that what is there now.

Specified by:
invokeIndex in class BaseCommonStream<E>

hasNext

public boolean hasNext()

calcAddNext

protected boolean calcAddNext()
Try to calculate one more, independent of the _current.

Specified by:
calcAddNext in class BaseCommonStream<E>

hasNextBase

public boolean hasNextBase()

next

public E next()
Get next element and advance _current.


setLast

protected void setLast(int index)

get

public E get(int inputIndex)
Get next element without advancing _current.

Returns:

isRandomAccess

public boolean isRandomAccess()
Description copied from interface: StreamProperties
If you can calculate 1 element independent of other elements.


isCached

public boolean isCached()
If there is a list that contains all the results. I would think that this should always happen for a ListStream, but it could happen for other streams as well.



Copyright © 2009. All Rights Reserved.