info.ephyra.util
Class Properties
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<java.lang.String,java.lang.String>
info.ephyra.util.Properties
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.String>
public class Properties
- extends java.util.HashMap<java.lang.String,java.lang.String>
Properties class the way it was meant to be; Generics and property filtering
and manipulation based on the conventional dot-separator property name
syntax.
- Version:
- 2008-02-10
- Author:
- Andy Schlaikjer
- See Also:
- Serialized Form
|
Method Summary |
Properties |
filterProperties(java.lang.String prefix,
boolean remove_prefix)
Filters the entries in this Properties object and returns a new object
containing only those entries whose keys match the given string prefix. |
java.lang.String |
getProperty(java.lang.String name)
|
java.lang.String |
getProperty(java.lang.String name,
java.lang.String defaultValue)
|
java.util.Set<java.lang.String> |
getPropertyNames()
|
void |
load(java.io.InputStream is)
|
static Properties |
loadFromClassName(java.lang.String className)
load properties from given a class name
Sample usage:
Properties p =
Properties.loadPropertiesFromClassName( getClass().getName() );
|
void |
loadFromXML(java.io.InputStream is)
|
java.util.Map<java.lang.String,Properties> |
mapProperties()
For each key in this Properties object a prefix string is created from
all leading characters before the first '.' |
void |
setProperty(java.lang.String name,
java.lang.String value)
|
java.util.Properties |
toJavaProperties()
|
| Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
| Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
equals, hashCode |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
Properties
public Properties()
Properties
public Properties(Properties properties)
getProperty
public java.lang.String getProperty(java.lang.String name)
setProperty
public void setProperty(java.lang.String name,
java.lang.String value)
getProperty
public java.lang.String getProperty(java.lang.String name,
java.lang.String defaultValue)
getPropertyNames
public java.util.Set<java.lang.String> getPropertyNames()
load
public void load(java.io.InputStream is)
throws java.io.IOException
- Parameters:
is -
- Throws:
java.io.IOException- See Also:
Properties.load(InputStream)
loadFromXML
public void loadFromXML(java.io.InputStream is)
throws java.io.IOException
- Parameters:
is -
- Throws:
java.io.IOException- See Also:
Properties.loadFromXML(InputStream)
filterProperties
public Properties filterProperties(java.lang.String prefix,
boolean remove_prefix)
- Filters the entries in this Properties object and returns a new object
containing only those entries whose keys match the given string prefix.
Optionally, you may have the prefix removed from the keys in the returned
Properties object.
- Parameters:
prefix - the prefix string to use as a filter on existing entry
keys.remove_prefix - if true, strips the prefix off of all key values in
the returned Properties object.
- Returns:
- a new Properties object containing only those entries from this
Properties object whose keys match the given prefix.
mapProperties
public java.util.Map<java.lang.String,Properties> mapProperties()
- For each key in this Properties object a prefix string is created from
all leading characters before the first '.' (period) character. This
prefix string is used as a new key which will reference a new Properties
object containing the original key stripped of the prefix and the
original value. For example, if this Properties object contains the
following entries:
one = yes
one.a = 1
one.b = 2
two.a = 3
two.b = 4
then the returned Map would look like this (Perl
notation):
{
one => {
a => '1',
b => '2'
},
two => {
a => '3',
b => '4'
}
}
toJavaProperties
public java.util.Properties toJavaProperties()
- Returns:
- a java.util.Properties object containing equivalent key-value
entries.
loadFromClassName
public static Properties loadFromClassName(java.lang.String className)
- load properties from given a class name
Sample usage:
Properties p =
Properties.loadPropertiesFromClassName( getClass().getName() );
- Returns:
- a Properties object containing the content of the properties file