Package com.yahoo.processing.request
Class Properties
- java.lang.Object
-
- com.yahoo.processing.request.Properties
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
PropertyMap
public class Properties extends java.lang.Object implements java.lang.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(java.lang.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 java.lang.Double
asDouble(java.lang.Object value, java.lang.Double defaultValue)
protected java.lang.Integer
asInteger(java.lang.Object value, java.lang.Integer defaultValue)
protected java.lang.Long
asLong(java.lang.Object value, java.lang.Long defaultValue)
protected java.lang.String
asString(java.lang.Object value, java.lang.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 chainProperties
clone()
Clones this instance and recursively all chained instance.static java.lang.Object
clone(java.lang.Object object)
Clones this object if it is clonable, and the clone is public.static java.util.Map<CompoundName,java.lang.Object>
cloneMap(java.util.Map<CompoundName,java.lang.Object> map)
Clones a map by deep cloning each value which is cloneable and shallow copying all other values.java.lang.Object
get(CompoundName name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)java.lang.Object
get(CompoundName name, java.lang.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.java.lang.Object
get(CompoundName name, java.util.Map<java.lang.String,java.lang.String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)java.lang.Object
get(CompoundName name, java.util.Map<java.lang.String,java.lang.String> context, Properties substitution)
Gets a named value which (if necessary) is resolved using a property context.java.lang.Object
get(java.lang.String name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)java.lang.Object
get(java.lang.String name, java.lang.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.java.lang.Object
get(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)java.lang.Object
get(java.lang.String name, java.util.Map<java.lang.String,java.lang.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(java.lang.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(java.lang.String key, boolean defaultValue)
Gets a property as a boolean.java.lang.Double
getDouble(CompoundName name)
Returns a property as a Doublejava.lang.Double
getDouble(CompoundName name, java.lang.Double defaultValue)
Returns a property as a Doublejava.lang.Double
getDouble(java.lang.String name)
Returns a property as a Doublejava.lang.Double
getDouble(java.lang.String name, java.lang.Double defaultValue)
Returns a property as a Double<T extends Properties>
TgetInstance(java.lang.Class<T> propertyClass)
Returns the first instance of the given class in this chain, or null if nonejava.lang.Integer
getInteger(CompoundName name)
Returns a property as an Integerjava.lang.Integer
getInteger(CompoundName name, java.lang.Integer defaultValue)
Returns a property as an Integerjava.lang.Integer
getInteger(java.lang.String name)
Returns a property as an Integerjava.lang.Integer
getInteger(java.lang.String name, java.lang.Integer defaultValue)
Returns a property as an Integerjava.lang.Long
getLong(CompoundName name)
Returns a property as a Longjava.lang.Long
getLong(CompoundName name, java.lang.Long defaultValue)
Returns a property as a Longjava.lang.Long
getLong(java.lang.String name)
Returns a property as a Longjava.lang.Long
getLong(java.lang.String name, java.lang.Long defaultValue)
Returns a property as a Longjava.lang.String
getString(CompoundName key)
Returns this property as a stringjava.lang.String
getString(CompoundName key, java.lang.String defaultValue)
Returns this property as a stringjava.lang.String
getString(java.lang.String key)
Returns this property as a stringjava.lang.String
getString(java.lang.String key, java.lang.String defaultValue)
Returns this property as a stringjava.util.Map<java.lang.String,java.lang.Object>
listProperties()
Lists all properties of this with no context, by delegating to listProperties("")java.util.Map<java.lang.String,java.lang.Object>
listProperties(CompoundName path)
Returns a snapshot of all properties by calling listProperties(path,null)java.util.Map<java.lang.String,java.lang.Object>
listProperties(CompoundName path, java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties by calling listProperties(path,null)java.util.Map<java.lang.String,java.lang.Object>
listProperties(CompoundName path, java.util.Map<java.lang.String,java.lang.String> context, Properties substitution)
Returns a snapshot of all properties of this having a given path prefixjava.util.Map<java.lang.String,java.lang.Object>
listProperties(java.lang.String path)
Returns a snapshot of all properties by calling listProperties(path,null)java.util.Map<java.lang.String,java.lang.Object>
listProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties by calling listProperties(path,null)java.util.Map<java.lang.String,java.lang.Object>
listProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> context, Properties substitution)
Returns a snapshot of all properties of this having a given path prefixjava.util.Map<java.lang.String,java.lang.Object>
listProperties(java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties of this - same as listProperties("",context)void
set(CompoundName name, java.lang.Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).void
set(CompoundName name, java.lang.Object value, java.util.Map<java.lang.String,java.lang.String> context)
Sets a value to the first chained instance which accepts it.void
set(java.lang.String name, java.lang.Object value)
Sets a value to the first chained instance which accepts it by calling set(name,value,null).void
set(java.lang.String name, java.lang.Object value, java.util.Map<java.lang.String,java.lang.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(java.lang.Class<T> propertyClass)
Returns the first instance of the given class in this chain, or null if none
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties()
Lists all properties of this with no context, by delegating to listProperties("")
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties(java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties of this - same as listProperties("",context)
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties(CompoundName path)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties(java.lang.String path)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties(CompoundName path, java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public final java.util.Map<java.lang.String,java.lang.Object> listProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.String> context)
Returns a snapshot of all properties by calling listProperties(path,null)
-
listProperties
public java.util.Map<java.lang.String,java.lang.Object> listProperties(CompoundName path, java.util.Map<java.lang.String,java.lang.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 java.util.Map<java.lang.String,java.lang.Object> listProperties(java.lang.String path, java.util.Map<java.lang.String,java.lang.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 java.lang.Object get(CompoundName name, java.util.Map<java.lang.String,java.lang.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 java.lang.Object get(java.lang.String name, java.util.Map<java.lang.String,java.lang.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 java.lang.Object get(CompoundName name, java.util.Map<java.lang.String,java.lang.String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)
-
get
public final java.lang.Object get(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> context)
Gets a named value from the first chained instance which has one by calling get(name,context,this)
-
get
public final java.lang.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 java.lang.Object get(java.lang.String name)
Gets a named value from the first chained instance which has one by calling get(name,null,this)
-
get
public final java.lang.Object get(CompoundName name, java.lang.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 java.lang.Object get(java.lang.String name, java.lang.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, java.lang.Object value, java.util.Map<java.lang.String,java.lang.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 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 none- Throws:
java.lang.RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(java.lang.String name, java.lang.Object value, java.util.Map<java.lang.String,java.lang.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 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 none- Throws:
java.lang.RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(CompoundName name, java.lang.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 valuevalue
- the value to set. Setting a name to null explicitly is legal.- Throws:
java.lang.RuntimeException
- if no instance in the chain accepted this name-value pair
-
set
public final void set(java.lang.String name, java.lang.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 valuevalue
- the value to set. Setting a name to null explicitly is legal.- Throws:
java.lang.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(java.lang.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(java.lang.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(java.lang.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 java.lang.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 java.lang.String getString(java.lang.String key)
Returns this property as a string- Returns:
- this property as a string, or null if the property is null
-
getString
public final java.lang.String getString(CompoundName key, java.lang.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 java.lang.String getString(java.lang.String key, java.lang.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
-
asString
protected final java.lang.String asString(java.lang.Object value, java.lang.String defaultValue)
-
getInteger
public final java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a toString which is not parseable as a number
-
getInteger
public final java.lang.Integer getInteger(java.lang.String name)
Returns a property as an Integer- Returns:
- the integer value of the name, or null if the property is null
- Throws:
java.lang.NumberFormatException
- if the given parameter exists but have a toString which is not parseable as a number
-
getInteger
public final java.lang.Integer getInteger(CompoundName name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter does not exist or does not have a toString parseable as a number
-
getInteger
public final java.lang.Integer getInteger(java.lang.String name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter does not exist or does not have a toString parseable as a number
-
asInteger
protected final java.lang.Integer asInteger(java.lang.Object value, java.lang.Integer defaultValue)
-
getLong
public final java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final java.lang.Long getLong(java.lang.String name)
Returns a property as a Long- Returns:
- the long value of the name, or null if the property is null
- Throws:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final java.lang.Long getLong(CompoundName name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getLong
public final java.lang.Long getLong(java.lang.String name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
asLong
protected final java.lang.Long asLong(java.lang.Object value, java.lang.Long defaultValue)
-
getDouble
public final java.lang.Double getDouble(CompoundName name)
Returns a property as a Double- Returns:
- the integer value of the name, or null if the property is null
- Throws:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final java.lang.Double getDouble(java.lang.String name)
Returns a property as a Double- Returns:
- the integer value of the name, or null if the property is null
- Throws:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final java.lang.Double getDouble(CompoundName name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
getDouble
public final java.lang.Double getDouble(java.lang.String name, java.lang.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:
java.lang.NumberFormatException
- if the given parameter exists but have a value which is not parseable as a number
-
asDouble
protected final java.lang.Double asDouble(java.lang.Object value, java.lang.Double defaultValue)
-
clone
public Properties clone()
Clones this instance and recursively all chained instance. Implementations should call this and clone their own state as appropriate- Overrides:
clone
in classjava.lang.Object
-
cloneMap
public static java.util.Map<CompoundName,java.lang.Object> cloneMap(java.util.Map<CompoundName,java.lang.Object> map)
Clones a map by deep cloning each value which is cloneable and shallow copying all other values.
-
clone
public static java.lang.Object clone(java.lang.Object object)
Clones this object if it is clonable, and the clone is public. Returns null if not
-
-