Package

de.h2b.scala.lib.util

config

Permalink

package config

This package provides various configuration sources under a common trait Config, which is basically an immutable map. The following implementations are available:

- ArgsConfig loads key/value pairs from an array of strings: array elements that contain a separator char (defined by ArgsConfig.SeparatorChar) are considered as key/value pairs, while elements not consumed by this rule can be retrieved by the remaining array (makes it suitable to scan a command line for such key/value pairs and parsing the rest with tools like described in [U1 Command-Line Interface](#u1-command-line-interface).

- FileConfig loads key/value pairs from a specified resource file which must conform to the java.util.Properties#load(InputStream) method; there is also a factory method where the resource is looked up under the modified package name of a specified class.

- BundleConfig loads key/value pairs from a resource bundle (according to the java.util.ResourceBundle class) of a specified base name using a locale option; there is also a factory method where the resource bundle is looked up under the modified package name of a specified class.

* SystemPropertiesConfig is a Config object that represents the system properties of the JVM.

* SystemEnvironmentConfig is a Config object that represents the system environment; note that the system may not support environment variables -- in this case, this object is empty.

Multiple Configs can be combined using the standard map ++ operators, yielding an overall Config.

Example:
  1. import de.h2b.scala.lib.util.config._
    val argsConfig = ArgsConfig("-x key1=val1 /y key2=val2 abc".split(' '))
    val sysConfig = SystemPropertiesConfig
    val otherConfig = Config("one"->1, "two"->2, "three"->3)
    val config = argsConfig ++ sysConfig ++ otherConfig
    println(config.get("key1")) //> Some(val1)
    println(config.get("java.version")) //> Some(1.8.0_121)
    println(config.get("two")) //> Some(2)
    println(argsConfig.remaining.mkString(" ")) //> -x /y abc
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. config
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class ArgsConfig extends Config[String, String]

    Permalink

    A Config that loads key/value pairs from an args array.

    A Config that loads key/value pairs from an args array.

    Only elements that contain a separator char (defined by ArgsConfig.SeparatorChar) are considered as a key/value pair. The substring before the first separator char is the key, everything after it is the value (even if contains more separator chars).

    Elements not consumed by this rule can be retrieved by the remaining array.

    Note

    According to the rule, one or both parts of a key/value pair may be the empty string.

  2. class BundleConfig extends Config[String, String]

    Permalink

    A Config that loads key/value pairs from a resource bundle

    A Config that loads key/value pairs from a resource bundle

    Note

    If some I/O or other exception occurs when loading the bundle, the resulting Config is empty.

    ,

    All values must be strings.

    ,

    The base name must identify a resource bundle according to the java.util.ResourceBundle class.

  3. trait Config[Key, Value] extends Map[Key, Value] with MapLike[Key, Value, Config[Key, Value]]

    Permalink

    An immutable type that provides configuration properties as a map of key/value pairs.

    An immutable type that provides configuration properties as a map of key/value pairs.

    Note

    This variant of the source code is for Scala up until version 2.12.

  4. class FileConfig extends Config[String, String]

    Permalink

    A Config that loads key/value pairs from a single properties file.

    A Config that loads key/value pairs from a single properties file.

    Note

    If some I/O or other exception occurs when loading the file, the resulting Config is empty.

    ,

    The content of the file must conform to the java.util.Properties#load(InputStream) method.

Value Members

  1. object ArgsConfig

    Permalink
  2. object BundleConfig

    Permalink
  3. object Config

    Permalink
  4. object FileConfig

    Permalink
  5. object SystemEnvironmentConfig extends Config[String, String]

    Permalink

    A Config that represents the system environment.

    A Config that represents the system environment.

    Note

    If a security manager exists and doesn't allow access to the process environment, this config object is empty.

    ,

    The system may not support environment variables. In this case, this config object is empty.

  6. object SystemPropertiesConfig extends Config[String, String]

    Permalink

    A Config that represents the system properties of the JVM.

    A Config that represents the system properties of the JVM.

    Note

    If a security manager exists and doesn't allow access to the system properties, this config object is empty.

Inherited from AnyRef

Inherited from Any

Ungrouped