de.grogra.util
Class Configuration

java.lang.Object
  extended by de.grogra.util.Configuration
All Implemented Interfaces:
Map, ModifiableMap

public final class Configuration
extends java.lang.Object
implements ModifiableMap

A Configuration is a ModifiableMap which uses Strings as keys and maintains three levels of associations:

  1. The basic level is represented by default values and is not modified by methods of this class.
  2. The next level overrides the basic level, it is defined by the override methods.
  3. The third level overrides the other levels, it is defined by the put method.

Author:
Ole Kniemeyer

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.grogra.util.ModifiableMap
ModifiableMap.Producer
 
Nested classes/interfaces inherited from interface de.grogra.util.Map
Map.Chain
 
Field Summary
 
Fields inherited from interface de.grogra.util.Map
DEFAULT_VALUE, EMPTY_MAP
 
Constructor Summary
Configuration(KeyDescription[] keys, Map values)
          Creates a new Configuration.
 
Method Summary
 java.lang.Object get(java.lang.Object key, java.lang.Object defaultValue)
          Returns the value associated with key.
 void override(java.lang.String key, java.lang.Object value)
          Overrides default values of this configuration.
 void overrideIfUnset(java.lang.String key, java.lang.Object value)
          Sets a default value if no default value is provided by the map for default values.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps key to value.
 void writeBack()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Configuration

public Configuration(KeyDescription[] keys,
                     Map values)
Creates a new Configuration. Its keys are described by keys, its default values by the map values.

Parameters:
keys - the keys of this configuration
values - the default values of this configuration
Method Detail

get

public java.lang.Object get(java.lang.Object key,
                            java.lang.Object defaultValue)
Description copied from interface: Map
Returns the value associated with key. If there is no value associated with key, defaultValue is returned.

Specified by:
get in interface Map
Parameters:
key - a key for the map
defaultValue - the default value
Returns:
the associated value, or defaultValue

override

public void override(java.lang.String key,
                     java.lang.Object value)
Overrides default values of this configuration.

Parameters:
key - a key
value - the new default value for key

overrideIfUnset

public void overrideIfUnset(java.lang.String key,
                            java.lang.Object value)
Sets a default value if no default value is provided by the map for default values.

Parameters:
key - a key
value - the default value for key

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: ModifiableMap
Maps key to value. Following invocations of the get-method with key as key will return value.

Specified by:
put in interface ModifiableMap
Parameters:
key - a key
value - the value to be associated with key
Returns:
the previously associated value, or null

writeBack

public void writeBack()