Class Settings.Builder
java.lang.Object
org.apache.juneau.commons.settings.Settings.Builder
- Enclosing class:
- Settings
Builder for creating Settings instances.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddSource(FunctionalSource source) Adds a functional source to the sources list.addSource(SettingSource source) Adds a source to the sources list.<T> Settings.BuilderaddTypeFunction(Class<T> type, Function<String, T> function) Registers a custom type conversion function for the specified type.build()Builds a Settings instance from this builder.globalStore(OptionalSupplier<SettingStore> supplier) Sets the supplier for the global store.localStore(OptionalSupplier<SettingStore> supplier) Sets the supplier for the local (per-thread) store.final Settings.BuildersetSources(SettingSource... sources) Sets the sources list, replacing any existing sources.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
globalStore
Sets the supplier for the global store.- Parameters:
supplier- The supplier for the global store. Must not benull . 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 benull .- Returns:
- This builder for method chaining.
-
setSources
Sets the sources list, replacing any existing sources.- Parameters:
sources- The sources to set. Must not benull or containnull elements.- Returns:
- This builder for method chaining.
-
addSource
Adds a source to the sources list.- Parameters:
source- The source to add. Must not benull .- Returns:
- This builder for method chaining.
-
addSource
Adds a functional source to the sources list.- Parameters:
source- The functional source to add. Must not benull .- Returns:
- This builder for method chaining.
-
addTypeFunction
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 Settingscustom = Settings.create () .addTypeFunction(Integer.class , Integer::valueOf) .addTypeFunction(MyCustomType.class , MyCustomType::fromString) .build();// Now you can use get() with these types IntegerintValue =custom .get("my.int.property" , 0); MyCustomTypecustomValue =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 benull .function- The function that converts a string to the specified type. Must not benull .- Returns:
- This builder for method chaining.
-
build
Builds a Settings instance from this builder.- Returns:
- A new Settings instance.
-