org.shapelogic.streams
Class BaseNumberedStream1<In,E>

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

public abstract class BaseNumberedStream1<In,E>
extends BaseCommonNumberedStream<E>
implements InputStream1<In,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 this should mainly just take a index get the input number for that and appy the calc.

Based on BaseListStream1

Author:
Sami Badawi

Field Summary
protected  NumberedStream<In> _inputStream
          Does not always exist.
 
Fields inherited from class org.shapelogic.streams.BaseCommonStream
_context, _current, _dirty, _last, _maxLast, _name, _nullLegalValue, _parentContext, _query, _value
 
Constructor Summary
BaseNumberedStream1()
           
BaseNumberedStream1(NumberedStream<In> inputStream)
           
BaseNumberedStream1(NumberedStream<In> inputStream, int maxLast)
           
 
Method Summary
 In getInput(int index)
           
 NumberedStream<In> getInputStream()
          Stream that this stream is connected to.
 E invokeIndex(int index)
          Calculate the value at an index.
protected  void setLastFromInput()
           
 
Methods inherited from class org.shapelogic.streams.BaseCommonNumberedStream
calcAddNext, get, hasNext, hasNextBase, isCached, isRandomAccess, next, setLast
 
Methods inherited from class org.shapelogic.streams.BaseCommonStream
getContext, getInContext, getIndex, getLast, getMaxLast, getName, getParentContext, getValue, isDeterministic, isDirty, isNullLegalValue, remove, setMaxLast, setNullLegalValue, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.shapelogic.calculation.Calc1
invoke
 

Field Detail

_inputStream

protected NumberedStream<In> _inputStream
Does not always exist.

Constructor Detail

BaseNumberedStream1

public BaseNumberedStream1(NumberedStream<In> inputStream,
                           int maxLast)

BaseNumberedStream1

public BaseNumberedStream1(NumberedStream<In> inputStream)

BaseNumberedStream1

public BaseNumberedStream1()
Method Detail

invokeIndex

public E invokeIndex(int index)
Description copied from class: BaseCommonNumberedStream
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 BaseCommonNumberedStream<E>

getInputStream

public NumberedStream<In> getInputStream()
Description copied from interface: InputStream1
Stream that this stream is connected to. What if the Range is of different type? I think that maybe I can relax this later.

Specified by:
getInputStream in interface InputStream1<In,E>

getInput

public In getInput(int index)
Specified by:
getInput in interface InputStream1<In,E>

setLastFromInput

protected void setLastFromInput()
Overrides:
setLastFromInput in class BaseCommonStream<E>


Copyright © 2009. All Rights Reserved.