Package com.yahoo.processing.request
Class Properties
java.lang.Object
com.yahoo.processing.request.Properties
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
PropertyMap
The properties of a request
- Author:
- bratseth
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final boolean
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 final Double
protected final Integer
protected final Long
protected final String
chain
(Properties chained) Sets the properties chained to this.chained()
Returns the properties chained to this, or null if this is the last in the chainfinal void
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.final void
Sets all properties having this name as a compound prefix to null.final void
Sets all properties having this name as a compound prefix to null.clone()
Clones this instance and recursively all chained instance.static 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.final Object
get
(CompoundName name) Gets a named value from the first chained instance which has one by calling get(name,null,this).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.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
(CompoundName name, Map<String, String> context, Properties substitution) Gets a named value which (if necessary) is resolved using a property context.final Object
Gets a named value from the first chained instance which has one by calling get(name,null,this).final Object
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.final Object
Gets a named value from the first chained instance which has one by calling get(name,context,this).final Object
Gets a named value which (if necessary) is resolved using a property context.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.final boolean
getBoolean
(CompoundName key, boolean defaultValue) Gets a property as a boolean.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.final boolean
getBoolean
(String key, boolean defaultValue) Gets a property as a boolean.final Double
getDouble
(CompoundName name) Returns a property as a Double.final Double
getDouble
(CompoundName name, Double defaultValue) Returns a property as a Double.final Double
Returns a property as a Double.final Double
Returns a property as a Double.final <T extends Properties>
TgetInstance
(Class<T> propertyClass) Returns the first instance of the given class in this chain, or null if nonefinal Integer
getInteger
(CompoundName name) Returns a property as an Integer.final Integer
getInteger
(CompoundName name, Integer defaultValue) Returns a property as an Integer.final Integer
getInteger
(String name) Returns a property as an Integer.final Integer
getInteger
(String name, Integer defaultValue) Returns a property as an Integer.final Long
getLong
(CompoundName name) Returns a property as a Long.final Long
getLong
(CompoundName name, Long defaultValue) Returns a property as a Long.final Long
Returns a property as a Long.final Long
Returns a property as a Long.final String
getString
(CompoundName key) Returns this property as a string.final String
getString
(CompoundName key, String defaultValue) Returns this property as a string.final String
Returns this property as a string.final String
Returns this property as a string.Lists all properties of this with no context, by delegating to listProperties("").listProperties
(CompoundName path) Returns a snapshot of all properties by calling listProperties(path, null).listProperties
(CompoundName path, Map<String, String> context) Returns a snapshot of all properties by calling listProperties(path, null).listProperties
(CompoundName path, Map<String, String> context, Properties substitution) Returns a snapshot of all properties of this having a given path prefix Some sources of properties may not be list-able and will not be included in this snapshot.listProperties
(String path) Returns a snapshot of all properties by calling listProperties(path, null).listProperties
(String path, Map<String, String> context) Returns a snapshot of all properties by calling listProperties(path, null).listProperties
(String path, Map<String, String> context, Properties substitution) Returns a snapshot of all properties of this having a given path prefix Some sources of properties may not be list-able and will not be included in this snapshot.listProperties
(Map<String, String> context) Returns a snapshot of all properties of this - same as listProperties("", context).final void
set
(CompoundName name, Object value) Sets a value to the first chained instance which accepts it by calling set(name, value, null).void
Sets a value to the first chained instance which accepts it.final void
Sets a value to the first chained instance which accepts it by calling set(name, value, null).final void
Sets a value to the first chained instance which accepts it.
-
Constructor Details
-
Properties
public Properties()
-
-
Method Details
-
chain
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
Returns the properties chained to this, or null if this is the last in the chain -
getInstance
Returns the first instance of the given class in this chain, or null if none -
listProperties
Lists all properties of this with no context, by delegating to listProperties(""). -
listProperties
Returns a snapshot of all properties of this - same as listProperties("", context). -
listProperties
Returns a snapshot of all properties by calling listProperties(path, null). -
listProperties
Returns a snapshot of all properties by calling listProperties(path, null). -
listProperties
Returns a snapshot of all properties by calling listProperties(path, null). -
listProperties
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 prefix Some sources of properties may not be list-able 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 prefix Some sources of properties may not be list-able 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
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
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
Gets a named value from the first chained instance which has one by calling get(name,context,this). -
get
Gets a named value from the first chained instance which has one by calling get(name,context,this). -
get
Gets a named value from the first chained instance which has one by calling get(name,null,this). -
get
Gets a named value from the first chained instance which has one by calling get(name,null,this). -
get
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Returns this property as a string.- Returns:
- this property as a string, or null if the property is null
-
getString
Returns this property as a string.- Returns:
- this property as a string, or null if the property is null
-
getString
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
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
-
asString
-
getInteger
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
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
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
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
-
asInteger
-
getLong
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
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
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
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
-
asLong
-
getDouble
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
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
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
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
-
asDouble
-
clone
Clones this instance and recursively all chained instance. Implementations should call this and clone their own state as appropriate -
cloneMap
Clones a map by deep cloning each value which is cloneable and shallow copying all other values. -
clone
Clones this object if it is clonable, and the clone is public. Returns null if not.
-