|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.buckets.index.impl.AbstractSearch<C,T>
C
- the type the boundaries used by the searchT
- the type of objects that this Search
searches forpublic abstract class AbstractSearch<C,T>
This class represents a search on an index.
Search parameters are specified in the constructor, namely the objects
are searched using the specified 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
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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 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. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface messif.buckets.index.Search |
---|
close |
Constructor Detail |
---|
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)Method Detail |
---|
public IndexComparator<? super C,? super T> getComparator()
protected boolean isKeyBounds()
protected int getKeyCount()
protected C getKey(int index) throws java.lang.IndexOutOfBoundsException
getKeyCount()
.
index
- the index of the key to return
java.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()
.
next
in interface Search<T>
java.lang.IllegalStateException
- if there was a problem retrieving the next object from the underlying storagepublic 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 negative
count
objects has been skipped
java.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()
.
previous
in interface Search<T>
java.lang.IllegalStateException
- if there was a problem retrieving the next object from the underlying storageprotected boolean checkKeys(T object)
object
- the object to check the boundaries for
protected 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 clonned search is often used to do the search in both directions from the same starting point.
clone
in interface Search<T>
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if this search cannot be cloned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |