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

java.lang.Object
  extended by org.shapelogic.streams.BaseCommonStream<E>
      extended by org.shapelogic.streams.BaseListCommonStream<E>
          extended by org.shapelogic.streams.BaseListStreamList<In,E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Iterator<E>, CalcList<In,E>, CalcValue<E>, ContextGettable, LazyCalc<E>, RecursiveContext, InputStreamList<In,E>, ListStream<E>, NumberedStream<E>, Stream<E>, StreamProperties
Direct Known Subclasses:
AddListStream, AndListStream, ArrayOutputListStream, XOrListStream

public abstract class BaseListStreamList<In,E>
extends BaseListCommonStream<E>
implements InputStreamList<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.

Author:
Sami Badawi

Field Summary
protected  java.util.List<NumberedStream<In>> _inputStream
          Does not always exist.
 
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
BaseListStreamList()
           
BaseListStreamList(java.util.List<NumberedStream<In>> inputStream)
           
BaseListStreamList(java.util.List<NumberedStream<In>> inputStream, int maxLast)
           
 
Method Summary
 int getDimension()
          How many input streams you have.
 java.util.List<In> getInput(int index)
           
 java.util.List<NumberedStream<In>> getInputStream()
          Stream that this stream is connected to.
 java.util.List<E> getList()
          Get underlying list.
 boolean hasNext()
           
 E invokeIndex(int index)
          Calculate the value at an index.
protected  void setLastFromInput()
           
 void setList(java.util.List<E> list)
          Get underlying list.
 
Methods inherited from class org.shapelogic.streams.BaseListCommonStream
calcAddNext, get, getCurrentSize, hasNextBase, isCached, isRandomAccess, iterator, next
 
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.CalcList
invoke
 
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

_inputStream

protected java.util.List<NumberedStream<In>> _inputStream
Does not always exist.

Constructor Detail

BaseListStreamList

public BaseListStreamList(java.util.List<NumberedStream<In>> inputStream,
                          int maxLast)

BaseListStreamList

public BaseListStreamList(java.util.List<NumberedStream<In>> inputStream)

BaseListStreamList

public BaseListStreamList()
Method Detail

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>

getList

public java.util.List<E> getList()
Description copied from interface: ListStream
Get underlying list.

Specified by:
getList in interface ListStream<E>
Overrides:
getList in class BaseListCommonStream<E>

setList

public void setList(java.util.List<E> list)
Description copied from interface: ListStream
Get underlying list.

Specified by:
setList in interface ListStream<E>
Overrides:
setList in class BaseListCommonStream<E>

getInputStream

public java.util.List<NumberedStream<In>> getInputStream()
Description copied from interface: InputStreamList
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 InputStreamList<In,E>

getInput

public java.util.List<In> getInput(int index)
Specified by:
getInput in interface InputStreamList<In,E>

getDimension

public int getDimension()
Description copied from interface: InputStreamList
How many input streams you have.

Specified by:
getDimension in interface InputStreamList<In,E>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<E>
Overrides:
hasNext in class BaseListCommonStream<E>

setLastFromInput

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


Copyright © 2009. All Rights Reserved.