Interface LoaderOptionSource


public interface LoaderOptionSource
A provider for ConfigurationLoader options.

This allows initializing a loader from sources like system properties, environment variables, or an existing configuration node.

To allow working with primitive value sources, only scalar values are supported.

Since:
4.2.0
  • Method Details

    • environmentVariables

      Retrieve loader options from environment variables.

      When reading environment variables, property keys will be converted to upper case and joined by '_' (an underscore).

      This source will use a default prefix of CONFIGURATE.

      Returns:
      a source retrieving options from environment variables
      Since:
      4.2.0
    • environmentVariables

      Retrieve loader options from environment variables.

      When reading environment variables, property keys will be converted to upper case and joined by '_' (an underscore).

      Parameters:
      prefix - the prefix to prepend to option paths
      Returns:
      a source retrieving options from environment variables
      Since:
      4.2.0
    • systemProperties

      Retrieve loader options from system properties.

      When reading system properties, property keys will be joined by '.' (a dot).

      This source will use a default prefix of configurate.

      Returns:
      a source retrieving options from system properties
      Since:
      4.2.0
    • systemProperties

      Retrieve loader options from system properties.

      When reading system properties, property keys will be joined by '.' (a dot).

      Parameters:
      prefix - the prefix to prepend to option paths
      Returns:
      a source retrieving options from system properties
      Since:
      4.2.0
    • node

      Create an option source that will read from an existing configuration node.

      Option paths will be converted directly to node paths.

      Parameters:
      node - the node to read options from
      Returns:
      a source retrieving options from the provided node
      Since:
      4.2.0
    • composite

      Create an option source that will try the provided sources in order.

      The first source with a present value will be used.

      Parameters:
      sources - the option sources to delegate to
      Returns:
      a new option source
      Since:
      4.2.0
    • get

      @Nullable String get(String... path)
      Get the value at the provided path.
      Parameters:
      path - the path for options.
      Returns:
      a value, or null if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getOr

      default String getOr(String defaultValue, String... path)
      Get the value at the provided path.

      If no value is present, defaultValue will be returned.

      Parameters:
      path - the path for options.
      defaultValue - the value to return if none is present
      Returns:
      a value, or defaultValue if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getEnum

      default <T extends Enum<T>> @Nullable T getEnum(Class<T> enumClazz, String... path)
      Get the value at the provided path as an enum constant.
      Type Parameters:
      T - enum type
      Parameters:
      enumClazz - the enum type's class
      path - the path for options.
      Returns:
      a value, or null if none is present or the provided value is not a member of the enum
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getEnum

      default <T extends Enum<T>> T getEnum(Class<T> enumClazz, T defaultValue, String... path)
      Get the value at the provided path as an enum constant.

      If no value is present or the provided value is not a known enum constant, defaultValue will be returned.

      Type Parameters:
      T - enum type
      Parameters:
      enumClazz - the enum type's class
      path - the path for options.
      defaultValue - the value to return if none is present
      Returns:
      a value, or defaultValue if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getInt

      default int getInt(int defaultValue, String... path)
      Get the value at the provided path as an integer.

      If no value is present or the value is not a valid integer, defaultValue will be returned.

      Parameters:
      path - the path for options.
      defaultValue - the value to return if none is available
      Returns:
      a value, or defaultValue if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getDouble

      default double getDouble(double defaultValue, String... path)
      Get the value at the provided path as a double.

      If no value is present or the value is not a valid double, defaultValue will be returned.

      Parameters:
      path - the path for options.
      defaultValue - the value to return if none is available
      Returns:
      a value, or defaultValue if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0
    • getBoolean

      default boolean getBoolean(boolean defaultValue, String... path)
      Get the value at the provided path as a boolean.

      If no value is present or the value is not a valid boolean, defaultValue will be returned.

      Parameters:
      path - the path for options.
      defaultValue - the value to return if none is available
      Returns:
      a value, or defaultValue if none is present
      Throws:
      IllegalArgumentException - if the provided path is an empty array
      Since:
      4.2.0