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

java.lang.Object
  extended by de.cesr.lara.components.container.storage.impl.LDefaultStorage<PropertyType>
Type Parameters:
PropertyType -
All Implemented Interfaces:
LaraContainer<PropertyType>, LaraStorage<PropertyType>, Iterable<PropertyType>
Direct Known Subclasses:
LDefaultLimitedCapacityStorage

public class LDefaultStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
extends Object
implements LaraStorage<PropertyType>

TODO implement observer management for other events than AUTO_REMOVED! (SH) Updates a key-wise (Key -> Step -> Property) and a step-wise (Step -> Key -> Property) map.


Field Summary
 
Fields inherited from interface de.cesr.lara.components.container.LaraContainer
UNLIMITED_CAPACITY
 
Constructor Summary
LDefaultStorage()
           
 
Method Summary
 void addStoragePropertyListener(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)
          NOTE: This method is highly inefficient in this implementation!
 boolean contains(PropertyType property, String key)
          Checks whether the memory contains the given LaraProperty with the given key.
 boolean contains(String key)
          Returns true, if, and only if, this storage contains a property for the specified key.
 boolean contains(String key, int step)
          Returns true, if, and only if, this storage contains a property for the specified key and step.
<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.
<RequestPropertyType extends PropertyType>
RequestPropertyType
fetch(Class<RequestPropertyType> propertyType, String key, int step)
          Generic method that returns the first property that is of the specified type, was stored in step and identified with key.
 PropertyType fetch(String key)
          Generic method that returns the most recently stored property that is identified with key.
 PropertyType fetch(String key, int step)
          Generic method that returns the first property that was stored in step and identified with key.
 Collection<PropertyType> fetchAll()
          Generic method that returns a collection of all properties found.
<RequestPropertyType extends PropertyType>
Collection<RequestPropertyType>
fetchAll(Class<RequestPropertyType> propertyType)
          Generic method that returns a collection of all properties found.
<RequestPropertyType extends PropertyType>
Collection<RequestPropertyType>
fetchAll(Class<RequestPropertyType> propertyType, String key)
          Generic method that returns a collection of all properties found that are of the specified type and are identified by key.
 Collection<PropertyType> fetchAll(String key)
          Generic method that returns a collection of all properties found that are identified by key.
 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.
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()
          Provides an iterator over all properties 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, int step)
          Removes the property with the specified key that was stored in step from this storage.
 Collection<PropertyType> removeAll(Collection<PropertyType> propertiesToBeRemoved)
          Removes all properties in the specified collection from this storage.
 Collection<PropertyType> removeAll(String key)
          Removes all properties that are identified by the specified key.
 void removeStoragePropertyListener(LaraStorageListener.StorageEvent eventType, LaraStorageListener listener)
           
 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
 

Constructor Detail

LDefaultStorage

public LDefaultStorage()
Method Detail

addStoragePropertyListener

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

Specified by:
addStoragePropertyListener in interface LaraStorage<PropertyType extends LaraProperty<? extends 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: LaraStorage
Clears the storage, i.e. removes all properties.

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

contains

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

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

contains

public boolean contains(PropertyType property)
NOTE: This method is highly inefficient in this implementation!

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

contains

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

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

contains

public boolean contains(String key)
Description copied from interface: LaraStorage
Returns true, if, and only if, this storage contains a property for the specified key.

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

contains

public boolean contains(String key,
                        int step)
Description copied from interface: LaraStorage
Returns true, if, and only if, this storage contains a property for the specified key and step.

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

fetch

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

Specified by:
fetch in interface LaraStorage<PropertyType extends LaraProperty<? extends 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:
LaraStorage.fetch(java.lang.Class, java.lang.String)

fetch

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

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

fetch

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

Specified by:
fetch in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be retrieved.
Returns:
the most recently stored property that is identified with key.
See Also:
LaraStorage.fetch(java.lang.String)

fetch

public PropertyType fetch(String key,
                          int step)
Description copied from interface: LaraStorage
Generic method that returns the first property that was stored in step and identified with key.

Specified by:
fetch in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be retrieved.
step - step in which the property was stored.
Returns:
the first property that was stored in step and identified with key.
See Also:
LaraStorage.fetch(java.lang.String, int)

fetchAll

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

Specified by:
fetchAll in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
all properties.
Throws:
LRetrieveException
See Also:
LaraStorage.fetchAll()

fetchAll

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

Specified by:
fetchAll in interface LaraStorage<PropertyType extends LaraProperty<? extends 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:
LaraStorage.fetchAll(java.lang.Class)

fetchAll

public <RequestPropertyType extends PropertyType> Collection<RequestPropertyType> fetchAll(Class<RequestPropertyType> propertyType,
                                                                                           String key)
                                                              throws LRetrieveException
Description copied from interface: LaraStorage
Generic method that returns a collection of all properties found that are of the specified type and are identified by key.

Specified by:
fetchAll in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
key - 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:
LaraStorage.fetchAll(java.lang.Class, java.lang.String)

fetchAll

public Collection<PropertyType> fetchAll(String key)
Description copied from interface: LaraStorage
Generic method that returns a collection of all properties found that are identified by key.

Specified by:
fetchAll in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the properties to be retrieved.
Returns:
the properties of the specified type that are identified with key.
See Also:
LaraStorage.fetchAll(java.lang.String)

getAllPropertyKeys

public Set<String> getAllPropertyKeys()
Description copied from interface: LaraStorage
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 LaraStorage<PropertyType extends LaraProperty<? extends 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<? extends PropertyType,?>>
Returns:
the capacity of this storage.
See Also:
LaraContainer.getCapacity()

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<? extends PropertyType,?>>
Returns:
the current size, i.e. the number of items currently stored.
See Also:
LaraContainer.getSize()

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<? extends PropertyType,?>>
Returns:
true, if and only if this container is empty.0
See Also:
LaraContainer.isEmpty()

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<? extends PropertyType,?>>
Returns:
true, if and only if this container is full.
See Also:
LaraContainer.isFull()

iterator

public Iterator<PropertyType> iterator()
Provides an iterator over all properties in no particular order.

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

remove

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

Specified by:
remove in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToRemove - the property to be removed.
Returns:
the property that was removed
See Also:
LaraStorage.remove(de.cesr.lara.components.LaraProperty)

remove

public PropertyType remove(String key,
                           int step)
Description copied from interface: LaraStorage
Removes the property with the specified key that was stored in step from this storage.

Specified by:
remove in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be removed.
step - the step in which the property to be removed was stored.
Returns:
the property that was removed
See Also:
LaraStorage.remove(java.lang.String, int)

removeAll

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

Specified by:
removeAll in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertiesToBeRemoved - the properties to be removed
Returns:
the properties that were removed
See Also:
LaraStorage.removeAll(java.util.Collection)

removeAll

public Collection<PropertyType> removeAll(String key)
Description copied from interface: LaraStorage
Removes all properties that are identified by the specified key.

Specified by:
removeAll in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - key identifier for the properties to be removed.
Returns:
the properties that were removed
See Also:
LaraStorage.removeAll(java.lang.String)

removeStoragePropertyListener

public void removeStoragePropertyListener(LaraStorageListener.StorageEvent eventType,
                                          LaraStorageListener listener)
Specified by:
removeStoragePropertyListener in interface LaraStorage<PropertyType extends LaraProperty<? extends 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)

store

public void store(PropertyType propertyToStore)
Description copied from interface: LaraStorage
Tries to add the specified property to this storage. In case the storage already contains a property of the same key for the same time-stamp the "old" property is overwritten.

Specified by:
store in interface LaraStorage<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToStore - the property to be stored.
See Also:
LaraStorage.store(de.cesr.lara.components.LaraProperty)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

getPropertyListeners

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

propListenersContainsEventKey

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