public class Properties extends Object implements Cloneable
Modifier and Type | Field and Description |
---|---|
private Properties |
chained |
private static CloneHelper |
cloneHelper |
Constructor and Description |
---|
Properties() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
asBoolean(Object value,
boolean defaultValue)
Converts a value to boolean - this will be true only if the value is either the empty string,
or any Object which has a toString which is case-insensitive equal to "true"
|
protected Double |
asDouble(Object value,
Double defaultValue) |
protected Integer |
asInteger(Object value,
Integer defaultValue) |
protected Long |
asLong(Object value,
Long defaultValue) |
protected String |
asString(Object value,
String defaultValue) |
Properties |
chain(Properties chained)
Sets the properties chained to this.
|
Properties |
chained()
Returns the properties chained to this, or null if this is the last in the chain
|
Properties |
clone()
Clones this instance and recursively all chained instance.
|
static Object |
clone(Object object)
Clones this object if it is clonable, and the clone is public.
|
static Map<CompoundName,Object> |
cloneMap(Map<CompoundName,Object> map)
Clones a map by deep cloning each value which is cloneable and shallow copying all other values.
|
Object |
get(CompoundName name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)
|
Object |
get(CompoundName name,
Map<String,String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)
|
Object |
get(CompoundName name,
Map<String,String> context,
Properties substitution)
Gets a named value which (if necessary) is resolved using a property context.
|
Object |
get(CompoundName name,
Object defaultValue)
Gets a named value from the first chained instance which has one,
or the default value if no value is set, or if the first value encountered is explicitly set to null.
|
Object |
get(String name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)
|
Object |
get(String name,
Map<String,String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)
|
Object |
get(String name,
Map<String,String> context,
Properties substitution)
Gets a named value which (if necessary) is resolved using a property context
|
Object |
get(String name,
Object defaultValue)
Gets a named value from the first chained instance which has one,
or the default value if no value is set, or if the first value encountered is explicitly set to null.
|
boolean |
getBoolean(CompoundName name)
Gets a property as a boolean - if this value can reasonably be interpreted as a boolean, this will return
the value.
|
boolean |
getBoolean(CompoundName key,
boolean defaultValue)
Gets a property as a boolean.
|
boolean |
getBoolean(String name)
Gets a property as a boolean - if this value can reasonably be interpreted as a boolean, this will return
the value.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Gets a property as a boolean.
|
Double |
getDouble(CompoundName name)
Returns a property as a Double
|
Double |
getDouble(CompoundName name,
Double defaultValue)
Returns a property as a Double
|
Double |
getDouble(String name)
Returns a property as a Double
|
Double |
getDouble(String name,
Double defaultValue)
Returns a property as a Double
|
<T extends Properties> |
getInstance(Class<T> propertyClass)
Returns the first instance of the given class in this chain, or null if none
|
Integer |
getInteger(CompoundName name)
Returns a property as an Integer
|
Integer |
getInteger(CompoundName name,
Integer defaultValue)
Returns a property as an Integer
|
Integer |
getInteger(String name)
Returns a property as an Integer
|
Integer |
getInteger(String name,
Integer defaultValue)
Returns a property as an Integer
|
Long |
getLong(CompoundName name)
Returns a property as a Long
|
Long |
getLong(CompoundName name,
Long defaultValue)
Returns a property as a Long
|
Long |
getLong(String name)
Returns a property as a Long
|
Long |
getLong(String name,
Long defaultValue)
Returns a property as a Long
|
String |
getString(CompoundName key)
Returns this property as a string
|
String |
getString(CompoundName key,
String defaultValue)
Returns this property as a string
|
String |
getString(String key)
Returns this property as a string
|
String |
getString(String key,
String defaultValue)
Returns this property as a string
|
Map<String,Object> |
listProperties()
Lists all properties of this with no context, by delegating to listProperties("")
|
Map<String,Object> |
listProperties(CompoundName path)
Returns a snapshot of all properties by calling listProperties(path,null)
|
Map<String,Object> |
listProperties(CompoundName path,
Map<String,String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
|
Map<String,Object> |
listProperties(CompoundName path,
Map<String,String> context,
Properties substitution)
Returns a snapshot of all properties of this having a given path prefix
|
Map<String,Object> |
listProperties(Map<String,String> context)
Returns a snapshot of all properties of this - same as listProperties("",context)
|
Map<String,Object> |
listProperties(String path)
Returns a snapshot of all properties by calling listProperties(path,null)
|
Map<String,Object> |
listProperties(String path,
Map<String,String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
|
Map<String,Object> |
listProperties(String path,
Map<String,String> context,
Properties substitution)
Returns a snapshot of all properties of this having a given path prefix
|
void |
set(CompoundName name,
Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).
|
void |
set(CompoundName name,
Object value,
Map<String,String> context)
Sets a value to the first chained instance which accepts it.
|
void |
set(String name,
Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).
|
void |
set(String name,
Object value,
Map<String,String> context)
Sets a value to the first chained instance which accepts it.
|
private static final CloneHelper cloneHelper
private Properties chained
public Properties chain(Properties chained)
chained
- the properties to chain to this, or null to make this the last in the chainpublic Properties chained()
public final <T extends Properties> T getInstance(Class<T> propertyClass)
public final Map<String,Object> listProperties()
public final Map<String,Object> listProperties(Map<String,String> context)
public final Map<String,Object> listProperties(CompoundName path)
public final Map<String,Object> listProperties(String path)
public final Map<String,Object> listProperties(CompoundName path, Map<String,String> context)
public final Map<String,Object> listProperties(String path, Map<String,String> context)
public Map<String,Object> listProperties(CompoundName path, Map<String,String> context, Properties substitution)
Some sources of properties may not be list-able (e.g those using reflection) and will not be included in this snapshot.
path
- the prefix (up to a ".") of the properties to return, or null or the empty string to return all propertiescontext
- the context used to resolve the properties, or null if nonesubstitution
- the properties which will be used to do string substitution in the values added to the mappublic final Map<String,Object> listProperties(String path, Map<String,String> context, Properties substitution)
Some sources of properties may not be list-able (e.g those using reflection) and will not be included in this snapshot.
path
- the prefix (up to a ".") of the properties to return, or null or the empty string to return all propertiescontext
- the context used to resolve the properties, or null if nonesubstitution
- the properties which will be used to do string substitution in the values added to the mappublic Object get(CompoundName name, Map<String,String> context, Properties substitution)
name
- the name of the property to returncontext
- the variant resolution context, or null if nonesubstitution
- the properties used to substitute in these properties, or null if nonepublic final Object get(String name, Map<String,String> context, Properties substitution)
name
- the name of the property to returncontext
- the variant resolution context, or null if nonesubstitution
- the properties used to substitute in these properties, or null if nonepublic final Object get(CompoundName name, Map<String,String> context)
public final Object get(String name, Map<String,String> context)
public final Object get(CompoundName name)
public final Object get(String name)
public final Object get(CompoundName name, Object defaultValue)
This default implementation simply forwards to the chained instance, or returns the default if none
name
- the name of the property to returndefaultValue
- the default value returned if the value returned is nullpublic final Object get(String name, Object defaultValue)
This default implementation simply forwards to the chained instance, or returns the default if none
name
- the name of the property to returndefaultValue
- the default value returned if the value returned is nullpublic void set(CompoundName name, Object value, Map<String,String> context)
This default implementation forwards to the chained instance or throws a RuntimeException if there is not chained instance.
name
- the name of the valuevalue
- the value to set. Setting a name to null explicitly is legal.context
- the context used to resolve where the values should be set, or null if noneRuntimeException
- if no instance in the chain accepted this name-value pairpublic final void set(String name, Object value, Map<String,String> context)
This default implementation forwards to the chained instance or throws a RuntimeException if there is not chained instance.
name
- the name of the valuevalue
- the value to set. Setting a name to null explicitly is legal.context
- the context used to resolve where the values should be set, or null if noneRuntimeException
- if no instance in the chain accepted this name-value pairpublic final void set(CompoundName name, Object value)
name
- the name of the valuevalue
- the value to set. Setting a name to null explicitly is legal.RuntimeException
- if no instance in the chain accepted this name-value pairpublic final void set(String name, Object value)
name
- the name of the valuevalue
- the value to set. Setting a name to null explicitly is legal.RuntimeException
- if no instance in the chain accepted this name-value pairpublic final boolean getBoolean(CompoundName name)
public final boolean getBoolean(String name)
public final boolean getBoolean(CompoundName key, boolean defaultValue)
defaultValue
- the value to return if this property is nullpublic final boolean getBoolean(String key, boolean defaultValue)
defaultValue
- the value to return if this property is nullprotected final boolean asBoolean(Object value, boolean defaultValue)
public final String getString(CompoundName key)
public final String getString(String key)
public final String getString(CompoundName key, String defaultValue)
key
- the property keydefaultValue
- the value to return if this property is nullpublic final String getString(String key, String defaultValue)
key
- the property keydefaultValue
- the value to return if this property is nullpublic final Integer getInteger(CompoundName name)
NumberFormatException
- if the given parameter exists but
have a toString which is not parseable as a numberpublic final Integer getInteger(String name)
NumberFormatException
- if the given parameter exists but
have a toString which is not parseable as a numberpublic final Integer getInteger(CompoundName name, Integer defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter does not exist
or does not have a toString parseable as a numberpublic final Integer getInteger(String name, Integer defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter does not exist
or does not have a toString parseable as a numberpublic final Long getLong(CompoundName name)
NumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Long getLong(String name)
NumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Long getLong(CompoundName name, Long defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Long getLong(String name, Long defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Double getDouble(CompoundName name)
NumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Double getDouble(String name)
NumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Double getDouble(CompoundName name, Double defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic final Double getDouble(String name, Double defaultValue)
name
- the property namedefaultValue
- the value to return if this property is nullNumberFormatException
- if the given parameter exists but have a value which
is not parseable as a numberpublic Properties clone()
public static Map<CompoundName,Object> cloneMap(Map<CompoundName,Object> map)
Copyright © 2018. All rights reserved.