Class ConfigBuilder<T>

  • Type Parameters:
    T - Type of the configuration.

    public class ConfigBuilder<T>
    extends java.lang.Object
    A builder for a generic Property-based configuration.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T build()
      Creates a new instance of the given Configuration class as defined by this builder with the information contained herein.
      void copyTo​(java.util.Map<java.lang.Object,​java.lang.Object> target)
      Copies the contents of this builder to the given target.
      ConfigBuilder<T> rebase​(java.util.Properties properties)
      Creates a new instance of the ConfigBuilder class that uses the given java.util.Properties object as a base.
      <V> ConfigBuilder<T> with​(Property<V> property, V value)
      Includes the given property and its value in the builder.
      ConfigBuilder<T> withUnsafe​(Property<?> property, java.lang.Object value)
      Includes the given property and its value in the builder, without Property-Value type-enforcement.
      • Methods inherited from class java.lang.Object

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

      • ConfigBuilder

        public ConfigBuilder​(java.lang.String namespace,
                             ConfigBuilder.ConfigConstructor<T> constructor)
        Creates a new instance of the ConfigBuilder class.
        Parameters:
        namespace - The configuration namespace to use.
        constructor - A Function that, given a TypedProperties object, returns a new instance of T using the given property values.
    • Method Detail

      • rebase

        public ConfigBuilder<T> rebase​(java.util.Properties properties)
        Creates a new instance of the ConfigBuilder class that uses the given java.util.Properties object as a base. This method does not touch the current instance.
        Parameters:
        properties - A java.util.Properties object to wrap.
        Returns:
        A new instance of the ConfigBuilder class with the same arguments as the current one, except that it uses the given Properties object.
      • with

        public <V> ConfigBuilder<T> with​(Property<V> property,
                                         V value)
        Includes the given property and its value in the builder.
        Type Parameters:
        V - Type of the property.
        Parameters:
        property - The property to set.
        value - The value of the property. This must be of the same type as accepted by the Property. In case a `null` value is sent, the value of the property will be set to empty string.
        Returns:
        This instance.
      • withUnsafe

        public ConfigBuilder<T> withUnsafe​(Property<?> property,
                                           java.lang.Object value)
        Includes the given property and its value in the builder, without Property-Value type-enforcement.
        Parameters:
        property - The property to set.
        value - The value of the property.
        Returns:
        This instance.
      • copyTo

        public void copyTo​(java.util.Map<java.lang.Object,​java.lang.Object> target)
        Copies the contents of this builder to the given target.
        Parameters:
        target - A Map to copy to.
      • build

        public T build()
                throws ConfigurationException
        Creates a new instance of the given Configuration class as defined by this builder with the information contained herein.
        Returns:
        The newly created instance.
        Throws:
        ConfigurationException - When a configuration issue has been detected. This can be: MissingPropertyException (a required Property is missing from the given properties collection), NumberFormatException (a Property has a value that is invalid for it).
        java.lang.NullPointerException - If any of the arguments are null.
        java.lang.IllegalArgumentException - If namespace is an empty string..