Class CollectionReader<T>
java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.core.Endpoint
com.northconcepts.datapipeline.core.DataEndpoint
com.northconcepts.datapipeline.core.DataReader
com.northconcepts.datapipeline.memory.CollectionReader<T>
- Type Parameters:
T- the type of elements in the collection
A DataReader that reads records from a Java
Collection, Iterator, or Stream.
Each element in the collection is converted to a Record using a provided converter function.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.DataReader
fieldLineage, recordLineageFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionCollectionReader(Collection<T> collection, Function<T, Record> recordConverterFunction) Creates a CollectionReader from a Collection.Creates a CollectionReader from an Iterator.Creates a CollectionReader from a Stream. -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds exception properties for debugging purposes.protected RecordelementToRecord(T nextElement) Converts an element to a Record using the converter function.protected Collection<T> Gets the underlying collection, if available.Gets the iterator used to read elements.Gets the function used to convert elements to Records.protected RecordreadImpl()Overridden by subclasses to read the next record from thisDataReader.Methods inherited from class com.northconcepts.datapipeline.core.DataReader
addLineage, available, getBufferSize, getNestedEndpoint, getNestedReader, getReader, getRootEndpoint, getRootReader, isExhausted, isLineageSupported, isSaveLineage, peek, pop, push, read, setSaveLineage, skipMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
close, decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, open, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime, setDescription
-
Constructor Details
-
CollectionReader
Creates a CollectionReader from a Collection.- Parameters:
collection- the collection to read from, or null for an empty collectionrecordConverterFunction- function to convert each element to a Record
-
CollectionReader
Creates a CollectionReader from an Iterator.- Parameters:
iterator- the iterator to read from, or null for an empty iteratorrecordConverterFunction- function to convert each element to a Record
-
CollectionReader
Creates a CollectionReader from a Stream.- Parameters:
stream- the stream to read from, or null for an empty streamrecordConverterFunction- function to convert each element to a Record
-
-
Method Details
-
readImpl
Description copied from class:DataReaderOverridden by subclasses to read the next record from thisDataReader. The default implementation ofDataReader.read()now insures that this method will not be called again after it returns anull.If no record is available,
nullwill be returned.Contract for subclasses (see also
docs/authoring/DataReader.md):- Return
nullexactly once to signal end-of-stream. - Do not call this method directly —
DataReader.read()is the template method that wraps exceptions, increments the record count, and tracks lineage. - Do not call
DataEndpoint.incrementRecordCount()here;DataReader.read()already does. - Throw raw exceptions;
DataReader.read()wraps them viaexception(throwable).
- Specified by:
readImplin classDataReader- Throws:
Throwable
- Return
-
elementToRecord
Converts an element to a Record using the converter function. Subclasses can override this method to customize conversion logic.- Parameters:
nextElement- the element to convert- Returns:
- the converted Record
-
getCollection
Gets the underlying collection, if available.- Returns:
- the collection, or null if created from an Iterator or Stream
-
getIterator
Gets the iterator used to read elements.- Returns:
- the iterator
-
getRecordConverterFunction
Gets the function used to convert elements to Records.- Returns:
- the converter function
-
addExceptionProperties
Adds exception properties for debugging purposes.- Overrides:
addExceptionPropertiesin classDataReader- Parameters:
exception- the exception to add properties to- Returns:
- the exception with added properties
-