Class TypedProperties


  • public class TypedProperties
    extends java.lang.Object
    * Wrapper for a java.util.Properties object, that sections it based on a namespace. Each property in the wrapped object will be prefixed by a namespace.

    Example:

    • foo.key1=value1
    • foo.key2=value2
    • bar.key1=value3
    • bar.key3=value4
    Indicate that namespace "foo" has Key-Values (key1=value1, key2=value2), and namespace "bar" has (key1=value3, key3=value4).
    • Constructor Summary

      Constructors 
      Constructor Description
      TypedProperties​(java.util.Properties properties, java.lang.String namespace)
      Creates a new instance of the TypedProperties class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String get​(Property<java.lang.String> property)
      Gets the value of a String property.
      boolean getBoolean​(Property<java.lang.Boolean> property)
      Gets the value of a boolean property.
      double getDouble​(Property<java.lang.Double> property)
      Gets the value of a Double property.
      java.time.Duration getDuration​(Property<java.lang.Integer> property, java.time.temporal.TemporalUnit unit)
      Gets a Duration from an Integer property only if it is greater than 0.
      <T extends java.lang.Enum<T>>
      T
      getEnum​(Property<T> property, java.lang.Class<T> enumClass)
      Gets the value of an Enumeration property.
      int getInt​(Property<java.lang.Integer> property)
      Gets the value of an Integer property.
      long getLong​(Property<java.lang.Long> property)
      Gets the value of a Long property.
      int getNonNegativeInt​(Property<java.lang.Integer> property)
      Gets the value of an Integer property only if it is non-negative (greater than or equal to 0).
      int getPositiveInt​(Property<java.lang.Integer> property)
      Gets the value of an Integer property only if it is greater than 0.
      long getPositiveLong​(Property<java.lang.Long> property)
      Gets the value of an Long property only if it is greater than 0.
      • Methods inherited from class java.lang.Object

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

      • TypedProperties

        public TypedProperties​(java.util.Properties properties,
                               java.lang.String namespace)
        Creates a new instance of the TypedProperties class.
        Parameters:
        properties - The java.util.Properties to wrap.
        namespace - The namespace of this instance.
    • Method Detail

      • get

        public java.lang.String get​(Property<java.lang.String> property)
                             throws ConfigurationException
        Gets the value of a String property.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set.
      • getInt

        public int getInt​(Property<java.lang.Integer> property)
                   throws ConfigurationException
        Gets the value of an Integer property.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as an Integer.
      • getLong

        public long getLong​(Property<java.lang.Long> property)
                     throws ConfigurationException
        Gets the value of a Long property.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Long.
      • getDouble

        public double getDouble​(Property<java.lang.Double> property)
                         throws ConfigurationException
        Gets the value of a Double property.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Double.
      • getEnum

        public <T extends java.lang.Enum<T>> T getEnum​(Property<T> property,
                                                       java.lang.Class<T> enumClass)
                                                throws ConfigurationException
        Gets the value of an Enumeration property.
        Type Parameters:
        T - Type of Enumeration.
        Parameters:
        property - The Property to get.
        enumClass - Class defining return type.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as the given Enum.
      • getBoolean

        public boolean getBoolean​(Property<java.lang.Boolean> property)
                           throws ConfigurationException
        Gets the value of a boolean property. Notes:
        • "true", "yes" and "1" (case insensitive) map to boolean "true".
        • "false", "no" and "0" (case insensitive) map to boolean "false".
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a Boolean.
      • getPositiveInt

        public int getPositiveInt​(Property<java.lang.Integer> property)
        Gets the value of an Integer property only if it is greater than 0.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Integer.
      • getNonNegativeInt

        public int getNonNegativeInt​(Property<java.lang.Integer> property)
        Gets the value of an Integer property only if it is non-negative (greater than or equal to 0).
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a non-negative Integer.
      • getPositiveLong

        public long getPositiveLong​(Property<java.lang.Long> property)
        Gets the value of an Long property only if it is greater than 0.
        Parameters:
        property - The Property to get.
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Long.
      • getDuration

        public java.time.Duration getDuration​(Property<java.lang.Integer> property,
                                              java.time.temporal.TemporalUnit unit)
        Gets a Duration from an Integer property only if it is greater than 0.
        Parameters:
        property - The Property to get.
        unit - Temporal unit related to the value associated to this property (i.e, seconds, millis).
        Returns:
        The property value or default value, if no such is defined in the base Properties.
        Throws:
        ConfigurationException - When the given property name does not exist within the current component and the property does not have a default value set, or when the property cannot be parsed as a positive Integer.