de.cesr.lara.components.container.storage.impl
Class LDefaultSimpleStorage<PropertyType extends LaraProperty<PropertyType,?>>

java.lang.Object
  extended by de.cesr.lara.components.container.storage.impl.LDefaultSimpleStorage<PropertyType>
Type Parameters:
PropertyType -
All Implemented Interfaces:
LaraCapacityManageableContainer<PropertyType>, LaraContainer<PropertyType>, LaraOverwriteStorage<PropertyType>, Iterable<PropertyType>

public class LDefaultSimpleStorage<PropertyType extends LaraProperty<PropertyType,?>>
extends Object
implements LaraOverwriteStorage<PropertyType>

A storage that does not care about time stamps since it only stores the most recent property for every key. This storage enables capacity management! NOTE: Other than LDefaultStorage this implementation does not throw LInvalidTimestampException()


Field Summary
static int DEFAULT_INITIAL_CAPACITY
           
 
Fields inherited from interface de.cesr.lara.components.container.LaraContainer
UNLIMITED_CAPACITY
 
Constructor Summary
LDefaultSimpleStorage()
           
LDefaultSimpleStorage(int capacity)
           
 
Method Summary
 void addStoragePropertyObserver(LaraStorageListener.StorageEvent eventType, LaraStorageListener listener)
          Adds a given LaraStorageListener for the specified LaraStorageListener.StorageEvent
 void clear()
          Clears the storage, i.e. removes all properties.
 boolean contains(Class<?> propertyType, String key)
          Checks whether the storage contains a property of the given type with the given key.
 boolean contains(PropertyType property)
          Returns true, if, and only if, this storage contains the given property.
 boolean contains(PropertyType property, String key)
          Checks whether the memory contains the given LaraProperty with the given key.
 boolean contains(String key)
          TODO test
<RequestPropertyType extends PropertyType>
RequestPropertyType
fetch(Class<RequestPropertyType> propertyType, String key)
          Generic method that returns the most recently stored property that is of the specified type and identified with key.
 PropertyType fetch(String key)
          Generic method that returns the most recently stored property that is identified with key.
<RequestPropertyType extends PropertyType>
Collection<RequestPropertyType>
fetchAll(Class<RequestPropertyType> propertyType)
          Generic method that returns a collection of all properties found.
 Set<String> getAllPropertyKeys()
          Returns a set of Strings that represent the keys of properties stored in the storage such that any property in the storage is represented.
 int getCapacity()
          Returns the capacity of this container, i.e. the number of items that can be stored or LaraContainer.UNLIMITED_CAPACITY (the default) if it is (virtually) unlimited.
 LaraCapacityManagementView<PropertyType> getCapacityManagementView()
           
 LaraCapacityManager<PropertyType> getCapacityManager()
           
protected  Collection<LaraStorageListener> getPropertyListeners(LaraStorageListener.StorageEvent event)
           
 int getSize()
          Returns the current size, i.e. the number of items currently stored.
 boolean isEmpty()
          Returns true, if and only if this container is empty.
 boolean isFull()
          Returns true, if and only if this container is full (see also LaraCapacityManager).
 Iterator<PropertyType> iterator()
          In no particular order.
protected  boolean propListenersContainsEventKey(LaraStorageListener.StorageEvent event)
           
 PropertyType remove(PropertyType propertyToRemove)
          Removes the specified property from this storage.
 PropertyType remove(String key)
          Removes the specified property from this storage.
 Collection<PropertyType> removeAll(Collection<PropertyType> propertiesToBeRemoved)
          Removes all properties in the specified collection from this storage.
 void removeStoragePropertyObserver(LaraStorageListener.StorageEvent eventType, LaraStorageListener listener)
           
 boolean setCapacity(int capacity)
           
 void setCapacityManager(LaraCapacityManager<PropertyType> manager)
           
 void store(PropertyType propertyToStore)
          Tries to add the specified property to this storage.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values
Constructor Detail

LDefaultSimpleStorage

public LDefaultSimpleStorage()

LDefaultSimpleStorage

public LDefaultSimpleStorage(int capacity)
Parameters:
capacity -
Method Detail

addStoragePropertyObserver

public void addStoragePropertyObserver(LaraStorageListener.StorageEvent eventType,
                                       LaraStorageListener listener)
Description copied from interface: LaraOverwriteStorage
Adds a given LaraStorageListener for the specified LaraStorageListener.StorageEvent

Specified by:
addStoragePropertyObserver in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
eventType - the category of storage property events the listeners shall be registered for
listener - the listener to be registered
See Also:
LaraStorage.addStoragePropertyListener(de.cesr.lara.components.container.storage.LaraStorageListener.StorageEvent, de.cesr.lara.components.container.storage.LaraStorageListener)

clear

public void clear()
Description copied from interface: LaraOverwriteStorage
Clears the storage, i.e. removes all properties.

Specified by:
clear in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>

contains

public boolean contains(Class<?> propertyType,
                        String key)
Description copied from interface: LaraOverwriteStorage
Checks whether the storage contains a property of the given type with the given key.

Specified by:
contains in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraOverwriteStorage.contains(java.lang.Class, java.lang.String)

contains

public boolean contains(PropertyType property)
Description copied from interface: LaraOverwriteStorage
Returns true, if, and only if, this storage contains the given property.

Specified by:
contains in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true, if, and only if, this storage contains the given property.
See Also:
LaraOverwriteStorage.contains(de.cesr.lara.components.LaraProperty)

contains

public boolean contains(PropertyType property,
                        String key)
Description copied from interface: LaraOverwriteStorage
Checks whether the memory contains the given LaraProperty with the given key.

Specified by:
contains in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraOverwriteStorage.contains(de.cesr.lara.components.LaraProperty, java.lang.String)

contains

public boolean contains(String key)
TODO test

Specified by:
contains in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true, if, and only if, this storage contains a property for the specified key.
See Also:
LaraStorage.contains(java.lang.String)

fetch

public <RequestPropertyType extends PropertyType> RequestPropertyType fetch(Class<RequestPropertyType> propertyType,
                                                                            String key)
                                               throws LRetrieveException
Description copied from interface: LaraOverwriteStorage
Generic method that returns the most recently stored property that is of the specified type and identified with key.

Specified by:
fetch in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
key - identifier for the property to be retrieved.
Returns:
the most recently stored property that is of the specified type and identified with key.
Throws:
LRetrieveException
See Also:
LaraOverwriteStorage.fetch(java.lang.Class, java.lang.String)

fetch

public PropertyType fetch(String key)
Description copied from interface: LaraOverwriteStorage
Generic method that returns the most recently stored property that is identified with key.

Specified by:
fetch in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
key - identifier for the property to be retrieved.
Returns:
the most recently stored property that is identified with key.

fetchAll

public <RequestPropertyType extends PropertyType> Collection<RequestPropertyType> fetchAll(Class<RequestPropertyType> propertyType)
                                                              throws LRetrieveException
Description copied from interface: LaraOverwriteStorage
Generic method that returns a collection of all properties found.

Specified by:
fetchAll in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
propertyType - identifier for the properties to be retrieved.
Returns:
the properties of the specified type that were stored in step and identified with key.
Throws:
LRetrieveException
See Also:
LaraOverwriteStorage.fetchAll(java.lang.Class)

getAllPropertyKeys

public Set<String> getAllPropertyKeys()
Description copied from interface: LaraOverwriteStorage
Returns a set of Strings that represent the keys of properties stored in the storage such that any property in the storage is represented.

Specified by:
getAllPropertyKeys in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
set of keys that represent a property stored in the storage
See Also:
LaraStorage.getAllPropertyKeys()

getCapacity

public int getCapacity()
Description copied from interface: LaraContainer
Returns the capacity of this container, i.e. the number of items that can be stored or LaraContainer.UNLIMITED_CAPACITY (the default) if it is (virtually) unlimited.

Specified by:
getCapacity in interface LaraContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
the capacity of this storage.

getCapacityManagementView

public LaraCapacityManagementView<PropertyType> getCapacityManagementView()
Specified by:
getCapacityManagementView in interface LaraCapacityManageableContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:

getCapacityManager

public LaraCapacityManager<PropertyType> getCapacityManager()
Specified by:
getCapacityManager in interface LaraCapacityManageableContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:

getSize

public int getSize()
Description copied from interface: LaraContainer
Returns the current size, i.e. the number of items currently stored.

Specified by:
getSize in interface LaraContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
the current size, i.e. the number of items currently stored.

isEmpty

public boolean isEmpty()
Description copied from interface: LaraContainer
Returns true, if and only if this container is empty.

Specified by:
isEmpty in interface LaraContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true, if and only if this container is empty.0

isFull

public boolean isFull()
Description copied from interface: LaraContainer
Returns true, if and only if this container is full (see also LaraCapacityManager).

Specified by:
isFull in interface LaraContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:
true, if and only if this container is full.

iterator

public Iterator<PropertyType> iterator()
In no particular order. TODO Throw Exception in case empty? (ME)

Specified by:
iterator in interface Iterable<PropertyType extends LaraProperty<PropertyType,?>>
See Also:
Iterable.iterator()

remove

public PropertyType remove(PropertyType propertyToRemove)
Description copied from interface: LaraOverwriteStorage
Removes the specified property from this storage.

Specified by:
remove in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
propertyToRemove - the property to be removed.
Returns:
the property that was removed

remove

public PropertyType remove(String key)
Description copied from interface: LaraOverwriteStorage
Removes the specified property from this storage.

Specified by:
remove in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
key - Key of property that shall be removed the property to be removed. Created by Michael Elbers on 22.02.2010
Returns:
the property that was removed

removeAll

public Collection<PropertyType> removeAll(Collection<PropertyType> propertiesToBeRemoved)
Description copied from interface: LaraOverwriteStorage
Removes all properties in the specified collection from this storage.

Specified by:
removeAll in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
propertiesToBeRemoved - the properties to be removed
Returns:
the properties that were removed

removeStoragePropertyObserver

public void removeStoragePropertyObserver(LaraStorageListener.StorageEvent eventType,
                                          LaraStorageListener listener)
Specified by:
removeStoragePropertyObserver in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
eventType - the category of storage property events the listeners shall be removed from
listener - the listener to be removed
See Also:
LaraStorage.removeStoragePropertyListener(de.cesr.lara.components.container.storage.LaraStorageListener.StorageEvent, de.cesr.lara.components.container.storage.LaraStorageListener)

setCapacity

public boolean setCapacity(int capacity)
Specified by:
setCapacity in interface LaraCapacityManageableContainer<PropertyType extends LaraProperty<PropertyType,?>>
Returns:

setCapacityManager

public void setCapacityManager(LaraCapacityManager<PropertyType> manager)
Specified by:
setCapacityManager in interface LaraCapacityManageableContainer<PropertyType extends LaraProperty<PropertyType,?>>

store

public void store(PropertyType propertyToStore)
Description copied from interface: LaraOverwriteStorage
Tries to add the specified property to this storage.

Specified by:
store in interface LaraOverwriteStorage<PropertyType extends LaraProperty<PropertyType,?>>
Parameters:
propertyToStore - the property to be stored.

toString

public String toString()
Overrides:
toString in class Object

getPropertyListeners

protected Collection<LaraStorageListener> getPropertyListeners(LaraStorageListener.StorageEvent event)
Parameters:
event -
Returns:

propListenersContainsEventKey

protected boolean propListenersContainsEventKey(LaraStorageListener.StorageEvent event)
Parameters:
event -
Returns: