Package com.yahoo.processing.request
Class Properties
- java.lang.Object
-
- com.yahoo.processing.request.Properties
-
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
PropertyMap
public class Properties extends Object implements Cloneable
The properties of a request- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description Properties()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 chainvoid
clearAll(CompoundName name)
Sets all properties having this name as a compound prefix to null.void
clearAll(CompoundName name, Map<String,String> context)
Sets all properties having this name as a compound prefix to null.void
clearAll(String name)
Sets all properties having this name as a compound prefix to null.void
clearAll(String name, Object value, Map<String,String> context)
Sets all properties having this name as a compound prefix to null.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, 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(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(String name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)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.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 contextboolean
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 DoubleDouble
getDouble(CompoundName name, Double defaultValue)
Returns a property as a DoubleDouble
getDouble(String name)
Returns a property as a DoubleDouble
getDouble(String name, Double defaultValue)
Returns a property as a Double<T extends Properties>
TgetInstance(Class<T> propertyClass)
Returns the first instance of the given class in this chain, or null if noneInteger
getInteger(CompoundName name)
Returns a property as an IntegerInteger
getInteger(CompoundName name, Integer defaultValue)
Returns a property as an IntegerInteger
getInteger(String name)
Returns a property as an IntegerInteger
getInteger(String name, Integer defaultValue)
Returns a property as an IntegerLong
getLong(CompoundName name)
Returns a property as a LongLong
getLong(CompoundName name, Long defaultValue)
Returns a property as a LongLong
getLong(String name)
Returns a property as a LongLong
getLong(String name, Long defaultValue)
Returns a property as a LongString
getString(CompoundName key)
Returns this property as a stringString
getString(CompoundName key, String defaultValue)
Returns this property as a stringString
getString(String key)
Returns this property as a stringString
getString(String key, String defaultValue)
Returns this property as a stringMap<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 prefixMap<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 prefixMap<String,Object>
listProperties(Map<String,String> context)
Returns a snapshot of all properties of this - same as listProperties("",context)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.
-
-
-
Method Detail
-
chain
public Properties chain(Properties chained)
Sets the properties chained to this.- Parameters:
chained
- the properties to chain to this, or null to make this the last in the chain- Returns:
- the given chained object to allow setting up a chain by dotting in one statement
-
chained
public Properties chained()
Returns the properties chained to this, or null if this is the last in the chain
-
getInstance
public final <T extends Properties> T getInstance(Class<T> propertyClass)
Returns the first instance of the given class in this chain, or null if none
-
listProperties
public final Map<String,Object> listProperties()
Lists all properties of this with no context, by delegating to listProperties("")
-
listProperties
public final Map<String,Object> listProperties(Map<String,String> context)
Returns a snapshot of all properties of this - same as listProperties("",context)
-
listProperties
public final Map<String,Object> listProperties(CompoundName path)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final Map<String,Object> listProperties(String path)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final Map<String,Object> listProperties(CompoundName path, Map<String,String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final Map<String,Object> listProperties(String path, Map<String,String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public Map<String,Object> listProperties(CompoundName path, Map<String,String> context, Properties substitution)
Returns a snapshot of all properties of this having a given path prefixSome sources of properties may not be list-able (e.g those using reflection) and will not be included in this snapshot.
- Parameters:
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 map
-
listProperties
public final Map<String,Object> listProperties(String path, Map<String,String> context, Properties substitution)
Returns a snapshot of all properties of this having a given path prefixSome sources of properties may not be list-able (e.g those using reflection) and will not be included in this snapshot.
- Parameters:
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 map
-
get
public Object get(CompoundName name, Map<String,String> context, Properties substitution)
Gets a named value which (if necessary) is resolved using a property context.- Parameters:
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 none
-
get
public final Object get(String name, Map<String,String> context, Properties substitution)
Gets a named value which (if necessary) is resolved using a property context- Parameters:
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 none
-
get
public final 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)
-
get
public final 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)
-
get
public final Object get(CompoundName name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)
-
get
public final Object get(String name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)
-
get
public final 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.This default implementation simply forwards to the chained instance, or returns the default if none
- Parameters:
name
- the name of the property to returndefaultValue
- the default value returned if the value returned is null
-
get
public final 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.This default implementation simply forwards to the chained instance, or returns the default if none
- Parameters:
name
- the name of the property to returndefaultValue
- the default value returned if the value returned is null
-
set
public void set(CompoundName name, Object value, Map<String,String> context)
Sets a value to the first chained instance which accepts it.This default implementation forwards to the chained instance or throws a RuntimeException if there is not chained instance.
- Parameters:
name
- the name of the propertyvalue
- the value to set. Setting a property to null clears it.context
- the context used to resolve where the values should be set, or null if none- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(String name, Object value, Map<String,String> context)
Sets a value to the first chained instance which accepts it.This default implementation forwards to the chained instance or throws a RuntimeException if there is not chained instance.
- Parameters:
name
- the name of the propertyvalue
- the value to set. Setting a property to null clears it.context
- the context used to resolve where the values should be set, or null if none- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(CompoundName name, Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).- Parameters:
name
- the name of the propertyvalue
- the value to set. Setting a property to null clears it.- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(String name, Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).- Parameters:
name
- the name of the propertyvalue
- the value to set. Setting a property to null clears it.- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
clearAll
public void clearAll(CompoundName name, Map<String,String> context)
Sets all properties having this name as a compound prefix to null. I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab". This default implementation forwards to the chained instance or throws a RuntimeException if there is not chained instance.- Parameters:
name
- the compound prefix of the properties to clearcontext
- the context used to resolve where the values should be cleared, or null if none- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
clearAll
public final void clearAll(String name, Object value, Map<String,String> context)
Sets all properties having this name as a compound prefix to null. I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab".- Parameters:
name
- the compound prefix of the properties to clearcontext
- the context used to resolve where the values should be cleared, or null if none- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
clearAll
public final void clearAll(CompoundName name)
Sets all properties having this name as a compound prefix to null. I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab".- Parameters:
name
- the compound prefix of the properties to clear- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
clearAll
public final void clearAll(String name)
Sets all properties having this name as a compound prefix to null. I.e clearAll("a") will clear the value of "a" and "a.b" but not "ab".- Parameters:
name
- the compound prefix of the properties to clear- Throws:
RuntimeException
- if no instance in the chain accepted this name-value pair
-
getBoolean
public final 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. Returns false if this property is null.
-
getBoolean
public final 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. Returns false if this property is null.
-
getBoolean
public final boolean getBoolean(CompoundName key, boolean defaultValue)
Gets a property as a boolean. This will return true only if the value is either the empty string, or any Object which has a toString which is case-insensitive equal to "true"- Parameters:
defaultValue
- the value to return if this property is null
-
getBoolean
public final boolean getBoolean(String key, boolean defaultValue)
Gets a property as a boolean. This will return true only if the value is either the empty string, or any Object which has a toString which is case-insensitive equal to "true"- Parameters:
defaultValue
- the value to return if this property is null
-
asBoolean
protected final 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"
-
getString
public final String getString(CompoundName key)
Returns this property as a string- Returns:
- this property as a string, or null if the property is null
-
getString
public final String getString(String key)
Returns this property as a string- Returns:
- this property as a string, or null if the property is null
-
getString
public final String getString(CompoundName key, String defaultValue)
Returns this property as a string- Parameters:
key
- the property keydefaultValue
- the value to return if this property is null- Returns:
- this property as a string
-
getString
public final String getString(String key, String defaultValue)
Returns this property as a string- Parameters:
key
- the property keydefaultValue
- the value to return if this property is null- Returns:
- this property as a string
-
getInteger
public final Integer getInteger(CompoundName name)
Returns a property as an Integer- Returns:
- the integer value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a toString which is not parseable as a number
-
getInteger
public final Integer getInteger(String name)
Returns a property as an Integer- Returns:
- the integer value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a toString which is not parseable as a number
-
getInteger
public final Integer getInteger(CompoundName name, Integer defaultValue)
Returns a property as an Integer- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for the name
- Throws:
NumberFormatException
- if the given parameter does not exist or does not have a toString parseable as a number
-
getInteger
public final Integer getInteger(String name, Integer defaultValue)
Returns a property as an Integer- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for the name
- Throws:
NumberFormatException
- if the given parameter does not exist or does not have a toString parseable as a number
-
getLong
public final Long getLong(CompoundName name)
Returns a property as a Long- Returns:
- the long value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final Long getLong(String name)
Returns a property as a Long- Returns:
- the long value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final Long getLong(CompoundName name, Long defaultValue)
Returns a property as a Long- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for this name
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final Long getLong(String name, Long defaultValue)
Returns a property as a Long- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for this name
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final Double getDouble(CompoundName name)
Returns a property as a Double- Returns:
- the double value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final Double getDouble(String name)
Returns a property as a Double- Returns:
- the double value of the name, or null if the property is null
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final Double getDouble(CompoundName name, Double defaultValue)
Returns a property as a Double- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for this name
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final Double getDouble(String name, Double defaultValue)
Returns a property as a Double- Parameters:
name
- the property namedefaultValue
- the value to return if this property is null- Returns:
- the integer value for this name
- Throws:
NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
clone
public Properties clone()
Clones this instance and recursively all chained instance. Implementations should call this and clone their own state as appropriate
-
cloneMap
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.
-
-