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

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

public abstract class AbstractDuDeObjectSorter
extends Object
implements DuDeObjectSorter

AbstractDuDeObjectSorter implements the DuDeObjectSorter interface partially. Sorting implementations only have to deal with the abstract method getSortedCollection().

Author:
Matthias Pohl

Constructor Summary
AbstractDuDeObjectSorter()
          Initializes an AbstractDuDeObjectSorter with no SortingKey.
AbstractDuDeObjectSorter(SortingKey key)
          Initializes an AbstractDuDeObjectSorter with the passed SortingKey.
 
Method Summary
 void add(DuDeObject record)
          Adds a DuDeObject to the collection that will be sorted.
 void addAll(Iterable<DuDeObject> objects)
          Adds all elements of the passed Iterable to the AbstractDuDeObjectSorter.
 void clear()
          Clears the already added data.
protected  List<DuDeObject> getInMemoryData()
          Returns the in-memory data.
abstract  DuDeStorage<DuDeObject> getSortedCollection()
          Returns the sorted data.
protected  SortingKey getSortingKey()
          Returns the SortingKey that defines the sorting order.
protected  boolean memoryLimitReached()
          Checks whether the memory limit was reached.
 void setSortingKey(SortingKey sortingKey)
          Sets a new SortingKey.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDuDeObjectSorter

public AbstractDuDeObjectSorter()
Initializes an AbstractDuDeObjectSorter with no SortingKey.


AbstractDuDeObjectSorter

public AbstractDuDeObjectSorter(SortingKey key)
Initializes an AbstractDuDeObjectSorter with the passed SortingKey.

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

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
Parameters:
record - The DuDeObject.

addAll

public void addAll(Iterable<DuDeObject> objects)
Adds all elements of the passed Iterable to the AbstractDuDeObjectSorter. It simply calls add(DuDeObject) on each element.

Specified by:
addAll in interface DuDeObjectSorter
Parameters:
objects - The DuDeObjects that shall be added.

clear

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

Specified by:
clear in interface DuDeObjectSorter

getSortedCollection

public abstract DuDeStorage<DuDeObject> getSortedCollection()
                                                     throws IOException
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
Returns:
A sorted collection of the data.
Throws:
IOException - If an error occurs while sorting the data file-based.

memoryLimitReached

protected boolean memoryLimitReached()
Checks whether the memory limit was reached.

Returns:
true, if no more elements should be added; otherwise false.

getInMemoryData

protected List<DuDeObject> getInMemoryData()
Returns the in-memory data.

Returns:
The in-memory data.

getSortingKey

protected SortingKey getSortingKey()
Returns the SortingKey that defines the sorting order.

Returns:
The SortingKey.

setSortingKey

public void setSortingKey(SortingKey sortingKey)
Description copied from interface: DuDeObjectSorter
Sets a new SortingKey.

Specified by:
setSortingKey in interface DuDeObjectSorter
Parameters:
sortingKey - The new SortingKey.


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