java.lang.Object
org.microbean.loader.spi.AbstractProvider
org.microbean.loader.spi.AbstractTreeBasedProvider<N>
- Type Parameters:
N
- the type of a node in the tree
- All Implemented Interfaces:
Provider
- Direct Known Subclasses:
JacksonProvider
,TypesafeConfigHoconProvider
An abstract
AbstractProvider
whose implementations are
built around tree structures of various kinds.- Author:
- Laird Nelson
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a newAbstractTreeBasedProvider
with no lower type bound.protected
AbstractTreeBasedProvider
(Type lowerTypeBound) Creates a newAbstractTreeBasedProvider
with the supplied lower type bound. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
Returnstrue
if the suppliednode
isnull
, absent or synthetic.protected final boolean
protected Supplier<?>
Returns a deterministicSupplier
suitable for the current request, represented by the suppliedabsolutePath
, as being executed by the suppliedLoader
, ornull
if no suchSupplier
is or ever will be suitable.protected abstract N
Returns the child node of the supplied parentnode
identified by the suppliedindex
, ornull
if either the child does not exist ornode
is not a list node.protected abstract N
Returns the child node of the supplied parentnode
identified by the suppliedname
, ornull
if either the child does not exist ornode
is not a map node.protected abstract boolean
Returnstrue
if the suppliednode
represents a list or an array, and therefore theget(Object, int)
method is likely to be relevant.protected abstract boolean
Returnstrue
if the suppliednode
represents a map, and therefore theget(Object, String)
method is likely to be relevant.Returns anIterator
over the names of the suppliednode
's child nodes, or an emptyIterator
if the suppliednode
is not a map node.protected abstract boolean
Returnstrue
if the suppliednode
isnull
or represents an explicitly setnull
value.Calls thepath(Loader, Path, BiFunction)
method with the supplied arguments and the return value of an invocation of thereader(Loader, Path)
method and returns its result.Returns aPath
for a newValue
that will be returned by theAbstractProvider.get(Loader, Path)
method.protected Qualifiers<? extends String,
?> qualifiers
(BiFunction<? super N, ? super Type, ?> reader, N qualifiersNode, String nextPathElementName) Returns aQualifiers
derived from the suppliedqualifiersNode
.protected abstract N
qualifiers
(N node) Returns a node possibly containing qualifiers applicable to the supplied node, ornull
.protected abstract BiFunction<? super N,
? super Type, ?> Returns aBiFunction
accepting a node and aType
and returning the result of reading an object of that type, ornull
if no suchBiFunction
could be sourced.protected abstract N
protected abstract int
Returns the number of child nodes the suppliednode
has, which may be (and often is)0
.Methods inherited from class org.microbean.loader.spi.AbstractProvider
get, lowerBound
-
Constructor Details
-
AbstractTreeBasedProvider
protected AbstractTreeBasedProvider()Creates a newAbstractTreeBasedProvider
with no lower type bound. -
AbstractTreeBasedProvider
Creates a newAbstractTreeBasedProvider
with the supplied lower type bound.- Parameters:
lowerTypeBound
- the lower type bound; may benull
-
-
Method Details
-
size
Returns the number of child nodes the suppliednode
has, which may be (and often is)0
.If the supplied
null
isnull
, absent or a scalar, an override of this method must return0
.- Parameters:
node
- the parent node; may benull
in which case0
must be returned- Returns:
- the number of child nodes the supplied
node
has, which may be (and often is)0
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
names
Returns anIterator
over the names of the suppliednode
's child nodes, or an emptyIterator
if the suppliednode
is not a map node.- Parameters:
node
- the parent node; may benull
in which case an emptyIterator
must be returned- Returns:
- an
Iterator
; nevernull
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method must not return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
get
Returns the child node of the supplied parentnode
identified by the suppliedname
, ornull
if either the child does not exist ornode
is not a map node.- Parameters:
node
- the parent node; may benull
in which casenull
must be returnedname
- the name of the child; must not benull
- Returns:
- the child node of the supplied parent
node
identified by the suppliedname
, ornull
if either the child does not exist ornode
is not a map node - Throws:
NullPointerException
- ifname
isnull
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may (and often do) return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
get
Returns the child node of the supplied parentnode
identified by the suppliedindex
, ornull
if either the child does not exist ornode
is not a list node.- Parameters:
node
- the parent node; may benull
in which casenull
must be returnedindex
- the zero-based index of the child- Returns:
- the child node of the supplied parent
node
identified by the suppliedname
, ornull
if either the child does not exist ornode
is not a map node - Throws:
NullPointerException
- ifname
isnull
IndexOutOfBoundsException
- ifindex
is invalid- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may (and often do) return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
absent
Returnstrue
if the suppliednode
isnull
, absent or synthetic.- Parameters:
node
- the node to test; may benull
in which casetrue
must be returned- Returns:
true
if the suppliednode
isnull
, absent or synthetic- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
nil
Returnstrue
if the suppliednode
isnull
or represents an explicitly setnull
value.- Parameters:
node
- the node to test; may benull
in which casetrue
must be returned- Returns:
true
if the suppliednode
isnull
or represents an explicitly setnull
value- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
map
Returnstrue
if the suppliednode
represents a map, and therefore theget(Object, String)
method is likely to be relevant.- Parameters:
node
- the node to test; may benull
in which casefalse
must be returned- Returns:
true
if the suppliednode
represents a map, and therefore theget(Object, String)
method is likely to be relevant- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
list
Returnstrue
if the suppliednode
represents a list or an array, and therefore theget(Object, int)
method is likely to be relevant.- Parameters:
node
- the node to test; may benull
in which casefalse
must be returned- Returns:
true
if the suppliednode
represents a list or an array, and therefore theget(Object, int)
method is likely to be relevant- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
container
- Parameters:
node
- the node to test; may benull
in which casefalse
must be returned- Returns:
true
ifnode
is either a map or a list or array- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
reader
protected abstract BiFunction<? super N,? super Type, reader?> (Loader<?> requestor, Path<? extends Type> absolutePath) Returns aBiFunction
accepting a node and aType
and returning the result of reading an object of that type, ornull
if no suchBiFunction
could be sourced.- Parameters:
requestor
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolute- Returns:
- a
BiFunction
accepting a node and aType
and returning the result of reading an object of that type, ornull
if no suchBiFunction
could be sourced - Throws:
NullPointerException
- if any argument isnull
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
rootNode
Returns the root node of the tree that is suitable for the suppliedLoader
andPath
, ornull
if no tree is suitable.- Parameters:
requestor
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolute- Returns:
- the root node, or
null
- Throws:
NullPointerException
- if any argument isnull
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may return
null
. - Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
qualifiers
Returns a node possibly containing qualifiers applicable to the supplied node, ornull
.- Parameters:
node
- the node for which a corresponding qualifiers node should be returned; may benull
in which casenull
must be returned- Returns:
- a node possibly containing qualifiers applicable to the
supplied node, or
null
- Idempotency:
- Overrides of this method must be idempotent and deterministic.
- Nullability:
- Overrides of this method may (and often do) return
null
- Thread Safety:
- Overrides of this method must be safe for concurrent use by multiple threads.
-
find
Returns a deterministicSupplier
suitable for the current request, represented by the suppliedabsolutePath
, as being executed by the suppliedLoader
, ornull
if no suchSupplier
is or ever will be suitable.- Specified by:
find
in classAbstractProvider
- Parameters:
requestor
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolute- Returns:
- a
Supplier
, ornull
- Throws:
NullPointerException
- if any argument isnull
- See Also:
- Idempotency:
- No guarantees are made of either idempotency or determinism, either of this implementation or of its overrides.
- Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
path
Calls thepath(Loader, Path, BiFunction)
method with the supplied arguments and the return value of an invocation of thereader(Loader, Path)
method and returns its result.- Overrides:
path
in classAbstractProvider
- Type Parameters:
T
- the type of both the supplied and returnedPath
s- Parameters:
requestor
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolute- Returns:
- a
Path
that will be used to build aValue
to be returned by theAbstractProvider.get(Loader, Path)
method; ifnull
, then theAbstractProvider.get(Loader, Path)
method will returnnull
as well - Throws:
NullPointerException
- ifabsolutePath
orreader
isnull
- See Also:
- Idempotency:
- No guarantees about idempotency or determinism are made of this method.
- Nullability:
- This method does not return
null
. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
path
protected <T extends Type> Path<T> path(Loader<?> requestor, Path<T> absolutePath, BiFunction<? super N, ? super Type, ?> reader) Returns aPath
for a newValue
that will be returned by theAbstractProvider.get(Loader, Path)
method.The default implementation of this method attempts to build a
Path
with the same sizze as the suppliedPath
and differing, perhaps, only in theQualifiers
assigned to eachPath.Element
.Overrides of this method must not call the
path(Loader, Path)
or theAbstractProvider.get(Loader, Path)
methods or undefined behavior, such as an infinite loop, may result.- Type Parameters:
T
- the type of the suppliedPath
and the returnedPath
- Parameters:
requestor
- theLoader
currently executing a request; must not benull
absolutePath
- the path being requested; must not benull
and must be absolutereader
- aBiFunction
accepting a node and aType
and returning the result of reading an object of that type; may benull
- Returns:
- a
Path
; nevernull
; sometimes simply the suppliedabsolutePath
- Throws:
NullPointerException
- ifabsolutePath
orreader
isnull
- Idempotency:
- No guarantees about idempotency or determinism are made of this method or its overrides.
- Nullability:
- This method does not, and its overrides must not,
return
null
. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-
qualifiers
protected Qualifiers<? extends String,?> qualifiers(BiFunction<? super N, ? super Type, ?> reader, N qualifiersNode, String nextPathElementName) Returns aQualifiers
derived from the suppliedqualifiersNode
.- Parameters:
reader
- aBiFunction
accepting a node and aType
and returning the result of reading an object of that type; may benull
qualifiersNode
- a node containing qualifier entries; may benull
nextPathElementName
- the name of the next path element; may benull
- Returns:
- a
Qualifiers
; nevernull
- Idempotency:
- This method is, and its overrides must be, idempotent and deterministic.
- Nullability:
- This method does not, and its overrides must not,
return
null
. - Thread Safety:
- This method is, and its overrides must be, safe for concurrent use by multiple threads.
-