org.openstreetmap.osmosis.core.sort.common
Class FileBasedSort<T extends Storeable>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.sort.common.FileBasedSort<T>
Type Parameters:
T - The object type to be sorted.
All Implemented Interfaces:
Releasable

public class FileBasedSort<T extends Storeable>
extends java.lang.Object
implements Releasable

Allows a large number of objects to be sorted by writing them all to disk then sorting using a merge sort algorithm.

Author:
Brett Henderson

Constructor Summary
FileBasedSort(ObjectSerializationFactory serializationFactory, java.util.Comparator<T> comparator, boolean useCompression)
          Creates a new instance.
 
Method Summary
 void add(T value)
          Adds a new object to be sorted.
 ReleasableIterator<T> iterate()
          Sorts and returns the contents of the sorter.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileBasedSort

public FileBasedSort(ObjectSerializationFactory serializationFactory,
                     java.util.Comparator<T> comparator,
                     boolean useCompression)
Creates a new instance.

Parameters:
serializationFactory - The factory defining the object serialisation implementation.
comparator - The comparator to be used for sorting the results.
useCompression - If true, the storage files will be compressed.
Method Detail

add

public void add(T value)
Adds a new object to be sorted.

Parameters:
value - The data object.

iterate

public ReleasableIterator<T> iterate()
Sorts and returns the contents of the sorter.

Returns:
An iterator providing access to the sorted entities.

release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable