Interface RuntimeProperties


@Immutable public interface RuntimeProperties
  • Field Details

  • Method Details

    • create

      static RuntimeProperties.Builder create()
      Create a new configuration builder.
      Returns:
      the configuration builder
    • copy

      Create a new configuration builder that starts with a copy of the supplied configuration.
      Parameters:
      config - the configuration to copy; may be null
      Returns:
      the configuration builder
    • from

      static RuntimeProperties from(Properties properties)
      Obtain a configuration instance by copying the supplied Properties object. The supplied Properties object is copied so that the resulting Configuration cannot be modified.
      Parameters:
      properties - the properties; may be null or empty
      Returns:
      the configuration; never null
    • from

      static RuntimeProperties from(Map<String,?> properties)
      Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.
      Parameters:
      properties - the properties; may be null or empty
      Returns:
      the configuration; never null
    • from

      static <T> RuntimeProperties from(Map<String,T> properties, Function<T,String> conversion)
      Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.
      Parameters:
      properties - the properties; may be null or empty
      conversion - the function that converts the supplied values into strings, or returns null if the value is to be excluded
      Returns:
      the configuration; never null
    • load

      static RuntimeProperties load(URL url) throws IOException
      Obtain a configuration instance by loading the Properties from the supplied URL.
      Parameters:
      url - the URL to the stream containing the configuration properties; may not be null
      Returns:
      the configuration; never null
      Throws:
      IOException - if there is an error reading the stream
    • load

      static RuntimeProperties load(File file) throws IOException
      Obtain a configuration instance by loading the Properties from the supplied file.
      Parameters:
      file - the file containing the configuration properties; may not be null
      Returns:
      the configuration; never null
      Throws:
      IOException - if there is an error reading the stream
    • load

      static RuntimeProperties load(InputStream stream) throws IOException
      Obtain a configuration instance by loading the Properties from the supplied stream.
      Parameters:
      stream - the stream containing the properties; may not be null
      Returns:
      the configuration; never null
      Throws:
      IOException - if there is an error reading the stream
    • keys

      Set<String> keys()
      Get the set of keys in this configuration.
      Returns:
      the set of keys; never null but possibly empty
    • getString

      String getString(String key)
      Get the string value associated with the given key.
      Parameters:
      key - the key for the configuration property
      Returns:
      the value, or null if the key is null or there is no such key-value pair in the configuration
    • getBoolean

      default boolean getBoolean(Property property)
      Get the boolean value associated with the given field when that field has a default value. If the configuration does not have a name-value pair with the same name as the field, then the field's default value.
      Parameters:
      property - the property
      Returns:
      the boolean value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
      Throws:
      NumberFormatException - if there is no name-value pair and the field has no default value
    • getBoolean

      default boolean getBoolean(String key, BooleanSupplier defaultValueSupplier)
      Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.
      Parameters:
      key - the key for the configuration property
      defaultValueSupplier - the supplier for the default value; may be null
      Returns:
      the boolean value, or null if the key is null, there is no such key-value pair in the configuration, the defaultValueSupplier reference is null, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
    • asProperties

      default Properties asProperties()
      Get a copy of these configuration properties as a Properties object.
      Returns:
      the properties object; never null
    • asMap

      default Map<String,String> asMap()
      Get a copy of these configuration properties as a Properties object.
      Returns:
      the properties object; never null
    • forEach

      default <T> void forEach(BiConsumer<String,String> function)
      Call the supplied function for each of the fields.
      Parameters:
      function - the consumer that takes the field name and the string value extracted from the field; may not be null