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

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

public class TextBasedSubkey
extends AbstractSubkey

The class TextBasedSubkey provides the functionality for generating sub-keys based on String values. By specifying the ignoredCharactersRegEx the considered character types can be set.

Author:
Matthias Pohl, Arvid Heise

Field Summary
static String NO_VOWELS_REGEX
          This regular expression can be used if vocals should be ignored.
protected  List<Integer> positions
          Stores the position information.
protected  boolean tillEnd
          The property stores the information whether the suffix shall is requested.
 
Constructor Summary
protected TextBasedSubkey()
          An empty constructor for supporting Jsonable.fromJson(DuDeJsonParser).
  TextBasedSubkey(String attrName)
          Initializes this subkey with the passed attribute name.
  TextBasedSubkey(String attrName, String ignoreRegex)
          Initializes this subkey with the passed attribute name and the specified ignoredCharacters regular expression.
 
Method Summary
 boolean caseSensitivityEnabled()
          Checks if case-sensitivity is enabled.
protected  void collectRelevantValues(JsonArray array, 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.
 void disableCaseSensitivity()
          Disables case-sensitivity for the comparisons.
 void disableCaseSensitivity(Locale locale)
          Disables case-sensitivity for the comparisons.
 void enableCaseSensitivity()
          Enables case-sensitivity for the comparisons.
 boolean equals(Object obj)
           
protected  int getFirstPosition()
          Returns the first set position or 0 if no position is set.
 String getIgnoreRegex()
          Returns the regular expression that specifies which character classes are ignored within the current instance.
 Iterable<Integer> getPositions()
          Returns an iterable instance that stores all specified character positions.
 int hashCode()
           
 void setIgnoredCharactersRegEx(String regEx)
          Sets the regular expression which specifies the characters that will be ignored.
 void setPositions(Integer... positions)
          Sets the positions that shall be taken into account explicitly.
 void setRange(int beginIndex)
          Sets the range that shall be taken into account.
 void setRange(int beginIndex, int length)
          Sets the range that shall be taken into account.
 
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
 

Field Detail

NO_VOWELS_REGEX

public static final String NO_VOWELS_REGEX
This regular expression can be used if vocals should be ignored.

See Also:
Constant Field Values

positions

protected List<Integer> positions
Stores the position information.


tillEnd

protected boolean tillEnd
The property stores the information whether the suffix shall is requested.

Constructor Detail

TextBasedSubkey

protected TextBasedSubkey()
An empty constructor for supporting Jsonable.fromJson(DuDeJsonParser).


TextBasedSubkey

public TextBasedSubkey(String attrName)
Initializes this subkey with the passed attribute name.

Parameters:
attrName - The name of the attribute that shall be used for generating the subkey.

TextBasedSubkey

public TextBasedSubkey(String attrName,
                       String ignoreRegex)
Initializes this subkey with the passed attribute name and the specified ignoredCharacters regular expression.

Parameters:
attrName - The name of the attribute that shall be used for generating the subkey.
ignoreRegex - A regular expression that describes all the characters that shall be ignored in this subkey instance.
Method Detail

setPositions

public void setPositions(Integer... positions)
Sets the positions that shall be taken into account explicitly.

Parameters:
positions - The positions that shall be taken into account.
Throws:
NullPointerException - If null was passed.

setRange

public void setRange(int beginIndex)
Sets the range that shall be taken into account. The range includes the whole substring beginning at the passed beginIndex.

Parameters:
beginIndex - The first position.

setRange

public void setRange(int beginIndex,
                     int length)
Sets the range that shall be taken into account.

Parameters:
beginIndex - The first position.
length - The range's length.
Throws:
IllegalArgumentException - If a negative length was passed.

getPositions

public Iterable<Integer> getPositions()
Returns an iterable instance that stores all specified character positions.

Returns:
An iterable instance that stores all specified character positions.

setIgnoredCharactersRegEx

public void setIgnoredCharactersRegEx(String regEx)
Sets the regular expression which specifies the characters that will be ignored.

Parameters:
regEx - The regular expression for specifying which characters shall be ignored.

getIgnoreRegex

public String getIgnoreRegex()
Returns the regular expression that specifies which character classes are ignored within the current instance.

Returns:
The regular expression specifying all ignorable characters.

enableCaseSensitivity

public void enableCaseSensitivity()
Enables case-sensitivity for the comparisons. This means that 'a' and 'A' will be unequal.


disableCaseSensitivity

public void disableCaseSensitivity(Locale locale)
Disables case-sensitivity for the comparisons. This means that 'A' will be converted into 'a' so that 'A' and 'a' are the same. In order to provide a valid transformation to lower case letters Locale can be specified. If null is passed, English will be used as the default language.

Parameters:
locale - Specifies the underlying language.

disableCaseSensitivity

public void disableCaseSensitivity()
Disables case-sensitivity for the comparisons. This means that 'A' will be converted into 'a' so that 'A' and 'a' are the same. For transforming capital letters to lower case letters, the rules of DEFAULT_LOCALE are used.


caseSensitivityEnabled

public boolean caseSensitivityEnabled()
Checks if case-sensitivity is enabled.

Returns:
true, if case-sensitivity is enabled; otherwise false.

compareJsonValues

protected int compareJsonValues(JsonValue val1,
                                JsonValue val2)
                         throws ClassCastException
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.

Specified by:
compareJsonValues in class AbstractSubkey
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.

collectRelevantValues

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

Specified by:
collectRelevantValues in class AbstractSubkey
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.

getFirstPosition

protected int getFirstPosition()
Returns the first set position or 0 if no position is set.

Returns:
The first position that is set.

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractSubkey

equals

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


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