public class ImmutableTypedProperties extends Properties
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID |
defaults
Constructor and Description |
---|
ImmutableTypedProperties(Properties... content)
Constructs a properties object.
|
Modifier and Type | Method and Description |
---|---|
private void |
addProperties(Properties properties)
Adds the specified properties to the current ones.
|
private Properties |
checkProperties(String prefix,
String[] validKeys,
String[] validSubPrefixes,
boolean printWarning)
Checks all properties with the given prefix for validity.
|
void |
clear() |
private static boolean |
contains(String[] list,
String element)
Returns true if the given element is a member of the given list.
|
boolean |
equals(Object object)
Compares this object to the specified object.
|
private Properties |
filter(String prefix)
Returns all properties who's key start with a certain prefix.
|
private Properties |
filter(String prefix,
boolean removePrefix,
boolean removeProperties)
Returns all properties who's key start with a certain prefix.
|
boolean |
getBooleanProperty(String name)
Returns true if property
name is defined and has a value
that is conventionally associated with 'true' (as in Ant): any of 1, on,
true, yes, or nothing. |
boolean |
getBooleanProperty(String key,
boolean defaultValue)
Returns true if property
name has a value that is
conventionally associated with 'true' (as in Ant): any of 1, on, true,
yes, or nothing. |
double |
getDoubleProperty(String key)
Returns the double value of property.
|
double |
getDoubleProperty(String key,
double defaultValue)
Returns the double value of property.
|
float |
getFloatProperty(String key)
Returns the float value of property.
|
float |
getFloatProperty(String key,
float defaultValue)
Returns the float value of property.
|
int |
getIntProperty(String key)
Returns the integer value of property.
|
int |
getIntProperty(String key,
int defaultValue)
Returns the integer value of property.
|
long |
getLongProperty(String key)
Returns the long value of property.
|
long |
getLongProperty(String key,
long defaultValue)
Returns the long value of property.
|
(package private) String[] |
getPropertyNames() |
short |
getShortProperty(String key)
Returns the short value of property.
|
short |
getShortProperty(String key,
short defaultValue)
Returns the short value of property.
|
long |
getSizeProperty(String key)
Returns the long value of a size property.
|
long |
getSizeProperty(String key,
long defaultValue)
Returns the long value of a size property.
|
String[] |
getStringList(String key)
Returns the split-up value of a string property.
|
String[] |
getStringList(String key,
String delim)
Returns the split-up value of a string property.
|
String[] |
getStringList(String key,
String delim,
String[] defaultValue)
Returns the split-up value of a string property.
|
void |
load(InputStream inStream) |
void |
load(Reader reader) |
static Properties |
loadFromClassPath(String resourceName)
Loads properties from a properties file on the classpath.
|
static Properties |
loadFromFile(String fileName)
Loads ImmutableTypedProperties from a file.
|
static void |
loadFromHomeFile(String fileName)
Tries to load properties from a file, which is located relative to the
users home directory.
|
void |
loadFromXML(InputStream in) |
void |
printProperties(PrintStream out,
String prefix)
Prints properties (including default properties) to a stream.
|
Object |
put(Object key,
Object value) |
void |
putAll(Map<? extends Object,? extends Object> t) |
Object |
remove(Object key) |
Object |
setProperty(String key,
String value) |
private static boolean |
startsWith(String string,
String[] prefixes)
Returns true if the given string starts with one of the given prefixes.
|
String |
toString()
Creates a string representation of this properties object.
|
getProperty, getProperty, list, list, propertyNames, save, store, store, storeToXML, storeToXML, stringPropertyNames
private static final long serialVersionUID
public ImmutableTypedProperties(Properties... content)
private void addProperties(Properties properties)
properties
- the properties to add.public static Properties loadFromClassPath(String resourceName) throws OctopusException
resourceName
- the name of the resource to load properties from.OctopusException
public static Properties loadFromFile(String fileName) throws OctopusException
fileName
- name of file to load from.OctopusException
public static void loadFromHomeFile(String fileName) throws OctopusException
fileName
- name of file to load from.OctopusException
public boolean getBooleanProperty(String name)
name
is defined and has a value
that is conventionally associated with 'true' (as in Ant): any of 1, on,
true, yes, or nothing.name
- property namepublic boolean getBooleanProperty(String key, boolean defaultValue)
name
has a value that is
conventionally associated with 'true' (as in Ant): any of 1, on, true,
yes, or nothing. If the property is not defined, return the specified
default value.key
- property namedefaultValue
- the value that is returned if the property is absentpublic int getIntProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not an integerpublic int getIntProperty(String key, int defaultValue)
key
- property namedefaultValue
- default value if the property is undefinedNumberFormatException
- if the property defined and not an integerpublic long getLongProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not an longpublic long getLongProperty(String key, long defaultValue)
key
- property namedefaultValue
- default value if the property is undefinedNumberFormatException
- if the property defined and not an Longpublic short getShortProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not an shortpublic short getShortProperty(String key, short defaultValue)
key
- property namedefaultValue
- default value if the property is undefinedNumberFormatException
- if the property defined and not an Shortpublic double getDoubleProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not an doublepublic double getDoubleProperty(String key, double defaultValue)
key
- property namedefaultValue
- default value if the property is undefinedNumberFormatException
- if the property defined and not an Doublepublic float getFloatProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not an floatpublic float getFloatProperty(String key, float defaultValue)
key
- property namedefaultValue
- default value if the property is undefinedNumberFormatException
- if the property defined and not an Floatpublic long getSizeProperty(String key)
key
- property nameNumberFormatException
- if the property is undefined or not a valid sizepublic long getSizeProperty(String key, long defaultValue)
key
- property namedefaultValue
- the default valueNumberFormatException
- if the property is not a valid sizepublic String[] getStringList(String key)
String.split(String)
for
details of the splitting. If the property is not defined, an empty array
of strings is returned.key
- the property namepublic String[] getStringList(String key, String delim)
String.split(String)
for details of the splitting. If
the property is not defined, an empty array of strings is returned.key
- the property namedelim
- the delimiterpublic String[] getStringList(String key, String delim, String[] defaultValue)
String.split(String)
for details of the splitting. If
the property is not defined, the specified default value is returned.key
- the property namedelim
- the delimiterdefaultValue
- the default valueprivate static boolean contains(String[] list, String element)
list
- the given list.element
- the given element.private static boolean startsWith(String string, String[] prefixes)
string
- the given string.prefixes
- the given prefixes.private Properties checkProperties(String prefix, String[] validKeys, String[] validSubPrefixes, boolean printWarning)
prefix
- the prefix that should be checkedvalidKeys
- the set of valid keys (all with the prefix).validSubPrefixes
- if a propery starts with one of these prefixes, it is declared
validprintWarning
- if true, a warning is printed to standard error for each
unknown propertyprivate Properties filter(String prefix, boolean removePrefix, boolean removeProperties)
prefix
- the desired prefixremovePrefix
- should the prefix be removed from the property name?removeProperties
- should the returned properties be removed from the current
properties?private Properties filter(String prefix)
prefix
- the desired prefixpublic void printProperties(PrintStream out, String prefix)
out
- The stream to write output to.prefix
- Only print properties which start with the given prefix. If
null, will print all propertiespublic String toString()
String[] getPropertyNames()
public boolean equals(Object object)
public Object setProperty(String key, String value)
setProperty
in class Properties
public void clear()
public void load(Reader reader) throws IOException
load
in class Properties
IOException
public void load(InputStream inStream) throws IOException
load
in class Properties
IOException
public void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException
loadFromXML
in class Properties
IOException
InvalidPropertiesFormatException