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