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

java.lang.Object
  extended by de.hpi.fgis.dude.util.sorting.sortingkey.AbstractSubkey
All Implemented Interfaces:
AutoJsonable, Subkey, Comparator<DuDeObject>
Direct Known Subclasses:
TextBasedSubkey

public abstract class AbstractSubkey
extends Object
implements Subkey

AbstractSubkey is an abstract class that should be extended by each subkey class. It implements Subkey particularly.

Author:
Matthias Pohl, Arvid Heise

Constructor Summary
AbstractSubkey(String... defaultAttr)
          Initializes a AbstractSubkey instance with the given default attribute.
 
Method Summary
protected abstract  void collectRelevantValues(JsonArray array, JsonValue value)
          Collects all relevant values and put them into the passed JsonArray.
 int compare(DuDeObject o1, DuDeObject o2)
           
protected abstract  int compareJsonValues(JsonValue val1, JsonValue val2)
          Executes the text-based comparison for each Json type.
 boolean equals(Object obj)
           
protected  String[] getAttribute(DuDeObject obj)
          Returns the attribute that corresponds to source of the passed DuDeObject.
 JsonArray getSubkeyValue(DuDeObject obj)
          Returns a JsonArray that collects all relevant values for the subkey of the passed DuDeObject.
 int hashCode()
           
 void setAttribute(DataSource source, String... attribute)
          Sets the attribute for the passed DataSource.
 void setDefaultAttribute(String... defaultAttr)
          Sets the default attribute.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractSubkey

public AbstractSubkey(String... defaultAttr)
Initializes a AbstractSubkey instance with the given default attribute.

Parameters:
defaultAttr - The default attribute that is used for generating a sub-key.
Method Detail

setDefaultAttribute

public void setDefaultAttribute(String... defaultAttr)
Sets the default attribute. This attribute is used, if no specific attribute was set for a given DataSource. Passing an empty attribute or null will unset the current default attribute.

Parameters:
defaultAttr - The default attribute.

setAttribute

public void setAttribute(DataSource source,
                         String... attribute)
Sets the attribute for the passed DataSource. Passing null instead of an attribute will remove the attribute of the passed DataSource from this Subkey.

Parameters:
source - The DataSource.
attribute - The corresponding attribute.
Throws:
NullPointerException - If the null was passed instead of a DataSource.

getAttribute

protected String[] getAttribute(DuDeObject obj)
Returns the attribute that corresponds to source of the passed DuDeObject.

Parameters:
obj - The DuDeObject.
Returns:
The corresponding attribute.

collectRelevantValues

protected abstract void collectRelevantValues(JsonArray array,
                                              JsonValue value)
Collects all relevant values and put them into the passed JsonArray.

Parameters:
array - The JsonArray that shall be filled.
value - The JsonValue that shall be traversed. All relevant values will be extracted out of this instance.

compare

public int compare(DuDeObject o1,
                   DuDeObject o2)
Specified by:
compare in interface Comparator<DuDeObject>

compareJsonValues

protected abstract int compareJsonValues(JsonValue val1,
                                         JsonValue val2)
                                  throws ClassCastException
Executes the text-based comparison for each Json type. Therefore all atomic JsonValues are transformed into their String representation. The Json types storing multiple JsonValues ( JsonRecord and JsonArray) are traversed. If the passed JsonValues are of different types, the order of the JsonValue.JsonTypes is used.

Parameters:
val1 - The first JsonValue.
val2 - The second JsonValue.
Returns:
-1 if val1 is less than val2; 1 if val1 is larger than val2 and 0, if they are equal.
Throws:
ClassCastException - If at least one of the past values can't be converted.

getSubkeyValue

public JsonArray getSubkeyValue(DuDeObject obj)
Description copied from interface: Subkey
Returns a JsonArray that collects all relevant values for the subkey of the passed DuDeObject.

Specified by:
getSubkeyValue in interface Subkey
Parameters:
obj - The object from which the sub-key shall be returned.
Returns:
The JsonArray collecting all relevant values of the sub-key.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

toString

public String toString()
Overrides:
toString in class Object


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