com.sleepycat.collections

Class StoredSortedKeySet

public class StoredSortedKeySet extends StoredKeySet implements SortedSet

The SortedSet returned by Map.keySet() and which can also be constructed directly if a Map is not needed. Since this collection is a set it only contains one element for each key, even when duplicates are allowed. Key set iterators are therefore particularly useful for enumerating the unique keys of a store or index that allows duplicates.

In addition to the standard SortedSet methods, this class provides the following methods for stored sorted sets only. Note that the use of these methods is not compatible with the standard Java collections interface.

Constructor Summary
StoredSortedKeySet(Database database, EntryBinding keyBinding, boolean writeAllowed)
Creates a sorted key set view of a Database.
Method Summary
Comparatorcomparator()
Returns null since comparators are not supported.
Objectfirst()
Returns the first (lowest) element currently in this sorted set.
SortedSetheadSet(Object toKey)
Returns a view of the portion of this sorted set whose elements are strictly less than toKey.
SortedSetheadSet(Object toKey, boolean toInclusive)
Returns a view of the portion of this sorted set whose elements are strictly less than toKey, optionally including toKey.
Objectlast()
Returns the last (highest) element currently in this sorted set.
SortedSetsubSet(Object fromKey, Object toKey)
Returns a view of the portion of this sorted set whose elements range from fromKey, inclusive, to toKey, exclusive.
SortedSetsubSet(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive)
Returns a view of the portion of this sorted set whose elements are strictly greater than fromKey and strictly less than toKey, optionally including fromKey and toKey.
SortedSettailSet(Object fromKey)
Returns a view of the portion of this sorted set whose elements are greater than or equal to fromKey.
SortedSettailSet(Object fromKey, boolean fromInclusive)
Returns a view of the portion of this sorted set whose elements are strictly greater than fromKey, optionally including fromKey.

Constructor Detail

StoredSortedKeySet

public StoredSortedKeySet(Database database, EntryBinding keyBinding, boolean writeAllowed)
Creates a sorted key set view of a Database.

Parameters: database is the Database underlying the new collection. keyBinding is the binding used to translate between key buffers and key objects. writeAllowed is true to create a read-write collection or false to create a read-only collection.

Throws: IllegalArgumentException if formats are not consistently defined or a parameter is invalid. RuntimeExceptionWrapper if a DatabaseException is thrown.

Method Detail

comparator

public Comparator comparator()
Returns null since comparators are not supported. The natural ordering of a stored collection is data byte order, whether the data classes implement the java.lang.Comparable interface or not. This method does not conform to the SortedSet#comparator interface.

Returns: null.

first

public Object first()
Returns the first (lowest) element currently in this sorted set. This method conforms to the SortedSet#first interface.

Returns: the first element.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

headSet

public SortedSet headSet(Object toKey)
Returns a view of the portion of this sorted set whose elements are strictly less than toKey. This method conforms to the SortedSet#headSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: toKey is the upper bound.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

headSet

public SortedSet headSet(Object toKey, boolean toInclusive)
Returns a view of the portion of this sorted set whose elements are strictly less than toKey, optionally including toKey. This method does not exist in the standard SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: toKey is the upper bound. toInclusive is true to include toKey.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

last

public Object last()
Returns the last (highest) element currently in this sorted set. This method conforms to the SortedSet#last interface.

Returns: the last element.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

subSet

public SortedSet subSet(Object fromKey, Object toKey)
Returns a view of the portion of this sorted set whose elements range from fromKey, inclusive, to toKey, exclusive. This method conforms to the SortedSet#subSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: fromKey is the lower bound. toKey is the upper bound.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

subSet

public SortedSet subSet(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive)
Returns a view of the portion of this sorted set whose elements are strictly greater than fromKey and strictly less than toKey, optionally including fromKey and toKey. This method does not exist in the standard SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: fromKey is the lower bound. fromInclusive is true to include fromKey. toKey is the upper bound. toInclusive is true to include toKey.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

tailSet

public SortedSet tailSet(Object fromKey)
Returns a view of the portion of this sorted set whose elements are greater than or equal to fromKey. This method conforms to the SortedSet#tailSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: fromKey is the lower bound.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.

tailSet

public SortedSet tailSet(Object fromKey, boolean fromInclusive)
Returns a view of the portion of this sorted set whose elements are strictly greater than fromKey, optionally including fromKey. This method does not exist in the standard SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters: fromKey is the lower bound. fromInclusive is true to include fromKey.

Returns: the subset.

Throws: RuntimeExceptionWrapper if a DatabaseException is thrown.