ikrs.util
Class EnvironmentDelegation<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by ikrs.util.MapDelegation<K,V>
          extended by ikrs.util.EnvironmentDelegation<K,V>
All Implemented Interfaces:
Environment<K,V>, java.util.Map<K,V>
Direct Known Subclasses:
AbstractSession

public class EnvironmentDelegation<K,V>
extends MapDelegation<K,V>
implements Environment<K,V>

The EnvironmentDelegation class is a wrapper for anonymous environments. The passed environment will become the underlying core and method calls to the delegation's environment-methods will be directly forwarded to the core.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
EnvironmentDelegation(Environment<K,V> core)
          Creates a new EnvironmentDelegation with the given core environment.
 
Method Summary
 boolean allowsMultipleChildNames()
          This method indicates if the environment allows multiple names for child environments.
 Environment<K,V> createChild(java.lang.String name)
          This method creates a new child environment and returns it.
 java.util.List<Environment<K,V>> getAllChildren()
          This method simply returns a list containing _all_ children.
 Environment<K,V> getChild(java.lang.String name)
          Get the child environment with the given name; there might be different children with the same name! The method will return the first match then.
 int getChildCount()
          This method returns the number of all children.
 java.util.List<Environment<K,V>> getChildren(java.lang.String name)
          Get *all* children with the given name.
 Environment<K,V> getParent()
          Get the environments parent.
 Environment<K,V> locateChild(Path<java.lang.String> path)
          Locate a child in the environment tree structure.
 void removeAllChildren()
          This method simply removes all children from this environment.
 Environment<K,V> removeChild(java.lang.String name)
          This method removes the child with the given name and returns its old value.
 
Methods inherited from class ikrs.util.MapDelegation
clear, entrySet, put, putAll, remove, toString
 
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

EnvironmentDelegation

public EnvironmentDelegation(Environment<K,V> core)
                      throws java.lang.NullPointerException
Creates a new EnvironmentDelegation with the given core environment.

Parameters:
core - The core environment (must not be null).
Throws:
java.lang.NullPointerException - if core is null.
Method Detail

allowsMultipleChildNames

public boolean allowsMultipleChildNames()
This method indicates if the environment allows multiple names for child environments. If this method returns false the method createChild MUST NOT create a new child if there already exists a child with that name.

Specified by:
allowsMultipleChildNames in interface Environment<K,V>

getParent

public Environment<K,V> getParent()
Get the environments parent. If there is no parent the method will return null. Only the root environment has not parent. *

Specified by:
getParent in interface Environment<K,V>

getChild

public Environment<K,V> getChild(java.lang.String name)
Get the child environment with the given name; there might be different children with the same name! The method will return the first match then. If no such child exists the method returns null.

Specified by:
getChild in interface Environment<K,V>
Parameters:
name - The child's name (if the child search is case sensitive depends on the actual implementation).
See Also:
DefaultEnvironment

locateChild

public Environment<K,V> locateChild(Path<java.lang.String> path)
Locate a child in the environment tree structure. If the environment has multiple children with the same name (if allowed; see allowsMultipleChildNames()) the method returns the child at the most left path (first child in subset). If the path is empty the method returns this environment itself. If a path element cannot be found in the child subsets the method returns null.

Specified by:
locateChild in interface Environment<K,V>
Parameters:
path - The path that determines the desired child environment.
Returns:
The child environment that is located at the given path or null if the path is invalid in the environment tree.

getAllChildren

public java.util.List<Environment<K,V>> getAllChildren()
This method simply returns a list containing _all_ children.

Specified by:
getAllChildren in interface Environment<K,V>

getChildren

public java.util.List<Environment<K,V>> getChildren(java.lang.String name)
Get *all* children with the given name.

Specified by:
getChildren in interface Environment<K,V>
Parameters:
name - The child's name (if the child search is case sensitive depends on the actual implementation).
See Also:
DefaultEnvironment

createChild

public Environment<K,V> createChild(java.lang.String name)
This method creates a new child environment and returns it. Note A: if allowsMultipleChildNames() returns true, this method always creates a new child. Note B: if allowsMultipleChildNames() returns false, and if a child with the given name already exists there will be no modifications to the environment. In this case the method return the old child.

Specified by:
createChild in interface Environment<K,V>
Parameters:
name - The child's name.

removeChild

public Environment<K,V> removeChild(java.lang.String name)
This method removes the child with the given name and returns its old value. If no such child can be found the method returns null. *

Specified by:
removeChild in interface Environment<K,V>
Parameters:
name - The child's name.

removeAllChildren

public void removeAllChildren()
This method simply removes all children from this environment. It is not a deep routine, so the inner data of child-environments themselves will not be affected.

Specified by:
removeAllChildren in interface Environment<K,V>

getChildCount

public int getChildCount()
This method returns the number of all children.

Specified by:
getChildCount in interface Environment<K,V>