de.hpi.fgis.dude.util.sorting.sortingkey
Class SortingKey

java.lang.Object
  extended by de.hpi.fgis.dude.util.sorting.sortingkey.SortingKey
All Implemented Interfaces:
AutoJsonable, Comparator<DuDeObject>

public class SortingKey
extends Object
implements Comparator<DuDeObject>, AutoJsonable

The SortingKey collects different sub-keys and compares different DuDeObject based on these sub-keys. Each sub-key has to implement Comparator based on DuDeObjects.

Author:
Matthias Pohl, Arvid Heise

Constructor Summary
SortingKey()
          Initializes a SortingKey with no sub-key(s).
SortingKey(Subkey... subkeys)
          Initializes a SortingKey instance.
 
Method Summary
 SortingKey addSubkey(Subkey newSubkey)
          Adds a sub-key to the SortingKey.
 int compare(DuDeObject record1, DuDeObject record2)
          Compares two DuDeObjects.
 boolean equals(Object obj)
           
 String getKeyString(DuDeObject obj)
          Returns the sorting key value of the passed DuDeObject.
 String getKeyString(DuDeObject obj, String splitToken)
          Returns the sorting key value of the passed DuDeObject.
 JsonArray getKeyValue(DuDeObject obj)
          Returns the sorting key value of the passed DuDeObject.
 int hashCode()
           
 boolean isEmpty()
          Checks whether any Subkey was added.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortingKey

public SortingKey()
Initializes a SortingKey with no sub-key(s). Additional sub-keys can be added using the addSubkey(Subkey) method. If no sub-key will be added all DuDeObjects that are compared based on that sorting key will be equal.


SortingKey

public SortingKey(Subkey... subkeys)
Initializes a SortingKey instance. Calling this constructor may cause a compiler warning. The warning can be ignored.

Parameters:
subkeys - A list of sub-keys that shall be used within the sorting key. (Caution: the order within the parameter list matters!)
Method Detail

addSubkey

public SortingKey addSubkey(Subkey newSubkey)
Adds a sub-key to the SortingKey. (Caution: the order of calling addSubkey() matters!)

Parameters:
newSubkey - An additional sub-key.
Returns:
A reference to this object.

compare

public int compare(DuDeObject record1,
                   DuDeObject record2)
Compares two DuDeObjects.

Specified by:
compare in interface Comparator<DuDeObject>
Parameters:
record1 - The first DuDeObject instance.
record2 - The second DuDeObject instance.
Returns:
The value 0, if the first DuDeObject instance is equal to the second one; a value less than 0, if the first DuDeObject instance is lexicographically less than the second one depending on the sorting key; and a value greater than 0, if the first DuDeObject instance is lexicographically greater than the second one depending on the sorting key.

equals

public boolean equals(Object obj)
Specified by:
equals in interface Comparator<DuDeObject>
Overrides:
equals in class Object

getKeyString

public String getKeyString(DuDeObject obj)
Returns the sorting key value of the passed DuDeObject.

Parameters:
obj - The DuDeObject from which the sorting key shall be returned.
Returns:
The String representation of the sorting key that belongs to the passed DuDeObject. If multiple values are generating the sorting key, they are concatenated without any split token (i.e. the split token is the empty String).
See Also:
getKeyString(DuDeObject, String)

getKeyString

public String getKeyString(DuDeObject obj,
                           String splitToken)
Returns the sorting key value of the passed DuDeObject. The returned String represents the key value that is used for positioning this object within a sorted collection.
Note: this method does not work well with numerical values

Parameters:
obj - The DuDeObject from which the sorting key shall be returned.
splitToken - The token that shall be used for splitting all values.
Returns:
The String representation of the sorting key that belongs to the passed DuDeObject. *
See Also:
getKeyValue(DuDeObject)

getKeyValue

public JsonArray getKeyValue(DuDeObject obj)
Returns the sorting key value of the passed DuDeObject. The returned JsonArray is used for positioning this object within a sorted collection.

Parameters:
obj - The DuDeObject from which the sorting key shall be returned.
Returns:
The JsonArray representation of the sorting key that belongs to the passed DuDeObject. *

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Checks whether any Subkey was added.

Returns:
true, if at least one Subkey was added; otherwise false.

toString

public String toString()
Overrides:
toString in class Object


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