Class CollectionReader<T>

Type Parameters:
T - the type of elements in the collection

public class CollectionReader<T> extends DataReader
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:
  • Constructor Details

    • CollectionReader

      public CollectionReader(Collection<T> collection, Function<T,Record> recordConverterFunction)
      Creates a CollectionReader from a Collection.
      Parameters:
      collection - the collection to read from, or null for an empty collection
      recordConverterFunction - function to convert each element to a Record
    • CollectionReader

      public CollectionReader(Iterator<T> iterator, Function<T,Record> recordConverterFunction)
      Creates a CollectionReader from an Iterator.
      Parameters:
      iterator - the iterator to read from, or null for an empty iterator
      recordConverterFunction - function to convert each element to a Record
    • CollectionReader

      public CollectionReader(Stream<T> stream, Function<T,Record> recordConverterFunction)
      Creates a CollectionReader from a Stream.
      Parameters:
      stream - the stream to read from, or null for an empty stream
      recordConverterFunction - function to convert each element to a Record
  • Method Details

    • readImpl

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

      Contract for subclasses (see also docs/authoring/DataReader.md):

      Specified by:
      readImpl in class DataReader
      Throws:
      Throwable
    • elementToRecord

      protected Record elementToRecord(T nextElement)
      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

      protected Collection<T> getCollection()
      Gets the underlying collection, if available.
      Returns:
      the collection, or null if created from an Iterator or Stream
    • getIterator

      protected Iterator<T> getIterator()
      Gets the iterator used to read elements.
      Returns:
      the iterator
    • getRecordConverterFunction

      protected Function<T,Record> getRecordConverterFunction()
      Gets the function used to convert elements to Records.
      Returns:
      the converter function
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Adds exception properties for debugging purposes.
      Overrides:
      addExceptionProperties in class DataReader
      Parameters:
      exception - the exception to add properties to
      Returns:
      the exception with added properties