global
Class SearchKey

java.lang.Object
  extended by global.SearchKey
All Implemented Interfaces:
java.lang.Comparable<SearchKey>

public class SearchKey
extends java.lang.Object
implements java.lang.Comparable<SearchKey>

Provides a general and type-safe way to store and compare index search keys.


Field Summary
protected static byte FLOAT_KEY
          Internal type number for Float keys.
protected static byte INTEGER_KEY
          Internal type number for Integer keys.
protected  short size
          The size of the key value (in bytes).
protected static byte STRING_KEY
          Internal type number for String keys.
protected  byte type
          The type of the key value.
protected  java.lang.Object value
          The actual key value.
 
Constructor Summary
SearchKey(byte[] data, short offset)
          Constructs a SearchKey stored in the given data buffer.
SearchKey(java.lang.Float value)
          Constructs a new float search key.
SearchKey(java.lang.Integer value)
          Constructs a new integer search key.
SearchKey(java.lang.Object value)
          Constructs a search key from a generic value.
SearchKey(SearchKey key)
          Copy constructor for a search key.
SearchKey(java.lang.String value)
          Constructs a new string search key.
 
Method Summary
 int compareTo(SearchKey key)
          Generically compares two search keys.
 boolean equals(java.lang.Object obj)
          True if obj is a SearchKey with the same values; false otherwise.
 int getHash(int depth)
          Gets the hash value for the search key, given the depth (i.e.
 short getLength()
          Gets the total length of the search key (in bytes).
 int hashCode()
          Returns a generic hash code for the key value.
 boolean isHash(int hash)
          Returns true if the search key matches the given hash value, false otherwise.
 void writeData(byte[] data, short offset)
          Writes the SearchKey into the given data buffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER_KEY

protected static final byte INTEGER_KEY
Internal type number for Integer keys.

See Also:
Constant Field Values

FLOAT_KEY

protected static final byte FLOAT_KEY
Internal type number for Float keys.

See Also:
Constant Field Values

STRING_KEY

protected static final byte STRING_KEY
Internal type number for String keys.

See Also:
Constant Field Values

type

protected byte type
The type of the key value.


size

protected short size
The size of the key value (in bytes).


value

protected java.lang.Object value
The actual key value.

Constructor Detail

SearchKey

public SearchKey(java.lang.Integer value)
Constructs a new integer search key.


SearchKey

public SearchKey(java.lang.Float value)
Constructs a new float search key.


SearchKey

public SearchKey(java.lang.String value)
Constructs a new string search key.


SearchKey

public SearchKey(java.lang.Object value)
Constructs a search key from a generic value.

Throws:
java.lang.IllegalArgumentException - if value's type is invalid

SearchKey

public SearchKey(SearchKey key)
Copy constructor for a search key.


SearchKey

public SearchKey(byte[] data,
                 short offset)
Constructs a SearchKey stored in the given data buffer.

Method Detail

writeData

public void writeData(byte[] data,
                      short offset)
Writes the SearchKey into the given data buffer.


getLength

public short getLength()
Gets the total length of the search key (in bytes).


getHash

public int getHash(int depth)
Gets the hash value for the search key, given the depth (i.e. number of bits to consider).


isHash

public boolean isHash(int hash)
Returns true if the search key matches the given hash value, false otherwise.


hashCode

public int hashCode()
Returns a generic hash code for the key value.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
True if obj is a SearchKey with the same values; false otherwise.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(SearchKey key)
Generically compares two search keys.

Specified by:
compareTo in interface java.lang.Comparable<SearchKey>
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
Throws:
java.lang.IllegalArgumentException - if the search keys are not comparable