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

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

public class NumberBasedSubkey
extends TextBasedSubkey

NumberBasedSubkey can be used for number-based sub-keys. All JsonNumber values are supported. In order to provide additional support for all other atomic values they are transformed in some way into numbers.

All non-atomic values (JsonArray and JsonRecord) are recursively traversed.

Author:
Matthias Pohl, Arvid Heise

Field Summary
 
Fields inherited from class de.hpi.fgis.dude.util.sorting.sortingkey.TextBasedSubkey
NO_VOWELS_REGEX, positions, tillEnd
 
Constructor Summary
protected NumberBasedSubkey()
          Internal constructor for Jsonable deserialization.
  NumberBasedSubkey(String attrName)
          Initializes a NumberBasedSubkey instance that takes all digits within the value.
  NumberBasedSubkey(String attrName, int firstDigit)
          Initializes a NumberBasedSubkey instance that takes all digits within the value.
  NumberBasedSubkey(String attrName, Integer[] pos)
          Initializes a NumberBasedSubkey instance that takes all digits within the value.
  NumberBasedSubkey(String attrName, int firstDigit, int length)
          Initializes a NumberBasedSubkey instance that takes all digits within the value.
 
Method Summary
protected  void collectRelevantValues(JsonArray collectedValues, JsonValue value)
          Collects all relevant values and put them into the passed JsonArray.
protected  int compareJsonValues(JsonValue val1, JsonValue val2)
          Executes the text-based comparison for each Json type.
 
Methods inherited from class de.hpi.fgis.dude.util.sorting.sortingkey.TextBasedSubkey
caseSensitivityEnabled, disableCaseSensitivity, disableCaseSensitivity, enableCaseSensitivity, equals, getFirstPosition, getIgnoreRegex, getPositions, hashCode, setIgnoredCharactersRegEx, setPositions, setRange, setRange
 
Methods inherited from class de.hpi.fgis.dude.util.sorting.sortingkey.AbstractSubkey
compare, getAttribute, getSubkeyValue, setAttribute, setDefaultAttribute, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberBasedSubkey

protected NumberBasedSubkey()
Internal constructor for Jsonable deserialization.


NumberBasedSubkey

public NumberBasedSubkey(String attrName)
Initializes a NumberBasedSubkey instance that takes all digits within the value.

Parameters:
attrName - The name of the attribute that shall be used for comparing the DuDeObjects.

NumberBasedSubkey

public NumberBasedSubkey(String attrName,
                         int firstDigit)
Initializes a NumberBasedSubkey instance that takes all digits within the value. firstCharacter specifies the index (starting at 0) of the first digit that will be considered.

Parameters:
attrName - The name of the attribute that shall be used for comparing the DuDeObjects.
firstDigit - The index of the first digit that shall be considered. If this value is a negative one, the counting starts from the end of the value (-1 means the last digit).

NumberBasedSubkey

public NumberBasedSubkey(String attrName,
                         int firstDigit,
                         int length)
Initializes a NumberBasedSubkey instance that takes all digits within the value. firstCharacter specifies the index (starting at 0) of the first digit that will be considered. length specifies the considered offset.

Parameters:
attrName - The name of the attribute that shall be used for comparing the DuDeObjects.
firstDigit - The index of the first digit that shall be considered. If this value is a negative one, the counting starts from the end of the value (-1 means the last digit).
length - The considered offset.

NumberBasedSubkey

public NumberBasedSubkey(String attrName,
                         Integer[] pos)
Initializes a NumberBasedSubkey instance that takes all digits within the value. pos can be used to specify which concrete digit shall be considered.

Parameters:
attrName - The name of the attribute that shall be used for comparing the DuDeObjects.
pos - An Integer array that is used for specifying the digits that shall be considered.
Method Detail

compareJsonValues

protected int compareJsonValues(JsonValue val1,
                                JsonValue val2)
Description copied from class: AbstractSubkey
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.

Overrides:
compareJsonValues in class TextBasedSubkey
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.

collectRelevantValues

protected void collectRelevantValues(JsonArray collectedValues,
                                     JsonValue value)
Description copied from class: AbstractSubkey
Collects all relevant values and put them into the passed JsonArray.

Overrides:
collectRelevantValues in class TextBasedSubkey
Parameters:
collectedValues - The JsonArray that shall be filled.
value - The JsonValue that shall be traversed. All relevant values will be extracted out of this instance.


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