Class 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 chain
      void clearAll​(CompoundName name)
      Sets all properties having this name as a compound prefix to null.
      void clearAll​(CompoundName name, java.util.Map<java.lang.String,​java.lang.String> context)
      Sets all properties having this name as a compound prefix to null.
      void clearAll​(java.lang.String name)
      Sets all properties having this name as a compound prefix to null.
      void clearAll​(java.lang.String name, java.lang.Object value, java.util.Map<java.lang.String,​java.lang.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 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 context
      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​(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 Double
      java.lang.Double getDouble​(CompoundName name, java.lang.Double defaultValue)
      Returns a property as a Double
      java.lang.Double getDouble​(java.lang.String name)
      Returns a property as a Double
      java.lang.Double getDouble​(java.lang.String name, java.lang.Double defaultValue)
      Returns a property as a Double
      <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
      java.lang.Integer getInteger​(CompoundName name)
      Returns a property as an Integer
      java.lang.Integer getInteger​(CompoundName name, java.lang.Integer defaultValue)
      Returns a property as an Integer
      java.lang.Integer getInteger​(java.lang.String name)
      Returns a property as an Integer
      java.lang.Integer getInteger​(java.lang.String name, java.lang.Integer defaultValue)
      Returns a property as an Integer
      java.lang.Long getLong​(CompoundName name)
      Returns a property as a Long
      java.lang.Long getLong​(CompoundName name, java.lang.Long defaultValue)
      Returns a property as a Long
      java.lang.Long getLong​(java.lang.String name)
      Returns a property as a Long
      java.lang.Long getLong​(java.lang.String name, java.lang.Long defaultValue)
      Returns a property as a Long
      java.lang.String getString​(CompoundName key)
      Returns this property as a string
      java.lang.String getString​(CompoundName key, java.lang.String defaultValue)
      Returns this property as a string
      java.lang.String getString​(java.lang.String key)
      Returns this property as a string
      java.lang.String getString​(java.lang.String key, java.lang.String defaultValue)
      Returns this property as a string
      java.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 prefix
      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)
      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 prefix
      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)
      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.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Properties

        public Properties()
    • 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 prefix

        Some 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 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 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 prefix

        Some 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 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 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 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 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 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 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 return
        defaultValue - 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 return
        defaultValue - 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 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:
        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 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:
        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 property
        value - the value to set. Setting a property to null clears it.
        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 property
        value - the value to set. Setting a property to null clears it.
        Throws:
        java.lang.RuntimeException - if no instance in the chain accepted this name-value pair
      • clearAll

        public void clearAll​(CompoundName name,
                             java.util.Map<java.lang.String,​java.lang.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:
        java.lang.RuntimeException - if no instance in the chain accepted this name-value pair
      • clearAll

        public final void clearAll​(java.lang.String name,
                                   java.lang.Object value,
                                   java.util.Map<java.lang.String,​java.lang.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:
        java.lang.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:
        java.lang.RuntimeException - if no instance in the chain accepted this name-value pair
      • clearAll

        public final void clearAll​(java.lang.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:
        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 key
        defaultValue - 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 key
        defaultValue - 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 name
        defaultValue - 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 name
        defaultValue - 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 name
        defaultValue - 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 name
        defaultValue - 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 double 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 double 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 name
        defaultValue - 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 name
        defaultValue - 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 class java.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