org.garret.serme
Class SortedCollection

java.lang.Object
  extended byorg.garret.serme.Persistent
      extended byorg.garret.serme.SortedCollection
All Implemented Interfaces:
ISerializable

public class SortedCollection
extends Persistent

Indexed collection providing fast access and sorting of their members. Members of the collection are sorted using provided user defined comparator. The instance of comparator class is also stored in database and provides methods for comparing collection members with each other and with key. SortedCollection is implemented using T-Tree, optimizing both speed of main operations (insert/find/remove) and space used by collection in memory.


Constructor Summary
SortedCollection()
          Default constructor internally used by SerMe
SortedCollection(IComparator comparator, boolean unique)
          Constructor of sorted collection
 
Method Summary
 boolean add(java.lang.Object obj)
          Add new member to collection
 void clear()
          Remove all objects from the collection
 boolean contains(java.lang.Object member)
          Check if collections contains specified member
 java.util.Enumeration elements()
          Get enumeration for all collection members.
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object[] get(java.lang.Object from, java.lang.Object till)
           
 IComparator getComparator()
          Get comparator used in this collection
 int getCounter()
          This method is used internally by SerMe to detect concurrent modifications
 void readObject(IInputStream in)
          Unpack object
 void remove(java.lang.Object obj)
          Remove member from collection
 int size()
          Get number of objects in the collection
 java.lang.Object[] toArray()
          Get all objects in the index as array ordered by index key.
 java.lang.Object[] toArray(java.lang.Object[] arr)
          Get all objects in the index as array ordered by index key.
 void writeObject(IOutputStream out)
          Pack object
 
Methods inherited from class org.garret.serme.Persistent
getStorage, remove, setStorage, store
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedCollection

public SortedCollection()
Default constructor internally used by SerMe


SortedCollection

public SortedCollection(IComparator comparator,
                        boolean unique)
Constructor of sorted collection

Parameters:
comparator - class used to compare collection members with each other and with key
unique - if key should be unique in collection
Method Detail

add

public boolean add(java.lang.Object obj)
Add new member to collection

Parameters:
obj - new member
Returns:
true if object is successfully added in the index, false if collection was declared as unique and there is already member with such value of the key in the collection.

clear

public void clear()
Remove all objects from the collection


contains

public boolean contains(java.lang.Object member)
Check if collections contains specified member

Returns:
true if specified member belongs to the collection

elements

public java.util.Enumeration elements()
Get enumeration for all collection members. Enumertion will be perfromed in order specified by comparator. It is not possible to modify collection duting enumeration - if such concurrent modification will be detected, then SermeException("Concurrent modification") exception will be thrown.

Returns:
enumeration for collection elements

get

public java.lang.Object get(java.lang.Object key)

get

public java.lang.Object[] get(java.lang.Object from,
                              java.lang.Object till)

getComparator

public IComparator getComparator()
Get comparator used in this collection

Returns:
collection comparator

getCounter

public int getCounter()
This method is used internally by SerMe to detect concurrent modifications


readObject

public void readObject(IInputStream in)
Unpack object

Parameters:
in - input stream

remove

public void remove(java.lang.Object obj)
Remove member from collection

Parameters:
obj - member to be removed
Throws:
StorageError(StorageError.KEY_NOT_FOUND) - exception if there is no such key in the collection

size

public int size()
Get number of objects in the collection

Returns:
number of objects in the collection

toArray

public java.lang.Object[] toArray()
Get all objects in the index as array ordered by index key.

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

toArray

public java.lang.Object[] toArray(java.lang.Object[] arr)
Get all objects in the index as array ordered by index key. Object are placed in specified array. If number of colelction members is greater than array size, then only first N of them will be stored, where N is length of array.
If this index fits in the specified array with room to spare (i.e., the array has more elements than this index), the element in the array immediately following the end of the index is set to null. This is useful in determining the length of this index only if the caller knows that this index does not contain any null elements.)

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

writeObject

public void writeObject(IOutputStream out)
Pack object

Parameters:
out - output stream