com.go.trove.util
Class PropertyMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--com.go.trove.util.PropertyMap
All Implemented Interfaces:
java.util.Map

public class PropertyMap
extends java.util.AbstractMap

A class that is similar to java.util.Properties but preserves original property order and supports a special subMap(java.lang.String) view operation. PropertyMap also has more convenience methods for getting properties as certain types.

Version:
13 4 01/02/26
Author:
Brian S O'Neill

Inner classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static java.lang.Class ELEMENT_TYPE
           
 
Constructor Summary
PropertyMap()
          Construct a PropetyMap using a dot (".") separator.
PropertyMap(java.util.Map map)
           
PropertyMap(java.util.Map map, java.lang.String separator)
           
PropertyMap(java.lang.String separator)
           
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsKey(java.lang.String key)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object get(java.lang.String key)
           
 boolean getBoolean(java.lang.String key)
          Returns true only if value is "true", ignoring case.
 boolean getBoolean(java.lang.String key, boolean def)
          Returns the default value if the given key isn't in this PropertyMap or if the the value isn't equal to "true", ignoring case.
 int getInt(java.lang.String key)
          Returns 0 if the given key isn't in this PropertyMap.
 int getInt(java.lang.String key, int def)
          Returns the default value if the given key isn't in this PropertyMap or isn't a valid integer.
 java.lang.Integer getInteger(java.lang.String key)
          Returns null if the given key isn't in this PropertyMap or it isn't a valid integer.
 java.lang.Integer getInteger(java.lang.String key, java.lang.Integer def)
          Returns the default value if the given key isn't in this PropertyMap or it isn't a valid integer.
 java.lang.Number getNumber(java.lang.String key)
          Returns null if the given key isn't in this PropertyMap.
 java.lang.Number getNumber(java.lang.String key, java.lang.Number def)
          Returns the default value if the given key isn't in this PropertyMap or isn't a valid number.
 java.lang.String getSeparator()
           
 java.lang.String getString(java.lang.String key)
          Returns null if the given key isn't in this PropertyMap.
 java.lang.String getString(java.lang.String key, java.lang.String def)
          Returns the default value if the given key isn't in this PropertyMap.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          The key is always converted to a String.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void putDefaults(java.util.Map map)
          Copies the entries of the given map into this one only for keys that aren't contained in this map.
 java.lang.Object remove(java.lang.Object key)
           
 java.lang.Object remove(java.lang.String key)
           
 int size()
           
 PropertyMap subMap(java.lang.String key)
          Returns a view of this map for keys that are the same as the given key, or start with it (and a separator).
 java.util.Set subMapKeySet()
          Returns the key names of each sub-map in this PropertyMap.
 java.util.Collection values()
           
 
Methods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ELEMENT_TYPE

public static final java.lang.Class ELEMENT_TYPE
Constructor Detail

PropertyMap

public PropertyMap()
Construct a PropetyMap using a dot (".") separator.

PropertyMap

public PropertyMap(java.util.Map map)
Parameters:
map - Map of defaults.

PropertyMap

public PropertyMap(java.lang.String separator)
Parameters:
separator - Sub-key separator, i.e. ".".

PropertyMap

public PropertyMap(java.util.Map map,
                   java.lang.String separator)
Parameters:
map - Optional map of defaults.
separator - Sub-key separator, i.e. ".".
See Also:
putDefaults(Map)
Method Detail

getSeparator

public java.lang.String getSeparator()

subMap

public PropertyMap subMap(java.lang.String key)
Returns a view of this map for keys that are the same as the given key, or start with it (and a separator). The names of the keys in the sub-map have their prefix truncated.

A sub-map of

 "x" = "a"
 "foo" = "b"
 "foo." = "c"
 "foo.bar" = "d"
 "foo.bar.splat" = "e"
 "foo..bar" = "f"
 ".foo" = "g"
 "" = "h"
 null = "i"
 
using a key of "foo" results in
 null = "b"
 "" = "c"
 "bar" = "d"
 "bar.splat" = "e"
 ".bar" = "f"
 
using a key of "x" results in
 null = "a"
 
using a key of "" results in
 "foo" = "g"
 null = "h"
 
and using a key of null results in the original map.

subMapKeySet

public java.util.Set subMapKeySet()
Returns the key names of each sub-map in this PropertyMap. The returned set is unmodifiable.

size

public int size()
Overrides:
size in class java.util.AbstractMap

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class java.util.AbstractMap

containsKey

public boolean containsKey(java.lang.Object key)
Overrides:
containsKey in class java.util.AbstractMap

containsKey

public boolean containsKey(java.lang.String key)

get

public java.lang.Object get(java.lang.Object key)
Overrides:
get in class java.util.AbstractMap

get

public java.lang.Object get(java.lang.String key)

getString

public java.lang.String getString(java.lang.String key)
Returns null if the given key isn't in this PropertyMap.
Parameters:
key - Key of property to read

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String def)
Returns the default value if the given key isn't in this PropertyMap.
Parameters:
key - Key of property to read
def - Default value

getInt

public int getInt(java.lang.String key)
           throws java.lang.NumberFormatException
Returns 0 if the given key isn't in this PropertyMap.
Parameters:
key - Key of property to read

getInt

public int getInt(java.lang.String key,
                  int def)
Returns the default value if the given key isn't in this PropertyMap or isn't a valid integer.
Parameters:
key - Key of property to read
def - Default value

getInteger

public java.lang.Integer getInteger(java.lang.String key)
Returns null if the given key isn't in this PropertyMap or it isn't a valid integer.
Parameters:
key - Key of property to read

getInteger

public java.lang.Integer getInteger(java.lang.String key,
                                    java.lang.Integer def)
Returns the default value if the given key isn't in this PropertyMap or it isn't a valid integer.
Parameters:
key - Key of property to read
def - Default value

getNumber

public java.lang.Number getNumber(java.lang.String key)
                           throws java.lang.NumberFormatException
Returns null if the given key isn't in this PropertyMap.
Parameters:
key - Key of property to read

getNumber

public java.lang.Number getNumber(java.lang.String key,
                                  java.lang.Number def)
Returns the default value if the given key isn't in this PropertyMap or isn't a valid number.
Parameters:
key - Key of property to read
def - Default value

getBoolean

public boolean getBoolean(java.lang.String key)
Returns true only if value is "true", ignoring case.
Parameters:
key - Key of property to read

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean def)
Returns the default value if the given key isn't in this PropertyMap or if the the value isn't equal to "true", ignoring case.
Parameters:
key - Key of property to read
def - Default value

entrySet

public java.util.Set entrySet()
Overrides:
entrySet in class java.util.AbstractMap

keySet

public java.util.Set keySet()
Overrides:
keySet in class java.util.AbstractMap

values

public java.util.Collection values()
Overrides:
values in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
The key is always converted to a String.
Overrides:
put in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)

putDefaults

public void putDefaults(java.util.Map map)
Copies the entries of the given map into this one only for keys that aren't contained in this map. Is equivalent to putAll if this map is empty.

remove

public java.lang.Object remove(java.lang.Object key)
Overrides:
remove in class java.util.AbstractMap

remove

public java.lang.Object remove(java.lang.String key)

clear

public void clear()
Overrides:
clear in class java.util.AbstractMap