public class SortingCollection<T>
extends java.lang.Object
implements java.lang.Iterable<T>
Modifier and Type | Class and Description |
---|---|
static interface |
SortingCollection.Codec<T>
Client must implement this class, which defines the way in which records are written to and
read from file.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T rec) |
void |
cleanup()
Delete any temporary files.
|
void |
doneAdding()
This method can be called after caller is done adding to collection, in order to possibly free
up memory.
|
boolean |
isDestructiveIteration() |
CloseableIterator<T> |
iterator()
Prepare to iterate through the records in order.
|
static <T> SortingCollection<T> |
newInstance(java.lang.Class<T> componentType,
SortingCollection.Codec<T> codec,
java.util.Comparator<T> comparator,
int maxRecordsInRAM)
Syntactic sugar around the ctor, to save some typing of type parameters.
|
static <T> SortingCollection<T> |
newInstance(java.lang.Class<T> componentType,
SortingCollection.Codec<T> codec,
java.util.Comparator<T> comparator,
int maxRecordsInRAM,
java.util.Collection<java.io.File> tmpDirs)
Syntactic sugar around the ctor, to save some typing of type parameters
|
static <T> SortingCollection<T> |
newInstance(java.lang.Class<T> componentType,
SortingCollection.Codec<T> codec,
java.util.Comparator<T> comparator,
int maxRecordsInRAM,
java.io.File... tmpDir)
Syntactic sugar around the ctor, to save some typing of type parameters
|
void |
setDestructiveIteration(boolean destructiveIteration)
Tell this collection that it is allowed to discard data during iteration in order to reduce memory footprint,
precluding a second iteration.
|
public void add(T rec)
public void doneAdding()
public boolean isDestructiveIteration()
public void setDestructiveIteration(boolean destructiveIteration)
public CloseableIterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public void cleanup()
public static <T> SortingCollection<T> newInstance(java.lang.Class<T> componentType, SortingCollection.Codec<T> codec, java.util.Comparator<T> comparator, int maxRecordsInRAM, java.io.File... tmpDir)
componentType
- Class of the record to be sorted. Necessary because of Java generic lameness.codec
- For writing records to file and reading them back into RAMcomparator
- Defines output sort ordermaxRecordsInRAM
- how many records to accumulate in memory before spilling to disktmpDir
- Where to write files of records that will not fit in RAMpublic static <T> SortingCollection<T> newInstance(java.lang.Class<T> componentType, SortingCollection.Codec<T> codec, java.util.Comparator<T> comparator, int maxRecordsInRAM, java.util.Collection<java.io.File> tmpDirs)
componentType
- Class of the record to be sorted. Necessary because of Java generic lameness.codec
- For writing records to file and reading them back into RAMcomparator
- Defines output sort ordermaxRecordsInRAM
- how many records to accumulate in memory before spilling to disktmpDirs
- Where to write files of records that will not fit in RAMpublic static <T> SortingCollection<T> newInstance(java.lang.Class<T> componentType, SortingCollection.Codec<T> codec, java.util.Comparator<T> comparator, int maxRecordsInRAM)
componentType
- Class of the record to be sorted. Necessary because of Java generic lameness.codec
- For writing records to file and reading them back into RAMcomparator
- Defines output sort ordermaxRecordsInRAM
- how many records to accumulate in memory before spilling to disk