- All Implemented Interfaces:
Provider
AbstractProvider that can return Values backed
by System properties.
While System properties are often casually assumed to be stable
and String-typed, the exact opposite is true: System
properties may contain arbitrarily-typed Objects under
arbitrarily-typed keys, and the properties themselves may be replaced at any point.
This means that all Values supplied by this SystemPropertyProvider are non-deterministic and may change type and presence from one call
to another.
It is also worth mentioning explicitly that, deliberately, no type conversion of any System property value takes place in this class.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newSystemPropertyProviderthat uses flat keys, does not presume that the only things stored in the System properties areStrings, and honors the fact that System properties are mutable.SystemPropertyProvider(boolean flatKeys, boolean onlyStrings, boolean mutable) Creates a newSystemPropertyProvider. -
Method Summary
Modifier and TypeMethodDescriptionprotected Supplier<?>protected static final StringOverrides theAbstractProvider.path(Loader, Path)method to return a (relative)Pathconsisting solely of the last element of the suppliedabsolutePath.Methods inherited from class org.microbean.loader.spi.AbstractProvider
get, lowerBound
-
Constructor Details
-
SystemPropertyProvider
public SystemPropertyProvider()Creates a newSystemPropertyProviderthat uses flat keys, does not presume that the only things stored in the System properties areStrings, and honors the fact that System properties are mutable. -
SystemPropertyProvider
Creates a newSystemPropertyProvider.- Parameters:
flatKeys- whether the key for a system property is derived from aPath's last element's name onlyonlyStrings- whether all System properties are expected to beString-typedmutable- whether System properties should be treated as mutable (which they are, strictly speaking, but for many applications this may not matter in practice)
-
-
Method Details
-
find
Returns aSuppliersuitable for the System property represented by the suppliedPath.This method never returns
null. Its overrides may if they wish.The name of the last element of the supplied
Pathis taken to be the name of the System property value to retrieve. If the type erasure of the suppliedPath'squalified()method is assignable fromString.class, then calls will be made by the returnedValue'sget()method toSystem.getProperty(String)before simple calls toSystem.getProperties().get(String).Any
Supplierreturned by this method will be non-deterministic, since system properties may change at any point. Additionally, if the suppliedPath's type is not assignable from that borne by a System property value, then theSupplierwill returnnullfrom itsget()method in such a case, indicating that the value is present but cannot be represented. Overrides are strongly encouraged to abide by these conditions.- Specified by:
findin classAbstractProvider- Parameters:
requestor- theLoaderseeking aValue; must not benullabsolutePath- an absolutePathfor which aValueis being sought; must not benull- Returns:
- a
Suppliersuitable for the System property whose name is represented by the suppliedPath's lastElement's name - Throws:
NullPointerException- if an argument for either parameter isnull- See Also:
- Idempotency:
- This method is idempotent and deterministic.
Overrides must be idempotent, but need not be deterministic.
Suppliers returned by this method or its overrides are not guaranteed to be idempotent or deterministic. - Nullability:
- This method never returns
nullbut its overrides may. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
path
Overrides theAbstractProvider.path(Loader, Path)method to return a (relative)Pathconsisting solely of the last element of the suppliedabsolutePath.- Overrides:
pathin classAbstractProvider- Type Parameters:
T- the type of both the supplied and returnedPaths- Parameters:
requestor- theLoaderseeking aValue; must not benullabsolutePath- an absolutePathfor which aValueis being sought; must not benull- Returns:
- a
Paththat will be used to build aValueto be returned by theAbstractProvider.get(Loader, Path)method - See Also:
- Idempotency:
- This method is, and its overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, but overrides may, return
null. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
key
- Parameters:
path- thePathin question; must not benullflat- whether the key is derived from the suppliedPath's last element's name only- Returns:
- a
Stringrepresentation of the suppliedPath - Throws:
NullPointerException- ifpathisnull- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method never returns
null. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-