Class Settings.Builder

java.lang.Object
org.apache.juneau.commons.settings.Settings.Builder
Enclosing class:
Settings

public static class Settings.Builder extends Object
Builder for creating Settings instances.
  • Constructor Details

  • Method Details

    • globalStore

      Sets the supplier for the global store.
      Parameters:
      supplier - The supplier for the global store. Must not be null. Can supply null to disable global store.
      Returns:
      This builder for method chaining.
    • localStore

      Sets the supplier for the local (per-thread) store.
      Parameters:
      supplier - The supplier for the local store. Must not be null.
      Returns:
      This builder for method chaining.
    • setSources

      Sets the sources list, replacing any existing sources.
      Parameters:
      sources - The sources to set. Must not be null or contain null elements.
      Returns:
      This builder for method chaining.
    • addSource

      Adds a source to the sources list.
      Parameters:
      source - The source to add. Must not be null.
      Returns:
      This builder for method chaining.
    • addSource

      Adds a functional source to the sources list.
      Parameters:
      source - The functional source to add. Must not be null.
      Returns:
      This builder for method chaining.
    • addTypeFunction

      public <T> Settings.Builder addTypeFunction(Class<T> type, Function<String,T> function)
      Registers a custom type conversion function for the specified type.

      This allows you to add support for converting string values to custom types when using Settings.get(String, Object). The function will be used to convert string values to the specified type.

      Example:

      // Register a custom converter for a custom type Settings custom = Settings.create() .addTypeFunction(Integer.class, Integer::valueOf) .addTypeFunction(MyCustomType.class, MyCustomType::fromString) .build(); // Now you can use get() with these types Integer intValue = custom.get("my.int.property", 0); MyCustomType customValue = custom.get("my.custom.property", MyCustomType.DEFAULT);

      Type Parameters:
      T - The type to register a converter for.
      Parameters:
      type - The class type to register a converter for. Must not be null.
      function - The function that converts a string to the specified type. Must not be null.
      Returns:
      This builder for method chaining.
    • build

      public Settings build()
      Builds a Settings instance from this builder.
      Returns:
      A new Settings instance.