ikrs.util
Class DefaultEnvironment<K,V>

java.lang.Object
  extended by ikrs.util.AbstractMapDelegation<K,V>
      extended by ikrs.util.DefaultEnvironment<K,V>
All Implemented Interfaces:
Environment<K,V>, java.util.Map<K,V>

public class DefaultEnvironment<K,V>
extends AbstractMapDelegation<K,V>
implements Environment<K,V>


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class ikrs.util.AbstractMapDelegation
baseMap
 
Constructor Summary
DefaultEnvironment()
          Create a new Environment having allowsMultipleChildNames() set to true.
DefaultEnvironment(MapFactory<K,V> mapFactory)
          Create a new Environment with the given MapFactory and having allowsMultipleChildNames() set to true.
DefaultEnvironment(MapFactory<K,V> mapFactory, boolean allowsMultipleChildNames)
          Create a new Environment with the given MapFactory.
DefaultEnvironment(MapFactory<K,V> mapFactory, java.util.Comparator<K> keyComparator, boolean allowsMultipleChildNames)
          Create a new Environment with the given MapFactory.
DefaultEnvironment(MapFactory<K,V> mapFactory, java.util.Comparator<K> keyComparator, Environment<K,V> parentEnvironment, boolean allowsMultipleChildNames)
          Create a new Environment with the given MapFactory.
 
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.
 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.
 java.lang.String toString()
           
 java.lang.StringBuffer toString(java.lang.StringBuffer b)
           
protected  java.lang.StringBuffer toString(java.lang.StringBuffer b, int indent)
           
 
Methods inherited from class ikrs.util.AbstractMapDelegation
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, makeIndent, put, putAll, remove, size, toString, toString, values
 
Methods inherited from class java.lang.Object
clone, 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

DefaultEnvironment

public DefaultEnvironment()
                   throws java.lang.NullPointerException
Create a new Environment having allowsMultipleChildNames() set to true. The environment will use a TreeMapFactory.

Parameters:
mapFactory - The map factory that will be used to create new internal child maps.
Throws:
java.lang.NullPointerException

DefaultEnvironment

public DefaultEnvironment(MapFactory<K,V> mapFactory)
                   throws java.lang.NullPointerException
Create a new Environment with the given MapFactory and having allowsMultipleChildNames() set to true.

Parameters:
mapFactory - The map factory that will be used to create new internal child maps.
Throws:
java.lang.NullPointerException

DefaultEnvironment

public DefaultEnvironment(MapFactory<K,V> mapFactory,
                          boolean allowsMultipleChildNames)
                   throws java.lang.NullPointerException
Create a new Environment with the given MapFactory.

Parameters:
mapFactory - The map factory that will be used to create new internal child maps.
Throws:
java.lang.NullPointerException

DefaultEnvironment

public DefaultEnvironment(MapFactory<K,V> mapFactory,
                          java.util.Comparator<K> keyComparator,
                          boolean allowsMultipleChildNames)
                   throws java.lang.NullPointerException
Create a new Environment with the given MapFactory.

Parameters:
mapFactory - The map factory that will be used to create new internal child maps.
keyComparator - The key comparator for this map.
Throws:
java.lang.NullPointerException

DefaultEnvironment

public DefaultEnvironment(MapFactory<K,V> mapFactory,
                          java.util.Comparator<K> keyComparator,
                          Environment<K,V> parentEnvironment,
                          boolean allowsMultipleChildNames)
                   throws java.lang.NullPointerException
Create a new Environment with the given MapFactory.

Parameters:
mapFactory - The map factory that will be used to create new internal child maps.
keyComparator - The key comparator for this map.
parentEnvironment - The parent environment (if exists).
Throws:
java.lang.NullPointerException
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. 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>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.StringBuffer toString(java.lang.StringBuffer b)
Overrides:
toString in class AbstractMapDelegation<K,V>

toString

protected java.lang.StringBuffer toString(java.lang.StringBuffer b,
                                          int indent)