T
- the class of objects stored in this storagepublic class MemoryStorage<T> extends java.lang.Object implements IntStorageIndexed<T>, java.io.Serializable
Constructor and Description |
---|
MemoryStorage(java.lang.Class<? extends T> storedObjectsClass)
Constructs an empty memory storage.
|
MemoryStorage(java.lang.Class<? extends T> storedObjectsClass,
int initialCapacity)
Constructs an empty memory storage with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(T object)
Adds the specified object to this instance.
|
static <E> MemoryStorage<E> |
castToMemoryStorage(java.lang.Class<E> storageObjectsClass,
java.lang.Object object)
Cast the provided object to
MemoryStorage with generics typing. |
static <T> MemoryStorage<T> |
create(java.lang.Class<T> storedObjectsClass,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Creates a new memory storage.
|
void |
destroy()
Destroy this index.
|
void |
finalize()
Finalize this index.
|
java.lang.Class<? extends T> |
getStoredObjectsClass()
Returns the class of objects that the this storage works with.
|
boolean |
isEmpty()
Returns true if this storage contains no elements.
|
T |
read(int address)
Reads the object stored at the specified address in this storage.
|
void |
remove(int address)
Removes the object stored at the specified address in this storage.
|
IntStorageSearch<T> |
search()
Returns a search for all objects in this index.
|
<C> IntStorageSearch<T> |
search(IndexComparator<? super C,? super T> comparator,
C key)
Returns a search for objects in this index that have any of the specified keys.
|
<C> IntStorageSearch<T> |
search(IndexComparator<? super C,? super T> comparator,
C from,
C to)
Returns a search for objects in this index that are within the specified key-range.
|
<C> IntStorageSearch<T> |
search(IndexComparator<? super C,? super T> comparator,
java.util.Collection<? extends C> keys)
Returns a search for objects in this index that have any of the specified keys.
|
int |
size()
Returns the number of elements in this storage.
|
IntAddress<T> |
store(T object)
Stores an object in this storage.
|
java.lang.String |
toString()
Returns a string representation of this storage.
|
public MemoryStorage(java.lang.Class<? extends T> storedObjectsClass, int initialCapacity) throws java.lang.IllegalArgumentException
storedObjectsClass
- the class of objects that the storage will work withinitialCapacity
- the initial capacity of the storagejava.lang.IllegalArgumentException
- if the specified initial capacity is invalidpublic MemoryStorage(java.lang.Class<? extends T> storedObjectsClass)
storedObjectsClass
- the class of objects that the storage will work withjava.lang.IllegalArgumentException
- if the specified initial capacity is invalidpublic void finalize() throws java.lang.Throwable
ModifiableIndex
public void destroy() throws java.lang.Throwable
ModifiableIndex
public static <T> MemoryStorage<T> create(java.lang.Class<T> storedObjectsClass, java.util.Map<java.lang.String,java.lang.Object> parameters) throws java.lang.IllegalArgumentException
T
- the class of objects that the new storage will work withstoredObjectsClass
- the class of objects that the new storage will work withparameters
- list of named parameters (see above)java.lang.IllegalArgumentException
- if the parameters specified are invalid (null values, etc.)public static <E> MemoryStorage<E> castToMemoryStorage(java.lang.Class<E> storageObjectsClass, java.lang.Object object) throws java.lang.ClassCastException
MemoryStorage
with generics typing.
The objects stored in the storage must be of the same type as the storageObjectsClass
.E
- the class of objects stored in the storagestorageObjectsClass
- the class of objects stored in the storageobject
- the storage instanceMemoryStorage
objectjava.lang.ClassCastException
- if passed object
is not a MemoryStorage
or the storage objects are incompatiblepublic java.lang.Class<? extends T> getStoredObjectsClass()
public int size()
public boolean isEmpty()
public IntAddress<T> store(T object)
Storage
public T read(int address) throws BucketStorageException
IntStorage
read
in interface IntStorage<T>
address
- the address of the object to readBucketStorageException
- if there was an error reading the datapublic void remove(int address) throws BucketStorageException, java.lang.UnsupportedOperationException
IntStorage
remove
in interface IntStorage<T>
address
- the address of the object to removeBucketStorageException
- if there was an error deleting an objectjava.lang.UnsupportedOperationException
- if this storage does not support removal of objectspublic java.lang.String toString()
String.valueOf(Object)
.toString
in class java.lang.Object
public boolean add(T object) throws BucketStorageException
Addible
add
in interface Addible<T>
object
- the object to be addedBucketStorageException
- if there was an error adding the objectpublic IntStorageSearch<T> search() throws java.lang.IllegalStateException
Index
search
in interface Index<T>
search
in interface ModifiableIndex<T>
search
in interface IntStorageIndexed<T>
search
in interface StorageIndexed<T>
java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> IntStorageSearch<T> search(IndexComparator<? super C,? super T> comparator, C key) throws java.lang.IllegalStateException
Index
key
need not necessarily be of the same class as the objects stored
in this index and also consistency with equals
is not required.
Note that objects are not necessarily returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
search
in interface IntStorageIndexed<T>
search
in interface StorageIndexed<T>
C
- the type of the key used by the searchcomparator
- compares the key
with the stored objectskey
- the key to search forjava.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> IntStorageSearch<T> search(IndexComparator<? super C,? super T> comparator, java.util.Collection<? extends C> keys) throws java.lang.IllegalStateException
Index
key
need not necessarily be of the same class as the objects stored
in this index and also consistency with equals
is not required.
Note that objects are not necessarily returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
search
in interface IntStorageIndexed<T>
search
in interface StorageIndexed<T>
C
- the type of the keys used by the searchcomparator
- compares the keys
with the stored objectskeys
- the keys to search for (at least one key must be given)java.lang.IllegalStateException
- if there was an error initializing the search on this indexpublic <C> IntStorageSearch<T> search(IndexComparator<? super C,? super T> comparator, C from, C to) throws java.lang.IllegalStateException
Index
[from, to]
need not necessarily be of the same
class as the objects stored in this index, however, the comparator must be
able to compare the boundaries and the internal objects.
Note that objects are not returned in the order defined by the comparator
search
in interface Index<T>
search
in interface ModifiableIndex<T>
search
in interface IntStorageIndexed<T>
search
in interface StorageIndexed<T>
C
- the type the boundaries used by the searchcomparator
- compares the boundaries [from, to]
with the stored objectsfrom
- the lower bound on the searched objects, i.e. objects greater or equal are returnedto
- the upper bound on the searched objects, i.e. objects smaller or equal are returnedjava.lang.IllegalStateException
- if there was an error initializing the search on this index