Class StreamListProcessor
java.lang.Object
com.singularsys.extensions.stream.StreamListProcessor
- All Implemented Interfaces:
ListProcessor,JepComponent,Serializable
- Direct Known Subclasses:
StreamMatrixListProcessor
A ListProcessor implementation that can process lists, vectors and streams.
It is used by the stream functions to convert their arguments to streams.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionargAsStream(Object arg) Converts the argument to a stream if possible.Converts the argument to a list.argToListOrElement(Object arg) Converts the argument to a list or single value.Get the first element of a stream.Get a stream with the first element removed.voidClear the clones map created bycloneStream(Stream).cloneStream(Stream<Object> stream) Clone a stream.Returns an iterable view of the input arguments.fromCollection(Collection<Object> tree) Convert a general collection into a type used the Jep environment.Convert a list produced byListProcessor.makeList()to the type used by Jep environment.Gets a light-weight instance suitable for using in multiple threads.voidInitialize the component.makeList()Get an empty list which elements can be added.
-
Constructor Details
-
StreamListProcessor
public StreamListProcessor()
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
fromArgs
Description copied from interface:ListProcessorReturns an iterable view of the input arguments.- Specified by:
fromArgsin interfaceListProcessor- Parameters:
arg- typically a list, but can be any type. If the type is not a list, an iterator with a single element is returned.- Returns:
- an Iterable view of the argument
- Throws:
EvaluationException- on error
-
argAsStream
Converts the argument to a stream if possible. If the argument is already a stream it is returned as is, if it is a list or aVectorIit is converted to a stream. Otherwise an stream consisting of a single element is created.- Throws:
EvaluationException
-
argToList
Converts the argument to a list. If the argument is aList,Streamor aVectorIit is converted to a list individual elements of these sequence are recursively converted to lists as well. If the argument is not a list, stream orVectorIa list consisting of a single element is created.- Parameters:
arg- the argument to convert- Returns:
- a list
- Throws:
EvaluationException
-
argToListOrElement
Converts the argument to a list or single value. If the argument is aList,Streamor aVectorIit is converted to a list individual elements of these sequence are recursively converted to lists as well. If the argument is not a list, stream orVectorIit is returned as is.- Parameters:
arg- the argument to convert- Returns:
- a list or single value
- Throws:
EvaluationException
-
makeList
Description copied from interface:ListProcessorGet an empty list which elements can be added.- Specified by:
makeListin interfaceListProcessor- Returns:
- an empty list
-
fromList
Description copied from interface:ListProcessorConvert a list produced byListProcessor.makeList()to the type used by Jep environment. Some implementations just return the input.- Specified by:
fromListin interfaceListProcessor- Parameters:
list- a list- Returns:
- a type suitable for use by Jep.
- Throws:
EvaluationException- on error
-
fromCollection
Description copied from interface:ListProcessorConvert a general collection into a type used the Jep environment.- Specified by:
fromCollectionin interfaceListProcessor- Parameters:
tree- input collection- Returns:
- a type suitable for use by Jep
- Throws:
EvaluationException- on error
-
cloneStream
Clone a stream. A reference to the original stream is kept in a Map this is used by subsequent callscloneStreamto so the all clones receive the same data. During the evaluation a a list of the elements from the original stream that have been accessed is kept, which may grow indefinitely. TheclearClones()method should be called after the clones are no longer needed to prevent memory leaks.- Parameters:
stream- the stream to clone- Returns:
- a clone of the stream
-
clearClones
public void clearClones()Clear the clones map created bycloneStream(Stream). This should be called after the clones are no longer needed to prevent memory leaks. -
car
Get the first element of a stream. This method can be called multiple times with the same stream, it will always return the same first element.- Parameters:
stream- input stream- Returns:
-
cdr
Get a stream with the first element removed. This method should not can be called multiple times.- Parameters:
stream- input stream- Returns:
- a stream with the first elements removed
-