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 Details

    • Properties

      public Properties()
  • Method Details

    • 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 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 properties
      context - the context used to resolve the properties, or null if none
      substitution - 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 properties
      context - the context used to resolve the properties, or null if none
      substitution - 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 return
      context - the variant resolution context, or null if none
      substitution - 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 return
      context - the variant resolution context, or null if none
      substitution - 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 return
      defaultValue - 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 return
      defaultValue - 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 property
      value - 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 property
      value - 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 property
      value - 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 property
      value - 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 clear
      context - 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 clear
      context - 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 static 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 key
      defaultValue - 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 key
      defaultValue - the value to return if this property is null
      Returns:
      this property as a string
    • asString

      protected static String asString(Object value, String defaultValue)
    • 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 name
      defaultValue - 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 name
      defaultValue - 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

      protected static Integer asInteger(Object value, Integer defaultValue)
    • 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 name
      defaultValue - 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 name
      defaultValue - 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

      protected static Long asLong(Object value, Long defaultValue)
    • 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 name
      defaultValue - 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 name
      defaultValue - 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

      protected static Double asDouble(Object value, 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 class Object
    • 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.
    • clone

      public static Object clone(Object object)
      Clones this object if it is clonable, and the clone is public. Returns null if not.