All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.text.SortKey

java.lang.Object
   |
   +----java.text.SortKey

public final class SortKey
extends Object
Sort keys are generated by the Collation class. These are not real String objects. Use the SortKey methods to compare and manipulate sort keys.

Example of use:

     Collation myCollation = Collation.getDefault(Locale.US);
     SortKey key1 = myCollation.getSortKey("abc");
     SortKey key2 = myCollation.getSortKey("ABC");
     // do something with the sort keys
 

Because Collation.compare()'s algorithm is complex, it is faster to sort long lists of words by retrieving sort keys with Collation.getSortKey(). You can then cache the sort keys and compare them using SortKey.compareTo(). The following is the characteristics of sort keys:

See Also:
Collation, TableCollation, CollationKey

Method Index

 o compareTo(SortKey)
Convenience method which does a string(bit-wise) comparison of the two sort keys.
 o equals(Object)
Compare if two objects are the same.
 o hashCode()
Creates an integer that is unique to the sort key.
 o toString()
The string value of a sort key.

Methods

 o compareTo
  public byte compareTo(SortKey target)
Convenience method which does a string(bit-wise) comparison of the two sort keys.

Parameters:
sourceKey - source sort key
targetKey - target sort key
Returns:
Returns LESS if sourceKey < targetKey, GREATER if sourceKey > targetKey and EQUAL otherwise.
See Also:
compareTo
 o toString
  public String toString()
The string value of a sort key. For debugging purpose only, do not modify the string.

Returns:
the string value of a sort key.
Overrides:
toString in class Object
 o equals
  public boolean equals(Object source)
Compare if two objects are the same.

Parameters:
source - the object to compare to.
Returns:
Returns true if two objects are equal, false otherwise.
Overrides:
equals in class Object
 o hashCode
  public int hashCode()
Creates an integer that is unique to the sort key. NOTE: this is not the same as String.hashCode, which is a call on an object. However, if you are building a hashTable, you must ensure that hash & equal are consistent, otherwise you will corrupt your structure. If two objects are identical, the hash values should be the same. That is, if x.equals(y), then x.hashCode() = y.hashCode(). This call is used by CollatedString.hashCode().

Example of use:

     Collation myCollation = Collation.getDefault(Locale.US);
     SortKey key1 = myCollation.getSortKey("abc");
     SortKey key2 = myCollation.getSortKey("ABC");
     // key1.hashCode() != key2.hashCode()
 

Returns:
the hash value based on the string's collation order.
Overrides:
hashCode in class Object
See Also:
hashCode

All Packages  Class Hierarchy  This Package  Previous  Next  Index