de.cesr.lara.components.environment.impl
Class LEnvironment

java.lang.Object
  extended by de.cesr.lara.components.environment.impl.LEnvironment
All Implemented Interfaces:
LaraEnvironment, LaraSuperEnvironment
Direct Known Subclasses:
Environment, MyEnvironment

public class LEnvironment
extends Object
implements LaraSuperEnvironment

This default implementation of LaraSuperEnvironment does not delegate to sub-environments for containsProperty(String), removeProperty(LAbstractEnvironmentalProperty), etc. TODO integrate LaraStorage TODO implement getters for filter properties TODO parameterise LaraEnvironment TODO add property functions that deal with sub-envs (like removePopertySubenv) TODO Test sub-environments


Field Summary
protected  Map<String,LAbstractEnvironmentalProperty<?>> abstractProperties
           
protected  Set<LaraEnvironmentListener> allObserver
          Contains listeners that observe all properties of this environment.
protected  Map<String,Set<LaraEnvironmentListener>> propertyObserver
          Contains listeners that observe certain properties.
protected   subEnvironments
          Container for sub-environments
 
Fields inherited from interface de.cesr.lara.components.environment.LaraSuperEnvironment
ALL_CATEGORIES
 
Constructor Summary
LEnvironment()
          constructor
 
Method Summary
 void addEnvListener(LaraEnvironmentListener listener)
          Adds an LaraEnvironmentListener to the entire LaraEnvironment.
 void addEnvListener(LaraEnvironmentListener listener, String name)
          Registers a LaraEnvironmentListener at this environment to observe only a certain property.
 void addProperty(LAbstractEnvironmentalProperty<?> property)
          Calls update.
 boolean containsProperty(LAbstractEnvironmentalProperty<?> property)
          Checks whether a property is in the list or not.
 boolean containsProperty(String name)
          Checks whether a property name is in the environment or not.
 Set<LaraEnvironmentListener> getAllListeners()
          Returns a set of all listeners - those that are registered at all properties and those registered at certain properties.
 Collection<LAbstractEnvironmentalProperty<?>> getEnvProperties()
          Returns a shallow copy of all LAbstractEnvironmentalPropertys registered at this environment.
 LAbstractEnvironmentalProperty<?> getPropertyByName(String name)
           
 Set<LaraEnvironment> getSubEnvironments()
          Returns a shallow copy of all registered sub-environments.
 Set<LaraEnvironment> getSubEnvironments(Object category)
          Returns all registered sub-environments of the given category.
<V> LAbstractEnvironmentalProperty<V>
getTypedPropertyByName(String name)
           
protected  void inform(LAbstractEnvironmentalProperty<?> property)
          Informs all listeners that are either registered for the all properties or the specifically for the given one.
 void registerEnvironment(Object cat, LaraEnvironment environment)
          Registers a new LaraEnvironment at this super environment.
 void removeEnvironment(LaraEnvironment environment)
          Removes a LaraEnvironment from this super environment.
 void removeEnvironment(Object cat)
          Removes all LaraEnvironment from this super environment that belong to the given category.
 boolean removeEnvListener(LaraEnvironmentListener listener)
          Remove a LaraEnvironmentListener from the entire LaraEnvironment.
 void removeEnvListener(LaraEnvironmentListener listener, String name)
          Removes a LaraEnvironmentListener at this environment from the given property.
 boolean removeProperty(LAbstractEnvironmentalProperty<?> property)
          Removes a property if it is contained in the environment's list.
 boolean removeProperty(String name)
          Removes a property if it is contained in the environment's list.
 boolean removePropertySubenv(Object category, String name)
          Removes properties with the given name also in sub-environments of the given category.
 String toString()
           
 void updateProperty(LAbstractEnvironmentalProperty<?> property)
          Informs listeners every time a value changed (should listeners be informed of an update even if the value has not changed implement a new registration function addEnvUpdateListeners()!)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

abstractProperties

protected Map<String,LAbstractEnvironmentalProperty<?>> abstractProperties

allObserver

protected Set<LaraEnvironmentListener> allObserver
Contains listeners that observe all properties of this environment.


propertyObserver

protected Map<String,Set<LaraEnvironmentListener>> propertyObserver
Contains listeners that observe certain properties.


subEnvironments

protected  subEnvironments
Container for sub-environments

Constructor Detail

LEnvironment

public LEnvironment()
constructor

Method Detail

addEnvListener

public void addEnvListener(LaraEnvironmentListener listener)
Description copied from interface: LaraEnvironment
Adds an LaraEnvironmentListener to the entire LaraEnvironment.

Specified by:
addEnvListener in interface LaraEnvironment
Parameters:
listener - listener to add.
See Also:
LaraEnvironment.addEnvListener(de.cesr.lara.components.environment.LaraEnvironmentListener)

addEnvListener

public void addEnvListener(LaraEnvironmentListener listener,
                           String name)
Description copied from interface: LaraEnvironment
Registers a LaraEnvironmentListener at this environment to observe only a certain property.

Specified by:
addEnvListener in interface LaraEnvironment
Parameters:
listener - the observer to register
name - name of property to observe
See Also:
LaraEnvironment.addEnvListener(de.cesr.lara.components.environment.LaraEnvironmentListener, java.lang.String)

addProperty

public void addProperty(LAbstractEnvironmentalProperty<?> property)
Calls update.

Specified by:
addProperty in interface LaraEnvironment
Parameters:
property - property to add
See Also:
LaraEnvironment.addProperty(de.cesr.lara.components.environment.impl.LAbstractEnvironmentalProperty)

containsProperty

public boolean containsProperty(LAbstractEnvironmentalProperty<?> property)
Description copied from interface: LaraEnvironment
Checks whether a property is in the list or not.

Specified by:
containsProperty in interface LaraEnvironment
Parameters:
property - property to check
Returns:
true if the property is within the list, false otherwise
See Also:
LaraEnvironment.containsProperty(de.cesr.lara.components.environment.impl.LAbstractEnvironmentalProperty)

containsProperty

public boolean containsProperty(String name)
Description copied from interface: LaraEnvironment
Checks whether a property name is in the environment or not.

Specified by:
containsProperty in interface LaraEnvironment
Parameters:
name - name of property to check
Returns:
true if the name is within the list, false otherwise
See Also:
LaraEnvironment.containsProperty(java.lang.String)

getAllListeners

public Set<LaraEnvironmentListener> getAllListeners()
Description copied from interface: LaraEnvironment
Returns a set of all listeners - those that are registered at all properties and those registered at certain properties.

Specified by:
getAllListeners in interface LaraEnvironment
Returns:
listeners set of all listeners
See Also:
LaraEnvironment.getAllListeners()

getEnvProperties

public Collection<LAbstractEnvironmentalProperty<?>> getEnvProperties()
Returns a shallow copy of all LAbstractEnvironmentalPropertys registered at this environment.

Specified by:
getEnvProperties in interface LaraEnvironment
Returns:
envProperties all LAbstractEnvironmentalPropertys stored by this LaraEnvironment
See Also:
LaraEnvironment.getEnvProperties()

getPropertyByName

public LAbstractEnvironmentalProperty<?> getPropertyByName(String name)
Specified by:
getPropertyByName in interface LaraEnvironment
Parameters:
name - the LAbstractEnvironmentalProperty's name
Returns:
property of environment
See Also:
LaraEnvironment.getPropertyByName(java.lang.String)

getSubEnvironments

public Set<LaraEnvironment> getSubEnvironments()
Returns a shallow copy of all registered sub-environments.

Specified by:
getSubEnvironments in interface LaraSuperEnvironment
Returns:
all sub-environments
See Also:
LaraSuperEnvironment.getSubEnvironments()

getSubEnvironments

public Set<LaraEnvironment> getSubEnvironments(Object category)
Description copied from interface: LaraSuperEnvironment
Returns all registered sub-environments of the given category.

Specified by:
getSubEnvironments in interface LaraSuperEnvironment
Returns:
all sub-environments
See Also:
LaraSuperEnvironment.getSubEnvironments(java.lang.Object)

getTypedPropertyByName

public <V> LAbstractEnvironmentalProperty<V> getTypedPropertyByName(String name)
Specified by:
getTypedPropertyByName in interface LaraEnvironment
Type Parameters:
V - type of requested property
Parameters:
name - the LAbstractEnvironmentalProperty's name
Returns:
property of environment
See Also:
LaraEnvironment.getTypedPropertyByName(java.lang.String)

registerEnvironment

public void registerEnvironment(Object cat,
                                LaraEnvironment environment)
Description copied from interface: LaraSuperEnvironment
Registers a new LaraEnvironment at this super environment. The category object allows the modeler to define categories of environment and to look up environments by this category. For instance, there are agent classes that are embedded in environments that are specialised but belong to a certain category. The category may be used for methods across agent classes. Furthermore, several environments may be grouped by category. Examples for categories are social and bio-physical environments.

Specified by:
registerEnvironment in interface LaraSuperEnvironment
Parameters:
cat - category object to identify the (type of) environment. Null is allowed.
environment - environment to register
See Also:
LaraSuperEnvironment.registerEnvironment(Object, de.cesr.lara.components.environment.LaraEnvironment)

removeEnvironment

public void removeEnvironment(LaraEnvironment environment)
Description copied from interface: LaraSuperEnvironment
Removes a LaraEnvironment from this super environment.

Specified by:
removeEnvironment in interface LaraSuperEnvironment
Parameters:
environment - environment to remove
See Also:
LaraSuperEnvironment.removeEnvironment(de.cesr.lara.components.environment.LaraEnvironment)

removeEnvironment

public void removeEnvironment(Object cat)
Description copied from interface: LaraSuperEnvironment
Removes all LaraEnvironment from this super environment that belong to the given category.

Specified by:
removeEnvironment in interface LaraSuperEnvironment
Parameters:
cat - category object to identify the (type of) environment
See Also:
LaraSuperEnvironment.removeEnvironment(Object)

removeEnvListener

public boolean removeEnvListener(LaraEnvironmentListener listener)
Description copied from interface: LaraEnvironment
Remove a LaraEnvironmentListener from the entire LaraEnvironment. This does not impact listeners that are registered at certain properties!

Specified by:
removeEnvListener in interface LaraEnvironment
Parameters:
listener - listener to remove.
Returns:
boolean true if the listener was contained and could be removed
See Also:
LaraEnvironment.removeEnvListener(de.cesr.lara.components.environment.LaraEnvironmentListener)

removeEnvListener

public void removeEnvListener(LaraEnvironmentListener listener,
                              String name)
Description copied from interface: LaraEnvironment
Removes a LaraEnvironmentListener at this environment from the given property. This does not impact possibly same listeners that are registered at the whole Environment.

Specified by:
removeEnvListener in interface LaraEnvironment
Parameters:
listener - the observer to register
name - name of observed property
See Also:
LaraEnvironment.removeEnvListener(de.cesr.lara.components.environment.LaraEnvironmentListener, java.lang.String)

removeProperty

public boolean removeProperty(LAbstractEnvironmentalProperty<?> property)
Description copied from interface: LaraEnvironment
Removes a property if it is contained in the environment's list.

Specified by:
removeProperty in interface LaraEnvironment
Parameters:
property - property to remove
Returns:
true if the property was in the list and could be removed
See Also:
LaraEnvironment.removeProperty(de.cesr.lara.components.environment.impl.LAbstractEnvironmentalProperty)

removeProperty

public boolean removeProperty(String name)
Description copied from interface: LaraEnvironment
Removes a property if it is contained in the environment's list.

Specified by:
removeProperty in interface LaraEnvironment
Parameters:
name - name of property to remove
Returns:
true if the property was in the list and could be removed
See Also:
LaraEnvironment.removeProperty(java.lang.String)

removePropertySubenv

public boolean removePropertySubenv(Object category,
                                    String name)
Description copied from interface: LaraSuperEnvironment
Removes properties with the given name also in sub-environments of the given category. ALL_CATEGORIES removes it in all categories. Null is allowed as category.

Specified by:
removePropertySubenv in interface LaraSuperEnvironment
name - of the properties to remove
Returns:
true if any property was removed
See Also:
de.cesr.lara.components.environment.LaraSuperEnvironment#removePropertySubenv(java.lang.String)

toString

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

updateProperty

public void updateProperty(LAbstractEnvironmentalProperty<?> property)
Informs listeners every time a value changed (should listeners be informed of an update even if the value has not changed implement a new registration function addEnvUpdateListeners()!)

Specified by:
updateProperty in interface LaraEnvironment
Parameters:
property - property to update or add
See Also:
LaraEnvironment.updateProperty(de.cesr.lara.components.environment.impl.LAbstractEnvironmentalProperty)

inform

protected void inform(LAbstractEnvironmentalProperty<?> property)
Informs all listeners that are either registered for the all properties or the specifically for the given one.

Parameters:
property - new property