|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.helidb.backend.AbstractDatabaseBackend<K,V,P>
K
- The type of keys in the database.V
- The type of values in the database.P
- The type of positions in the database.public abstract class AbstractDatabaseBackend<K,V,P>
This abstract class can be used as a starting point for a
DatabaseBackend
implementation. It contains methods for handling
record move listeners.
RecordMoveListener
Constructor Summary | |
---|---|
AbstractDatabaseBackend()
|
Method Summary | |
---|---|
void |
addRecordMoveListener(RecordMoveListener<? super K,? super V,? super P> l)
Add a listener that will receive notifications whenever a database record is moved to a new position. |
protected abstract void |
assertNotClosed()
Subclasses implement this to throw an IllegalStateException if
the database backend is closed. |
P |
find(Comparable<K> key,
SearchMode mode)
This implementation iterates through all keys in the database to find the best match. |
P |
find(K key,
SearchMode mode,
Comparator<? super K> cmp)
This implementation iterates through all keys in the database to find the best match. |
int |
getContentsVersion()
Get a version number for the contents of the database backend. |
protected boolean |
hasRecordMoveListeners()
Does this database backend have any registered record move listeners? |
protected void |
notifyRecordMoveListeners(K key,
P oldPos,
P newPos)
Notify all record move listeners that a record has been relocated. |
void |
removeRecordMoveListener(RecordMoveListener<? super K,? super V,? super P> l)
Remove a record move listener. |
protected void |
updateContentsVersion()
This is used by subclasses to update the contents version whenever the database is modified. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.helidb.backend.DatabaseBackend |
---|
clear, close, compact, delete, find, forEachKey, getFirstPosition, getKeys, getLastPosition, getNextPosition, getPreviousPosition, getRecords, getValueFor, getValues, insert, insertCheckKeyUnique, insertOrUpdate, keyIterator, readKeyAt, readRecordAt, readValueAt, remove, removeAt, replaceContentsWith, update, updateAt, valueIterator, writeContentsTo |
Methods inherited from interface java.lang.Iterable |
---|
iterator |
Constructor Detail |
---|
public AbstractDatabaseBackend()
Method Detail |
---|
protected abstract void assertNotClosed() throws IllegalStateException
IllegalStateException
if
the database backend is closed.
IllegalStateException
- Thrown if the database backend is closed.public void addRecordMoveListener(RecordMoveListener<? super K,? super V,? super P> l)
DatabaseBackend
addRecordMoveListener
in interface DatabaseBackend<K,V,P>
l
- The listener.DatabaseBackend.removeRecordMoveListener(RecordMoveListener)
public void removeRecordMoveListener(RecordMoveListener<? super K,? super V,? super P> l)
DatabaseBackend
removeRecordMoveListener
in interface DatabaseBackend<K,V,P>
l
- The listener to remove.DatabaseBackend.addRecordMoveListener(RecordMoveListener)
protected void notifyRecordMoveListeners(K key, P oldPos, P newPos)
key
- The record's key.oldPos
- The old position.newPos
- The new position.protected boolean hasRecordMoveListeners()
true
if there are registered record move listeners.public int getContentsVersion() throws IllegalStateException
DatabaseBackend
The version number is used by database cursors to detect changes in the
backend (upon which they throw
ConcurrentModificationException
:s).
The version number does not have to be persisted. It does not have to be consistent between different backend objects created on the same data.
getContentsVersion
in interface DatabaseBackend<K,V,P>
IllegalStateException
- If the database backend has been closed.protected void updateContentsVersion()
public P find(Comparable<K> key, SearchMode mode)
find
in interface DatabaseBackend<K,V,P>
key
- The key to find.mode
- The search mode. The backend implementation must support the
SearchMode.EXACT_MATCH
mode (which makes this method behave
exactly like DatabaseBackend.find(Object)
). The backend may also support
SearchMode.CLOSEST_ABOVE
, SearchMode.CLOSEST_BELOW
and
SearchMode.CLOSEST_MATCH
. If not, this method should throw an
UnsupportedOperationException
when called with any of those
search modes. The backend implementation may also invent its own search
modes.
The closest match is defined as the match that gives the lowest positive
(SearchMode.CLOSEST_ABOVE
), negative (
SearchMode.CLOSEST_BELOW
) or absolute (
SearchMode.CLOSEST_MATCH
) value from the supplied key's
Comparable.compareTo(Object)
method when comparing the keys in
the database with the key to search for.
null
if no record matching the search criteria is found.DatabaseBackend.find(Object)
,
DatabaseBackend.find(Object, SearchMode, Comparator)
public P find(K key, SearchMode mode, Comparator<? super K> cmp)
find
in interface DatabaseBackend<K,V,P>
key
- The key to find.mode
- The search mode. The backend implementation must support the
SearchMode.EXACT_MATCH
mode (which makes this method behave
exactly like DatabaseBackend.find(Object)
). The backend may also support
SearchMode.CLOSEST_ABOVE
, SearchMode.CLOSEST_BELOW
and
SearchMode.CLOSEST_MATCH
. If not, this method should throw an
UnsupportedOperationException
when called with any of those
search modes. The backend implementation may also invent its own search
modes.
The closest match is defined as the match that gives the lowest positive
(SearchMode.CLOSEST_ABOVE
), negative (
SearchMode.CLOSEST_BELOW
) or absolute (
SearchMode.CLOSEST_MATCH
) value from the comparator when
comparing the keys in the database with the key to search for.
cmp
- The Comparator
used to compare keys.
null
if no record matching the search criteria is found.DatabaseBackend.find(Object)
,
DatabaseBackend.find(Comparable, SearchMode)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |