com.sleepycat.collections
Class KeyRange

java.lang.Object
  extended by com.sleepycat.collections.KeyRange

 class KeyRange
extends Object

Encapsulates a key range for use with a RangeCursor.


Field Summary
(package private)  boolean beginInclusive
           
(package private)  DatabaseEntry beginKey
           
(package private)  Comparator comparator
           
(package private)  boolean endInclusive
           
(package private)  DatabaseEntry endKey
           
(package private)  boolean singleKey
           
 
Constructor Summary
KeyRange(Comparator comparator)
          Creates an unconstrained key range.
 
Method Summary
(package private)  boolean check(DatabaseEntry key)
          Returns whether a given key is within range.
(package private)  boolean check(DatabaseEntry key, boolean inclusive)
          Returns whether a given key is within range.
(package private)  boolean checkBegin(DatabaseEntry key, boolean inclusive)
          Returns whether the given key is within range with respect to the beginning of the range.
(package private)  boolean checkEnd(DatabaseEntry key, boolean inclusive)
          Returns whether the given key is within range with respect to the end of the range.
(package private)  int compare(DatabaseEntry key1, DatabaseEntry key2)
          Compares two keys, using the user comparator if there is one.
(package private) static int compareBytes(byte[] data1, int offset1, int size1, byte[] data2, int offset2, int size2)
          Compares two keys as unsigned byte arrays, which is the default comparison used by JE/DB.
(package private) static DatabaseEntry copy(DatabaseEntry from)
          Returns a copy of an entry.
(package private) static void copy(DatabaseEntry from, DatabaseEntry to)
          Copies one entry to another.
(package private) static boolean equalBytes(DatabaseEntry e1, DatabaseEntry e2)
          Returns the two DatabaseEntry objects have the same data value.
(package private) static byte[] getByteArray(DatabaseEntry entry)
          Returns an entry's byte array, copying it if the entry offset is non-zero.
(package private)  DatabaseEntry getSingleKey()
          Returns the key of a single-key range, or null if not a single-key range.
(package private)  boolean hasBound()
          Returns whether this range has a begin or end bound.
(package private)  KeyRange subRange(DatabaseEntry key)
          Creates a range for a single key.
(package private)  KeyRange subRange(DatabaseEntry beginKey, boolean beginInclusive, DatabaseEntry endKey, boolean endInclusive)
          Creates a range that is the intersection of this range and the given range parameters.
 String toString()
          Formats this range as a string for debugging.
(package private) static String toString(DatabaseEntry dbt)
          Converts the byte array of this thang to space-separated integers, and suffixed by the record number if applicable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comparator

Comparator comparator

beginKey

DatabaseEntry beginKey

endKey

DatabaseEntry endKey

singleKey

boolean singleKey

beginInclusive

boolean beginInclusive

endInclusive

boolean endInclusive
Constructor Detail

KeyRange

KeyRange(Comparator comparator)
Creates an unconstrained key range.

Method Detail

subRange

KeyRange subRange(DatabaseEntry key)
            throws KeyRangeException
Creates a range for a single key.

Throws:
KeyRangeException

subRange

KeyRange subRange(DatabaseEntry beginKey,
                  boolean beginInclusive,
                  DatabaseEntry endKey,
                  boolean endInclusive)
            throws KeyRangeException
Creates a range that is the intersection of this range and the given range parameters.

Throws:
KeyRangeException

getSingleKey

final DatabaseEntry getSingleKey()
Returns the key of a single-key range, or null if not a single-key range.


hasBound

final boolean hasBound()
Returns whether this range has a begin or end bound.


toString

public String toString()
Formats this range as a string for debugging.

Overrides:
toString in class Object

check

boolean check(DatabaseEntry key)
Returns whether a given key is within range.


check

boolean check(DatabaseEntry key,
              boolean inclusive)
Returns whether a given key is within range.


checkBegin

boolean checkBegin(DatabaseEntry key,
                   boolean inclusive)
Returns whether the given key is within range with respect to the beginning of the range.

The inclusive parameter should be true for checking a key read from the database; this will require that the key is within range. When inclusive=false the key is allowed to be equal to the beginKey for the range; this is used for checking a new exclusive bound of a sub-range.

Note that when inclusive=false and beginInclusive=true our check is not exactly correct because in theory we should allow the key to be "one less" than the existing bound; however, checking for "one less" is impossible so we do the best we can and test the bounds conservatively.


checkEnd

boolean checkEnd(DatabaseEntry key,
                 boolean inclusive)
Returns whether the given key is within range with respect to the end of the range. See checkBegin for details.


compare

int compare(DatabaseEntry key1,
            DatabaseEntry key2)
Compares two keys, using the user comparator if there is one.


compareBytes

static int compareBytes(byte[] data1,
                        int offset1,
                        int size1,
                        byte[] data2,
                        int offset2,
                        int size2)
Compares two keys as unsigned byte arrays, which is the default comparison used by JE/DB.


copy

static DatabaseEntry copy(DatabaseEntry from)
Returns a copy of an entry.


copy

static void copy(DatabaseEntry from,
                 DatabaseEntry to)
Copies one entry to another.


getByteArray

static byte[] getByteArray(DatabaseEntry entry)
Returns an entry's byte array, copying it if the entry offset is non-zero.


equalBytes

static boolean equalBytes(DatabaseEntry e1,
                          DatabaseEntry e2)
Returns the two DatabaseEntry objects have the same data value.


toString

static String toString(DatabaseEntry dbt)
Converts the byte array of this thang to space-separated integers, and suffixed by the record number if applicable.

Parameters:
dbt - the thang to convert.
the - resulting string.


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.