org.garret.perst
Interface BitIndex<T extends IPersistent>

All Superinterfaces:
java.util.Collection, java.io.Externalizable, IPersistent, IResource, ITable, java.lang.Iterable, java.io.Serializable

public interface BitIndex<T extends IPersistent>
extends IPersistent, IResource, ITable<T>

Interface of bit index. Bit index allows to effiicently search object with specified set of properties. Each object has associated mask of 32 bites. Meaning of bits is application dependent. Usually each bit stands for some binary or boolean property, for example "sex", but it is possible to use group of bits to represent enumerations with more possible values.


Method Summary
 void clear()
          Remove all objects from the index
 int get(T obj)
          Get properties of specified object
 IterableIterator<T> iterator(int set, int clear)
          Get iterator for selecting objects with specified properties.
 void put(T obj, int mask)
          Put new object in the index.
 void remove(T obj)
          Remove object from the index
 int size()
          Get number of objects in the index
 
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 org.garret.perst.ITable
select
 
Methods inherited from interface java.util.Collection
add, addAll, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 

Method Detail

clear

void clear()
Remove all objects from the index

Specified by:
clear in interface java.util.Collection

get

int get(T obj)
Get properties of specified object

Parameters:
obj - object which properties are requested
Returns:
bit mask associated with this objects
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no object in the index

iterator

IterableIterator<T> iterator(int set,
                             int clear)
Get iterator for selecting objects with specified properties. To select all record this method should be invoked with (0, 0) parameters This iterator doesn't support remove() method. It is not possible to modify bit index during iteration.

Parameters:
set - bitmask specifying bits which should be set (1)
clear - bitmask specifying bits which should be cleared (0)
Returns:
selection iterator

put

void put(T obj,
         int mask)
Put new object in the index. If such objct already exists in index, then its mask will be rewritten

Parameters:
obj - object placed in the index. Object can be not yet peristent, in this case its forced to become persistent by assigning OID to it.
mask - bit mask associated with this objects

remove

void remove(T obj)
Remove object from the index

Parameters:
obj - object removed from the index
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no such key in the index

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