org.shapelogic.streams
Class BaseListStream2<In0,In1,E>

java.lang.Object
  extended by org.shapelogic.streams.BaseCommonStream<E>
      extended by org.shapelogic.streams.BaseListCommonStream<E>
          extended by org.shapelogic.streams.BaseListStream2<In0,In1,E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Iterator<E>, CalcValue<E>, ContextGettable, LazyCalc<E>, RecursiveContext, IndexedInputStream2<In0,In1,E>, ListStream<E>, NumberedStream<E>, Stream<E>, StreamProperties

public abstract class BaseListStream2<In0,In1,E>
extends BaseListCommonStream<E>
implements IndexedInputStream2<In0,In1,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.

Author:
Sami Badawi

Field Summary
protected  CartesianIndex _cartesianIndex
           
protected  NumberedStream<In0> _inputStream0
           
protected  NumberedStream<In1> _inputStream1
           
 
Fields inherited from class org.shapelogic.streams.BaseListCommonStream
_list
 
Fields inherited from class org.shapelogic.streams.BaseCommonStream
_context, _current, _dirty, _last, _maxLast, _name, _nullLegalValue, _parentContext, _query, _value
 
Constructor Summary
BaseListStream2(NumberedStream<In0> inputStream0, NumberedStream<In1> inputStream1)
           
BaseListStream2(NumberedStream<In0> inputStream0, NumberedStream<In1> inputStream1, int maxLast)
           
 
Method Summary
 boolean calcAddNext()
          Try to calculate one more, independent of the _current.
 In0 getInput0(int index)
          Get numbered element from InputStream
 In1 getInput1(int index)
           
 NumberedStream<In0> getInputStream0()
          Stream that this stream is connected to.
 NumberedStream<In1> getInputStream1()
           
abstract  E invoke(In0 input0, In1 input1, int index)
          Calculate the next value
 E invokeIndex(int index)
          Calculate the value at an index.
 
Methods inherited from class org.shapelogic.streams.BaseListCommonStream
get, getCurrentSize, getList, hasNext, hasNextBase, isCached, isRandomAccess, iterator, next, setLastFromInput, setList
 
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.streams.NumberedStream
getIndex, getLast, getMaxLast, setMaxLast
 
Methods inherited from interface org.shapelogic.calculation.LazyCalc
isDirty, setup
 
Methods inherited from interface org.shapelogic.calculation.CalcValue
getValue
 
Methods inherited from interface java.util.Iterator
remove
 

Field Detail

_inputStream0

protected final NumberedStream<In0> _inputStream0

_inputStream1

protected final NumberedStream<In1> _inputStream1

_cartesianIndex

protected final CartesianIndex _cartesianIndex
Constructor Detail

BaseListStream2

public BaseListStream2(NumberedStream<In0> inputStream0,
                       NumberedStream<In1> inputStream1,
                       int maxLast)

BaseListStream2

public BaseListStream2(NumberedStream<In0> inputStream0,
                       NumberedStream<In1> inputStream1)
Method Detail

invoke

public abstract E invoke(In0 input0,
                         In1 input1,
                         int index)
Calculate the next value

Specified by:
invoke in interface IndexedInputStream2<In0,In1,E>
index - of element in list
Returns:

invokeIndex

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

calcAddNext

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

Overrides:
calcAddNext in class BaseListCommonStream<E>

getInput0

public In0 getInput0(int index)
Description copied from interface: IndexedInputStream2
Get numbered element from InputStream

Specified by:
getInput0 in interface IndexedInputStream2<In0,In1,E>

getInput1

public In1 getInput1(int index)
Specified by:
getInput1 in interface IndexedInputStream2<In0,In1,E>

getInputStream0

public NumberedStream<In0> getInputStream0()
Description copied from interface: IndexedInputStream2
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:
getInputStream0 in interface IndexedInputStream2<In0,In1,E>

getInputStream1

public NumberedStream<In1> getInputStream1()
Specified by:
getInputStream1 in interface IndexedInputStream2<In0,In1,E>


Copyright © 2009. All Rights Reserved.