C
- the type the boundaries used by the searchT
- the type of objects that this Search
searches forpublic abstract class AbstractSearch<C,T> extends java.lang.Object implements Search<T>, java.lang.Cloneable
comparator
that is checked on the
[from
, to
] boundaries. Specifically, all objects
that are bigger or equal to from
and smaller or equal to to
are returned, i.e.
comparator.indexCompare
(from, o) &lp= 0
and
comparator.indexCompare
(to, o) == 0
holds.
The comparator.indexCompare
method will always have
the from/to
attributes passesed as the first argument and
the object that is checked as the second argument.
Index
Modifier | Constructor and Description |
---|---|
protected |
AbstractSearch(IndexComparator<? super C,? super T> comparator,
C fromKey,
C toKey)
Creates a new instance of Search for the specified search comparator and lower and upper key bounds.
|
protected |
AbstractSearch(IndexComparator<? super C,? super T> comparator,
java.util.Collection<? extends C> keys)
Creates a new instance of Search for the specified search comparator and keys to search.
|
Modifier and Type | Method and Description |
---|---|
AbstractSearch<C,T> |
clone()
Creates and returns a copy of this search.
|
IndexComparator<? super C,? super T> |
getComparator()
Returns the comparator that this search uses on keys.
|
T |
getCurrentObject()
Returns the object found by the last search.
|
protected C |
getKey(int index)
Returns the key with specified index.
|
protected int |
getKeyCount()
Returns the number of keys that this search currently searches for.
|
protected java.lang.Object[] |
getKeys()
Returns the keys that this search currently searches for.
|
protected boolean |
checkKeys(T object)
Checks if the specified object satisfies the given keys (either boundaries
or equality).
|
protected boolean |
isKeyBounds()
Returns true if the searched keys are treated as bounds.
|
boolean |
next()
Searches for the next object (forward search) and returns false
if none is found.
|
boolean |
previous()
Searches for the previous object (backward search) and returns false
if none is found.
|
protected abstract T |
readNext()
Returns the next sibling object of the current one.
|
protected abstract T |
readPrevious()
Returns the previous sibling object of the current one.
|
boolean |
skip(int count)
Skips
count objects using Search.next() or Search.previous()
search and returns false if count objects cannot be skipped. |
protected AbstractSearch(IndexComparator<? super C,? super T> comparator, java.util.Collection<? extends C> keys)
comparator
- the comparator that is used to compare the keyskeys
- list of keys to search forprotected AbstractSearch(IndexComparator<? super C,? super T> comparator, C fromKey, C toKey)
[fromKey, toKey]
is returned.comparator
- the comparator that is used to compare the keysfromKey
- the lower bound on the searched object keys (inclusive)toKey
- the upper bound on the searched object keys (inclusive)public IndexComparator<? super C,? super T> getComparator()
protected boolean isKeyBounds()
protected int getKeyCount()
protected java.lang.Object[] getKeys()
protected C getKey(int index) throws java.lang.IndexOutOfBoundsException
getKeyCount()
.index
- the index of the key to returnjava.lang.IndexOutOfBoundsException
- if the specified index is less than zero or bigger than or equal to getKeyCount()
public T getCurrentObject()
Search
Search.next()
or Search.previous()
has returned true, this method returns the matching
object. If false has been returned, this method throws an IllegalStateException
.getCurrentObject
in interface Search<T>
public boolean next() throws java.lang.IllegalStateException
Search
Search.getCurrentObject()
.public boolean skip(int count) throws java.lang.IllegalStateException
Search
count
objects using Search.next()
or Search.previous()
search and returns false if count
objects cannot be skipped.
Otherwise, the found object can be retrieved by Search.getCurrentObject()
.
Note that this is equivalent to calling Search.next()
or Search.previous()
while true is returned up to count
times. So if the
method returns false, the Search.getCurrentObject()
may not return
a valid object.
skip
in interface Search<T>
count
- number of objects to skip,
i.e. the number of calls to Search.next()
if count is positive
or Search.previous()
if count is negativecount
objects has been skippedjava.lang.IllegalStateException
- if there was a problem retrieving the next/previous object from the underlying storagepublic boolean previous() throws java.lang.IllegalStateException
Search
Search.getCurrentObject()
.protected boolean checkKeys(T object)
object
- the object to check the boundaries forprotected abstract T readNext() throws BucketStorageException
BucketStorageException
- if there was a problem retrieving the next object from the underlying storageprotected abstract T readPrevious() throws BucketStorageException
BucketStorageException
- if there was a problem retrieving the previous object from the underlying storagepublic AbstractSearch<C,T> clone() throws java.lang.CloneNotSupportedException
Search
Search.next()
or Search.previous()
will return the same values as for the original search.
In practice, the cloned search is often used to do the search in both directions from the same starting point.