Interface FunctionalSource
- All Superinterfaces:
SettingSource
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
SettingSource instances from a function.
This functional interface allows you to create setting sources directly from lambda expressions or method references,
making it easy to wrap existing property sources (e.g., System.getProperty(String),
System.getenv(String)) as SettingSource instances.
Functional sources are read-only and do not implement SettingStore. If you need a writable source,
use MapStore or FunctionalStore instead.
Return Value Semantics:
- If the function returns
null , this source returnsnull (key doesn't exist). - If the function returns a non-null value, this source returns
Optional.of(value) .
Note: This source cannot distinguish between a key that doesn't exist and a key that exists with a null value,
since the function only returns a MapStore instead.
Example:
-
Method Summary
-
Method Details
-
get
Returns a setting by applying the function.If the function returns
null , this method returnsnull (indicating the key doesn't exist). If the function returns a non-null value, this method returnsOptional.of(value) .- Specified by:
getin interfaceSettingSource- Parameters:
name- The property name.- Returns:
- The property value, or
null if the function returnsnull .
-
of
Creates a functional source from a function that returns a string.This is a convenience factory method for creating functional sources from functions that return
String values. The function's return value is converted to anOptional as follows:- If the function returns
null , the source returnsnull (key doesn't exist). - If the function returns a non-null value, the source returns
Optional.of(value) .
Example:
// Create from a lambda FunctionalSourcesource1 = FunctionalSource.of (name -> System.getProperty(name));// Create from a method reference FunctionalSourcesource2 = FunctionalSource.of (System::getProperty);- Parameters:
function- The function to delegate property lookups to. Must not benull .- Returns:
- A new functional source instance.
- If the function returns
-