com.fasterxml.sort.util
Class CollectionReader<T>

java.lang.Object
  extended by com.fasterxml.sort.DataReader<T>
      extended by com.fasterxml.sort.util.CollectionReader<T>

public class CollectionReader<T>
extends DataReader<T>

Simple DataReader implementation that can be used to serve items from a Collection (or Iterator). Note that implementation of estimateSizeInBytes(T) is naive and returns 1 for all items; it must be redefined if memory limits are to be enforced, or alternatively Sorter should be configured with maximum number of items to use as memory limit.


Field Summary
protected  Iterator<T> _items
           
 
Constructor Summary
CollectionReader(Collection<T> items)
           
CollectionReader(Iterator<T> items)
           
 
Method Summary
 void close()
          Method for closing the reader.
 int estimateSizeInBytes(T item)
          Method that should estimate memory usage of given item, for purpose of limiting amount of data kept in memory during pre-sorting phase.
 T readNext()
          Method for reading the next data item; will return null to indicate end of input, otherwise return a non-null item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_items

protected Iterator<T> _items
Constructor Detail

CollectionReader

public CollectionReader(Collection<T> items)

CollectionReader

public CollectionReader(Iterator<T> items)
Method Detail

readNext

public T readNext()
Description copied from class: DataReader
Method for reading the next data item; will return null to indicate end of input, otherwise return a non-null item.

Specified by:
readNext in class DataReader<T>

estimateSizeInBytes

public int estimateSizeInBytes(T item)
Description copied from class: DataReader
Method that should estimate memory usage of given item, for purpose of limiting amount of data kept in memory during pre-sorting phase.

Specified by:
estimateSizeInBytes in class DataReader<T>

close

public void close()
           throws IOException
Description copied from class: DataReader
Method for closing the reader. Note that reader needs to ensure that it is ok to call close multiple times. Reader may also close underlying resources as soon as it has reached end of input.

Specified by:
close in class DataReader<T>
Throws:
IOException


Copyright © 2011. All Rights Reserved.