org.apache.tamaya.optional

## Class OptionalConfiguration

- java.lang.Object
- - org.apache.tamaya.optional.OptionalConfiguration

-     public final class OptionalConfiguration
      extends Object

  Simplified configuration API, that can be used by code that only wants Tamaya to optionally enhance its configuration mechanism, but by default uses its own configuration by default.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ValueProvider` | `DEFAULT_PROVIDER` Default value provider returning Strings from system properties and the system environment.
    `static ValueProvider` | `NULLPROVIDER` Default value provider that always returns `null`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `get(String key)` Access a String value.
    `<T> T` | `get(String key, Class<T> type)` Method that returns the corresponding value, depending on the availability of Tamaya, the registered provider and evaluation policy.
    `<T> T` | `getOrDefault(String key, Class<T> type, T defaultValue)` Access a String value.
    `String` | `getOrDefault(String key, String defaultValue)` Access a String value.
    `static OptionalConfiguration` | `of(EvaluationPolicy policy)` Returns a default instance, which uses a default provider returning values from system properties and environment only.
    `static OptionalConfiguration` | `of(EvaluationPolicy policy, ValueProvider provider)` Returns an instance of OptionalConfiguration, which uses the given provider and policy for evaluating the values.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PROVIDER

          public static final ValueProvider DEFAULT_PROVIDER

      Default value provider returning Strings from system properties and the system environment. In all other cases `null` is returned.

    - #### NULLPROVIDER

          public static final ValueProvider NULLPROVIDER

      Default value provider that always returns `null`.

  - ### Method Detail

    - #### of

          public static OptionalConfiguration of(EvaluationPolicy policy,
                                 ValueProvider provider)

      Returns an instance of OptionalConfiguration, which uses the given provider and policy for evaluating the values.
      Parameters:
        `policy` - the policy how a value should be evaluated depending if Tamaya is available or not.
        `provider` - the non Tamaya-based provider to be used to evaluate values.
      Returns:
        a default OptionalConfiguration instance, never null.

    - #### of

          public static OptionalConfiguration of(EvaluationPolicy policy)

      Returns a default instance, which uses a default provider returning values from system properties and environment only.
      Parameters:
        `policy` - the policy how a value should be evaluated depending if Tamaya is available or not.
      Returns:
        a default OptionalConfiguration instance, never null.

    - #### get

          public String get(String key)

      Access a String value.
      Parameters:
        `key` - the key, not null.
      Returns:
        the value found, or null.

    - #### getOrDefault

          public String getOrDefault(String key,
                            String defaultValue)

      Access a String value.
      Parameters:
        `key` - the key, not null.
        `defaultValue` - the default value, returned if no such key is found in the configuration.
      Returns:
        the value found, or null.

    - #### get

          public <T> T get(String key,
                  Class<T> type)

      Method that returns the corresponding value, depending on the availability of Tamaya, the registered provider and evaluation policy.
      Type Parameters:
        `T` - the type param.
      Parameters:
        `key` - the key, not null.
        `type` - the target type, not null.
      Returns:
        the value, or null.

    - #### getOrDefault

          public <T> T getOrDefault(String key,
                           Class<T> type,
                           T defaultValue)

      Access a String value.
      Type Parameters:
        `T` - the type param.
      Parameters:
        `key` - the key, not null.
        `type` - the target type, not null.
        `defaultValue` - the default value, returned if no such key is found in the configuration.
      Returns:
        the value found, or null.

Copyright © 2014–2016 Apache Software Foundation. All rights reserved.