de.hpi.fgis.dude.util.sorting.sorter
Class TwoPhaseMultiWayMergeSorter

java.lang.Object
  extended by de.hpi.fgis.dude.util.sorting.sorter.AbstractDuDeObjectSorter
      extended by de.hpi.fgis.dude.util.sorting.sorter.TwoPhaseMultiWayMergeSorter
All Implemented Interfaces:
DuDeObjectSorter

public class TwoPhaseMultiWayMergeSorter
extends AbstractDuDeObjectSorter

TwoPhaseMultiWayMergeSorter implements a file-based sorting using the Two-Phase Multi-Way Merge-Sort algorithm (TPMMS).

Author:
Matthias Pohl

Constructor Summary
TwoPhaseMultiWayMergeSorter()
          Initializes a TwoPhaseMultiWayMergeSorter with no SortingKey.
TwoPhaseMultiWayMergeSorter(SortingKey key)
          Initializes a TwoPhaseMultiWayMergeSorter with the passed SortingKey.
 
Method Summary
 void add(DuDeObject record)
          Adds a DuDeObject to the collection that will be sorted.
 void clear()
          Clears the already added data.
protected  void generateSortedFile()
          Sorts the in-memory data and writes it into a file.
protected  String getNextTemporaryFilename()
          Returns the name of the next temporary DuDeObjectFile.
 DuDeStorage<DuDeObject> getSortedCollection()
          Returns the sorted data.
protected  String getSortedDataFilename()
          Returns the name of the DuDeObjectFile containing the sorted data.
 
Methods inherited from class de.hpi.fgis.dude.util.sorting.sorter.AbstractDuDeObjectSorter
addAll, getInMemoryData, getSortingKey, memoryLimitReached, setSortingKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwoPhaseMultiWayMergeSorter

public TwoPhaseMultiWayMergeSorter()
Initializes a TwoPhaseMultiWayMergeSorter with no SortingKey.


TwoPhaseMultiWayMergeSorter

public TwoPhaseMultiWayMergeSorter(SortingKey key)
Initializes a TwoPhaseMultiWayMergeSorter with the passed SortingKey.

Parameters:
key - The sorting key that defines the sorting order.
Method Detail

clear

public void clear()
Description copied from interface: DuDeObjectSorter
Clears the already added data.

Specified by:
clear in interface DuDeObjectSorter
Overrides:
clear in class AbstractDuDeObjectSorter

add

public void add(DuDeObject record)
Description copied from interface: DuDeObjectSorter
Adds a DuDeObject to the collection that will be sorted.

Specified by:
add in interface DuDeObjectSorter
Overrides:
add in class AbstractDuDeObjectSorter
Parameters:
record - The DuDeObject.

getSortedCollection

public DuDeStorage<DuDeObject> getSortedCollection()
                                            throws IOException
Description copied from class: AbstractDuDeObjectSorter
Returns the sorted data. This method needs to be implemented by each sub-class. It should sort the data in some way and return it.

Specified by:
getSortedCollection in interface DuDeObjectSorter
Specified by:
getSortedCollection in class AbstractDuDeObjectSorter
Returns:
A sorted collection of the data.
Throws:
IOException - If an error occurs while sorting the data file-based.

generateSortedFile

protected void generateSortedFile()
Sorts the in-memory data and writes it into a file. This file is encapsulated in an SortedDataFile that will be added to sortedDataFiles.


getNextTemporaryFilename

protected String getNextTemporaryFilename()
Returns the name of the next temporary DuDeObjectFile.

Returns:
The next file name that shall be used.

getSortedDataFilename

protected String getSortedDataFilename()
Returns the name of the DuDeObjectFile containing the sorted data. This file name is a concatenation of SORTED_DATA_FILENAME_PREFIX and the current time in milliseconds.

Returns:
The name of the file that contains the sorted data.


Copyright © 2011 Hasso Plattner Institute - Chair of Information Systems. All Rights Reserved.