org.garret.perst
Interface GenericIndex<T>

All Superinterfaces:
java.util.Collection, java.io.Externalizable, IPersistent, IResource, java.lang.Iterable, java.io.Serializable
All Known Subinterfaces:
FieldIndex, Index

public interface GenericIndex<T>
extends IPersistent, IResource, java.util.Collection<T>

Interface of object index. This is base interface for Index and FieldIndex, allowing to write generic algorithms working with both itype of indices.


Field Summary
static int ASCENT_ORDER
           
static int DESCENT_ORDER
           
 
Method Summary
 void clear()
          Remove all objects from the index
 IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator()
          Get iterator for traversing all entries in the index.
 IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator(Key from, Key till, int order)
          Get iterator for traversing index entries with key belonging to the specified range.
 IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator(java.lang.Object from, java.lang.Object till, int order)
          Get iterator for traversing index entries with key belonging to the specified range.
 T get(Key key)
          Get object by key (exact match)
 IPersistent[] get(Key from, Key till)
          Get objects which key value belongs to the specified range.
 T get(java.lang.Object key)
          Get object by string key (exact match)
 IPersistent[] get(java.lang.Object from, java.lang.Object till)
          Get objects which key value belongs to the specified range.
 java.lang.Class getKeyType()
          Get type of index key
 java.lang.Class[] getKeyTypes()
          Get types of index compound key components
 java.util.ArrayList<T> getList(Key from, Key till)
          Get objects which key value belongs to the specified range.
 java.util.ArrayList<T> getList(java.lang.Object from, java.lang.Object till)
          Get objects which key value belongs to the specified range.
 IPersistent[] getPrefix(java.lang.String prefix)
          Get objects with objects with key started with specified prefix, i.e. getPrefix("abc") will return "abc", "abcd", "abcdef", ... but not "ab".
 java.util.ArrayList<T> getPrefixList(java.lang.String prefix)
          Get objects with string key prefix
 java.util.Iterator<T> iterator()
          Get iterator for traversing all objects in the index.
 IterableIterator<T> iterator(Key from, Key till, int order)
          Get iterator for traversing objects in the index with key belonging to the specified range.
 IterableIterator<T> iterator(java.lang.Object from, java.lang.Object till, int order)
          Get iterator for traversing objects in the index with key belonging to the specified range.
 IterableIterator<T> prefixIterator(java.lang.String prefix)
          Get iterator for records which keys started with specified prefix Objects are iterated in the ascent key order.
 IPersistent[] prefixSearch(java.lang.String word)
          Locate all objects which key is prefix of specified word, i.e. prefixSearch("12345") will return "12", "123", "1234", "12345", but not "123456"
 java.util.ArrayList<T> prefixSearchList(java.lang.String word)
          Locate all objects which key is prefix of specified word.
 int size()
          Get number of objects in the index
 IPersistent[] toPersistentArray()
          Get all objects in the index as array ordered by index key.
 
Methods inherited from interface org.garret.perst.IPersistent
assignOid, deallocate, getOid, getStorage, invalidate, isDeleted, isModified, isPersistent, isRaw, load, loadAndModify, makePersistent, modify, onLoad, onStore, recursiveLoading, store
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface org.garret.perst.IResource
exclusiveLock, exclusiveLock, reset, sharedLock, sharedLock, unlock
 
Methods inherited from interface java.util.Collection
add, addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

ASCENT_ORDER

static final int ASCENT_ORDER
See Also:
Constant Field Values

DESCENT_ORDER

static final int DESCENT_ORDER
See Also:
Constant Field Values
Method Detail

clear

void clear()
Remove all objects from the index

Specified by:
clear in interface java.util.Collection

entryIterator

IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator()
Get iterator for traversing all entries in the index. Iterator next() method returns object implementing Map.Entry interface which allows to get entry key and value. Objects are iterated in the ascent key order. You should not update/remove or add members to the index during iteration This iterator doesn't support remove method. If you want to update/remove records during traversal, please use range iterator.

Returns:
index iterator

entryIterator

IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator(Key from,
                                                                        Key till,
                                                                        int order)
Get iterator for traversing index entries with key belonging to the specified range. Iterator next() method returns object implementing Map.Entry interface This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

entryIterator

IterableIterator<java.util.Map.Entry<java.lang.Object,T>> entryIterator(java.lang.Object from,
                                                                        java.lang.Object till,
                                                                        int order)
Get iterator for traversing index entries with key belonging to the specified range. Iterator next() method returns object implementing Map.Entry interface This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - inclusive low boundary. If null then low boundary is not specified.
till - inclusive high boundary. If null then high boundary is not specified.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

get

T get(Key key)
Get object by key (exact match)

Parameters:
key - specified key. It should match with type of the index and should be inclusive.
Returns:
object with this value of the key or null if key not found
Throws:
StorageError(StorageError.KEY_NOT_UNIQUE) - exception if there are more than one objects in the index with specified value of the key.

get

IPersistent[] get(Key from,
                  Key till)
Get objects which key value belongs to the specified range. Either from boundary, either till boundary either both of them can be null. In last case the method returns all objects from the index.

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
Returns:
array of objects which keys belongs to the specified interval, ordered by key value

get

T get(java.lang.Object key)
Get object by string key (exact match)

Parameters:
key - packed key
Returns:
object with this value of the key or null if key not[ found
Throws:
StorageError(StorageError.KEY_NOT_UNIQUE) - exception if there are more than one objects in the index with specified value of the key.

get

IPersistent[] get(java.lang.Object from,
                  java.lang.Object till)
Get objects which key value belongs to the specified range. Either from boundary, either till boundary either both of them can be null. In last case the method returns all objects from the index.

Parameters:
from - inclusive low boundary. If null then low boundary is not specified.
till - inclusive high boundary. If null then high boundary is not specified.
Returns:
array of objects which keys belongs to the specified interval, ordered by key value

getKeyType

java.lang.Class getKeyType()
Get type of index key

Returns:
type of index key

getKeyTypes

java.lang.Class[] getKeyTypes()
Get types of index compound key components

Returns:
array of types of compound key components

getList

java.util.ArrayList<T> getList(Key from,
                               Key till)
Get objects which key value belongs to the specified range. Either from boundary, either till boundary either both of them can be null. In last case the method returns all objects from the index.

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
Returns:
array of objects which keys belongs to the specified interval, ordered by key value

getList

java.util.ArrayList<T> getList(java.lang.Object from,
                               java.lang.Object till)
Get objects which key value belongs to the specified range. Either from boundary, either till boundary either both of them can be null. In last case the method returns all objects from the index.

Parameters:
from - inclusive low boundary. If null then low boundary is not specified.
till - inclusive high boundary. If null then high boundary is not specified.
Returns:
array of objects which keys belongs to the specified interval, ordered by key value

getPrefix

IPersistent[] getPrefix(java.lang.String prefix)
Get objects with objects with key started with specified prefix, i.e. getPrefix("abc") will return "abc", "abcd", "abcdef", ... but not "ab".

Parameters:
prefix - string key prefix
Returns:
array of objects which key starts with this prefix

getPrefixList

java.util.ArrayList<T> getPrefixList(java.lang.String prefix)
Get objects with string key prefix

Parameters:
prefix - string key prefix
Returns:
list of objects which key starts with this prefix

iterator

java.util.Iterator<T> iterator()
Get iterator for traversing all objects in the index. Objects are iterated in the ascent key order. You should not update/remove or add members to the index during iteration This iterator doesn't support remove method. If you want to update/remove records during traversal, please use range iterator.

Specified by:
iterator in interface java.util.Collection
Returns:
index iterator

iterator

IterableIterator<T> iterator(Key from,
                             Key till,
                             int order)
Get iterator for traversing objects in the index with key belonging to the specified range. This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - high boundary. If null then high boundary is not specified. High boundary can be inclusive or exclusive.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

iterator

IterableIterator<T> iterator(java.lang.Object from,
                             java.lang.Object till,
                             int order)
Get iterator for traversing objects in the index with key belonging to the specified range. This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
from - inclusive low boundary. If null then low boundary is not specified. Low boundary can be inclusive or exclusive.
till - inclusive high boundary. If null then high boundary is not specified.
order - ASCENT_ORDER or DESCENT_ORDER
Returns:
selection iterator

prefixIterator

IterableIterator<T> prefixIterator(java.lang.String prefix)
Get iterator for records which keys started with specified prefix Objects are iterated in the ascent key order. This iterator supports remove() method. To make it possible to update, remove or add members to the index during iteration it is necessary to set "perst.concurrent.iterator" property (by default it is not supported because it cause extra overhead during iteration)

Parameters:
prefix - key prefix
Returns:
selection iterator

prefixSearch

IPersistent[] prefixSearch(java.lang.String word)
Locate all objects which key is prefix of specified word, i.e. prefixSearch("12345") will return "12", "123", "1234", "12345", but not "123456"

Parameters:
word - string which prefixes are located in index
Returns:
array of objects which key is prefix of specified word, ordered by key value

prefixSearchList

java.util.ArrayList<T> prefixSearchList(java.lang.String word)
Locate all objects which key is prefix of specified word.

Parameters:
word - string which prefixes are located in index
Returns:
list of objects which key is prefix of specified word, ordered by key value

size

int size()
Get number of objects in the index

Specified by:
size in interface java.util.Collection
Returns:
number of objects in the index

toPersistentArray

IPersistent[] toPersistentArray()
Get all objects in the index as array ordered by index key.

Returns:
array of objects in the index ordered by key value