All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class uhr.core.tron.PropMapStd

java.lang.Object
   |
   +----uhr.core.tron.PropMapStd

public class PropMapStd
extends Object
implements PropMap
This class defines a configurable key value data structure similar to Hashtable. Its outstanding characteristic is it can also automatically support tree like behavior, allowing it be used as a param, tree, etc. We expect to add more configurable properties.

Keys must be Strings with no spaces allowed. All configurable properties have sensible defaults. The configurable properties are:

 
    isNullValueAllowed()
    isOrderedKeys()
    getNestedKeySeparator()
 
This implementation is not thread-safe. We expect to need to add methods to the interface as needs arise. For example there is no getParent(), which hinders full use as a tree.


Constructor Index

 o PropMapStd()
A no arg constructor that leaves configuration defaults alone.
 o PropMapStd(boolean, boolean, String)
A constructor for configuration.

Method Index

 o clone()
Returns a shallow copy of the object.
 o containsKey(String)
Returns true if the collection contains the key, false if not.
 o containsValue(Object)
Returns true if the collection contains the value, false if not.
 o findFirstKey(Object)
Returns the first key found for the value, or null if not found.
 o get(String)
Returns the value to which the specified key is mapped in this collection.
 o getBoolean(String)
Returns the boolean value for the key.
 o getDouble(String)
Returns the double value for the key.
 o getDoubleDefault(String, double)
Same as getDouble(key) except allows a default to be returned rather than an exception if not found.
 o getFloat(String)
Returns the float value for the key.
 o getFloatDefault(String, float)
Same as getFloat(key) except allows a default to be returned rather than an exception if not found.
 o getInt(String)
Returns the int value for the key.
 o getIntDefault(String, int)
Same as getInt(key) except allows a default to be returned rather than an exception if not found.
 o getKeys()
Returns an enumeration of the keys in this collection.
 o getLong(String)
Returns the long value for the key.
 o getLongDefault(String, long)
Same as getLong(key) except allows a default to be returned rather than an exception if not found.
 o getNestedKeySeparator()
Returns the nested key separator or null if none in use.
 o getSize()
Returns the number of key values in the collection, which may be zero.
 o getString(String)
Returns the String value for the key.
 o getStringDefault(String, String)
Same as getString(key) except allows a default to be returned rather than null.
 o insertBefore(String, Object, String)
Inserts the key and value before the keyBefore.
 o isEmpty()
Returns true if the collection is empty or false if not.
 o isFalse(String)
Used to determine if the key value is false.
 o isFalseDefault(String, boolean)
Same as isFalse(key) except allows a default to be returned if not found rather than an exception.
 o isNullValueAllowed()
Returns true if null values are allowed, false if not.
 o isOrderedKeys()
Returns true if ordered keys are maintained, false if not.
 o isTree()
Returns true if a non-null nested key separator has been set.
 o isTrue(String)
Used to determine if the key value is true.
 o isTrueDefault(String, boolean)
Same as isTrue(key) except allows a default to be returned if not found rather than an exception.
 o put(String, Object)
Puts the value in the collection and associates it with the key for retrival.
 o removeAll()
Removes all keys and values from the collection.
 o removeKey(String)
Removes the key and its value.
 o removeValue(Object)
Removes all occurances of the key for this value.
 o setBoolean(String, boolean)
Sets the key value, overwriting any that already exists.
 o setDouble(String, double)
Sets the key value, overwriting any that already exists.
 o setFalse(String)
Same as setBoolean(key, false).
 o setFloat(String, float)
Sets the key value, overwriting any that already exists.
 o setInt(String, int)
Sets the key value, overwriting any that already exists.
 o setLong(String, long)
Sets the key value, overwriting any that already exists.
 o setString(String, String)
Sets the key value, overwriting any that already exists.
 o setTrue(String)
Same as setBoolean(key, true).
 o toString()
Returns a comma delimited string of key/values, for example: "[Name=Pantajeli, Age=11]".

Constructors

 o PropMapStd
 public PropMapStd()
A no arg constructor that leaves configuration defaults alone. The defaults are null values are not allowed, keys are not ordered, and no key separator.

 o PropMapStd
 public PropMapStd(boolean isNullValueAllowed,
                   boolean isOrderedKeys,
                   String keySeparator)
A constructor for configuration.

Parameters:
isNullValueAllowed - determines whether null values are allowed.
isOrderedKeys - determines whether ordered keys are maintained.
keySeparator - the key separator to use or null for none.

Methods

 o isNullValueAllowed
 public boolean isNullValueAllowed()
Returns true if null values are allowed, false if not. The default is false.

Returns:
whether null values are allowed or not.
 o isOrderedKeys
 public boolean isOrderedKeys()
Returns true if ordered keys are maintained, false if not. The default is false.

If true the keys are maintained in the order added. This allows the order of keys to be preserved, instead of being random. An example of usefulness is to preserve the order of a visual tree or list.

Returns:
whether ordered keys are maintained or not.
 o getNestedKeySeparator
 public String getNestedKeySeparator()
Returns the nested key separator or null if none in use. The default is null.

The separator is used for reads and writes with nested keys, such as "State.County.Town". This allows very efficient use of keys for tree structures. This is only useful if a tree is being used and single keys don't have the separator. The default is null, meaning none. Common, safe key separators are "." and "/".

If a key separator has been set, reads and writes will use automatic nesting, which occurs if a separator is present in the key.

For example put("Georgia.Dekalb.Clarkston", "2000") would put "2000" into the path using the key. The call get("Georgia.Dekalb.Clarkston") would return "2000", as expected. But the call get("Georgia.Dekalb") returns an OmniTron, and can be followed by omniTron.get("Clarkston") which returns "2000". Thus nested OmniTrons can be used to create a clean, easy to use, tree structure.

Returns:
the nested key separator or null if none.
 o isTree
 public boolean isTree()
Returns true if a non-null nested key separator has been set. The default is false.

Returns:
whether a nested key separator is in use fot a tree data structure or not.
 o put
 public Object put(String key,
                   Object value)
Puts the value in the collection and associates it with the key for retrival. Any previous value is overwritten.

Parameters:
key - the unique identifier for the value.
value - the Object to associate with the key.
Returns:
the previous value with the key, or null if none or the value was null.
 o insertBefore
 public void insertBefore(String key,
                          Object value,
                          String keyBefore)
Inserts the key and value before the keyBefore. This is only allowed for ordered collections. The keyBefore must already be in the collection and the key must not already be in the collection.

Parameters:
key - the unique identifier for the value.
value - the Object to associate with the key.
keyBefore - the key to insert the key/value before.
 o removeKey
 public Object removeKey(String key)
Removes the key and its value.

Parameters:
key - the key to remove.
Returns:
the value removed, or null if none or the value was null.
 o removeValue
 public int removeValue(Object value)
Removes all occurances of the key for this value. If the value is null and null values are allowed, then all keys with null values are removed, so be careful. :-)

Parameters:
value - the value to remove all occurances of.
Returns:
the number of keys removed.
 o removeAll
 public void removeAll()
Removes all keys and values from the collection. Has no effect on the configuration.

 o get
 public Object get(String key)
Returns the value to which the specified key is mapped in this collection.

Parameters:
key - the key of the value to retrieve.
Returns:
the value for the key, or null if not found or null if the value was null.
 o getKeys
 public Enumeration getKeys()
Returns an enumeration of the keys in this collection.

Returns:
an enumeration of all the keys, in order if ordered keys.
 o getSize
 public int getSize()
Returns the number of key values in the collection, which may be zero. Note this doesn't include children if a tree.

Returns:
the size of the collection.
 o isEmpty
 public boolean isEmpty()
Returns true if the collection is empty or false if not.

Returns:
true if empty or false if not.
 o containsKey
 public boolean containsKey(String key)
Returns true if the collection contains the key, false if not.

Parameters:
key - the key to test.
Returns:
true if the collection contains the key, false if not.
 o containsValue
 public boolean containsValue(Object value)
Returns true if the collection contains the value, false if not. Note that if null values are allowed and the value is null, then the value may be associated with more than one key.

Parameters:
value - the value to test.
Returns:
true if the collection contains the value, false if not.
 o findFirstKey
 public String findFirstKey(Object value)
Returns the first key found for the value, or null if not found. This may be only useful for ordered keys.

Parameters:
value - the value to use to find the key.
Returns:
the key found or null if not foubd.
 o toString
 public String toString()
Returns a comma delimited string of key/values, for example: "[Name=Pantajeli, Age=11]". If a tree then a tree format is used. Both are designed to be easily readable.

Returns:
the String representation of the collection.
Overrides:
toString in class Object
 o clone
 public Object clone()
Returns a shallow copy of the object.

Returns:
a shallow copy of the object.
Overrides:
clone in class Object
 o setString
 public void setString(String key,
                       String value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the String value, which may be null.
 o getString
 public String getString(String key)
Returns the String value for the key.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or null.
 o getStringDefault
 public String getStringDefault(String key,
                                String defaultValue)
Same as getString(key) except allows a default to be returned rather than null.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if the return would otherwise be null.
Returns:
the key's value or the defaultValue if not found.
 o setBoolean
 public void setBoolean(String key,
                        boolean value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the boolean value.
 o setTrue
 public void setTrue(String key)
Same as setBoolean(key, true).

 o setFalse
 public void setFalse(String key)
Same as setBoolean(key, false).

 o getBoolean
 public boolean getBoolean(String key)
Returns the boolean value for the key. We assume that the setBoolean method was used to set this value. If a non-Boolean value is found, an IllegalStateException is thrown. If no value is set, an IllegalStateException is thrown.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or an exception if not found.
 o isTrue
 public boolean isTrue(String key)
Used to determine if the key value is true.

Parameters:
key - the key in question.
Returns:
true if the key's value is true, false if it's false, or an exception if not found.
 o isTrueDefault
 public boolean isTrueDefault(String key,
                              boolean defaultValue)
Same as isTrue(key) except allows a default to be returned if not found rather than an exception.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if the value is not found.
Returns:
true if the key's value is true, false if it's false, or the defaultValue if not found.
 o isFalse
 public boolean isFalse(String key)
Used to determine if the key value is false.

Parameters:
key - the key in question.
Returns:
true if the key's value is false, false if it's true, or an exception if not found.
 o isFalseDefault
 public boolean isFalseDefault(String key,
                               boolean defaultValue)
Same as isFalse(key) except allows a default to be returned if not found rather than an exception.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if the value is not found.
Returns:
true if the key's value is false, false if it's true, or the defaultValue if not found.
 o setInt
 public void setInt(String key,
                    int value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the int value.
 o getInt
 public int getInt(String key)
Returns the int value for the key.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or an exception if not found.
 o getIntDefault
 public int getIntDefault(String key,
                          int defaultValue)
Same as getInt(key) except allows a default to be returned rather than an exception if not found.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if not found.
Returns:
the key's value or the defaultValue if not found.
 o setLong
 public void setLong(String key,
                     long value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the long value.
 o getLong
 public long getLong(String key)
Returns the long value for the key.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or an exception if not found.
 o getLongDefault
 public long getLongDefault(String key,
                            long defaultValue)
Same as getLong(key) except allows a default to be returned rather than an exception if not found.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if not found.
Returns:
the key's value or the defaultValue if not found.
 o setFloat
 public void setFloat(String key,
                      float value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the float value.
 o getFloat
 public float getFloat(String key)
Returns the float value for the key.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or an exception if not found.
 o getFloatDefault
 public float getFloatDefault(String key,
                              float defaultValue)
Same as getFloat(key) except allows a default to be returned rather than an exception if not found.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if not found.
Returns:
the key's value or the defaultValue if not found.
 o setDouble
 public void setDouble(String key,
                       double value)
Sets the key value, overwriting any that already exists.

Parameters:
key - the unique key, which may not be null.
value - the double value.
 o getDouble
 public double getDouble(String key)
Returns the double value for the key.

Parameters:
key - the key to be used for the lookup.
Returns:
the key's value or an exception if not found.
 o getDoubleDefault
 public double getDoubleDefault(String key,
                                double defaultValue)
Same as getDouble(key) except allows a default to be returned rather than an exception if not found.

Parameters:
key - the key to be used for the lookup.
defaultValue - the default to be used if not found.
Returns:
the key's value or the defaultValue if not found.

All Packages  Class Hierarchy  This Package  Previous  Next  Index