Class Setting<T>

java.lang.Object
org.apache.juneau.commons.function.ResettableSupplier<T>
org.apache.juneau.commons.settings.Setting<T>
Type Parameters:
T - The type of value supplied.
All Implemented Interfaces:
Supplier<T>, OptionalSupplier<T>
Direct Known Subclasses:
StringSetting

public class Setting<T> extends ResettableSupplier<T>
A resettable supplier that provides convenience methods for type conversion.

This class extends ResettableSupplier to provide methods to convert the string value to various types, similar to the StringSetting.asInteger(), StringSetting.asBoolean(), etc. methods.

Example:

StringSetting setting = Settings.get().setting("my.property"); Setting<Integer> intValue = setting.asInteger(); Setting<Boolean> boolValue = setting.asBoolean(); Setting<Charset> charset = setting.asCharset(); // Reset the cache to force recomputation setting.reset();

  • Constructor Details

    • Setting

      public Setting(Settings settings, Supplier<T> supplier)
      Creates a new Setting from a Settings instance and a Supplier.
      Parameters:
      settings - The Settings instance that created this setting. Must not be null.
      supplier - The supplier that provides the value. Must not be null.
  • Method Details

    • getSettings

      Returns the Settings instance that created this setting.
      Returns:
      The Settings instance.
    • asOptional

      public Optional<T> asOptional()
      Returns the underlying Optional<T>.

      Note: The returned Optional is a snapshot-in-time of the current value. Resetting this Setting will not affect the returned Optional instance. To get an updated value after resetting, call this method again.

      Returns:
      The optional value.
    • map

      public <U> Setting<U> map(Function<? super T,? extends U> mapper)
      If a value is present, applies the provided mapping function to it and returns a Setting describing the result.

      The returned Setting maintains its own cache, independent of this supplier. Resetting the mapped supplier does not affect this supplier, and vice versa.

      Specified by:
      map in interface OptionalSupplier<T>
      Overrides:
      map in class ResettableSupplier<T>
      Type Parameters:
      U - The type of the result of the mapping function.
      Parameters:
      mapper - A mapping function to apply to the value, if present. Must not be null.
      Returns:
      A Setting describing the result of applying a mapping function to the value of this Setting, if a value is present, otherwise an empty Setting.
    • filter

      public Setting<T> filter(Predicate<? super T> predicate)
      If a value is present, and the value matches the given predicate, returns a Setting describing the value, otherwise returns an empty Setting.

      The returned Setting maintains its own cache, independent of this supplier. Resetting the filtered supplier does not affect this supplier, and vice versa.

      Specified by:
      filter in interface OptionalSupplier<T>
      Overrides:
      filter in class ResettableSupplier<T>
      Parameters:
      predicate - A predicate to apply to the value, if present. Must not be null.
      Returns:
      A Setting describing the value of this Setting if a value is present and the value matches the given predicate, otherwise an empty Setting.