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.


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
getClass, notify, notifyAll, toString, wait, wait, wait
 

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