com.arsdigita.messaging
Class SortKey

java.lang.Object
  extended bycom.arsdigita.messaging.SortKey

public class SortKey
extends Object

A utility class used to manipulate sort keys for messages. Sort keys are used to encode the structure of a set of message threads as follows:

    message       sort key
    ----------    -----------
    msg1          05a
       msg2       05a000
       msg3       05a001
          msg5    05a001000
          msg6    05a001001
          ...
          msg95   05a00101X
    msg4          05b
 

Sort keys are base-62 numbers that are encoded using the alphanumeric characters 0-9, A-Z, and a-z to represent digits 0 through 61. This maps to the following character range:

  00-09    '0'-'9'
  10-35    'A'-'Z'
  36-61    'a'-'z'
 

A tree structure like the one pictured above is respresented with 3 digits for each level (238328 keys) and an unlimited number of levels. Child keys are generated by extending the parent's key 3 digits to the right. In the example above you can observe this by comparing the sort keys for msg2 and msg1, for example.

There are several advantages to this:

  1. The parents and children of any key are easy to compute.
  2. All keys sort lexagraphically to produce the correct structure of the tree.
  3. Computing the next key in the sequence is easy.
  4. It is possible to represent very large keys with a small number of bytes.

Version:
$Id: //core-platform/dev/src/com/arsdigita/messaging/SortKey.java#7 $
Author:
Ron Henderson, Stefan Deusch

Field Summary
static String versionId
           
 
Constructor Summary
SortKey()
          Creates a new sort key and initializes it to the zero value.
SortKey(SortKey parent)
          Takes a parent sort key and returns its first child.
SortKey(String sortkey)
          Takes the given string and converts it into a sort key.
 
Method Summary
 SortKey getChild()
          Gets the first child of this sort key.
 int getDepth()
          Gets the depth of the current sort key in the tree.
 SortKey getParent()
          Gets the parent of this sort key.
 int intValue()
          Returns the value of the sort key as an integer.
 int length()
          Gets the length of the sort key, in other words the number of digits it contains.
 void next()
          Increments the value of the sort key to the next element of the sequence.
 String toString()
          Returns a string representation of this sort key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

SortKey

public SortKey()
Creates a new sort key and initializes it to the zero value.


SortKey

public SortKey(String sortkey)
Takes the given string and converts it into a sort key.


SortKey

public SortKey(SortKey parent)
Takes a parent sort key and returns its first child.

Method Detail

getChild

public SortKey getChild()
Gets the first child of this sort key. This extends the current sort key's value by 3 digits to the right.

Returns:
the first child of this sort key.

getParent

public SortKey getParent()
Gets the parent of this sort key.

Returns:
the parent of this sort key.

toString

public String toString()
Returns a string representation of this sort key.

Returns:
a string representation of this sort key.

getDepth

public int getDepth()
Gets the depth of the current sort key in the tree. Note that depth is always greater than or equal to one.

Returns:
the depth of the current sort key in the tree.

length

public int length()
Gets the length of the sort key, in other words the number of digits it contains.

Returns:
the length of the sort key

next

public void next()
Increments the value of the sort key to the next element of the sequence.


intValue

public int intValue()
Returns the value of the sort key as an integer. This will run out of room to fit inside an int when the depth is somewhere between 2 and 3 levels, so it's really only useful for very shallow trees. Used mainly for debugging.

Returns:
the value of the sort key as an integer.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC