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
ConstructorsModifierConstructorDescriptionprotectedCreates a newAbstractTreeBasedProviderwith no lower type bound.protectedAbstractTreeBasedProvider(Type lowerTypeBound) Creates a newAbstractTreeBasedProviderwith the supplied lower type bound. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanReturnstrueif the suppliednodeisnull, absent or synthetic.protected final booleanprotected Supplier<?>Returns a deterministicSuppliersuitable for the current request, represented by the suppliedabsolutePath, as being executed by the suppliedLoader, ornullif no suchSupplieris or ever will be suitable.protected abstract NReturns the child node of the supplied parentnodeidentified by the suppliedindex, ornullif either the child does not exist ornodeis not a list node.protected abstract NReturns the child node of the supplied parentnodeidentified by the suppliedname, ornullif either the child does not exist ornodeis not a map node.protected abstract booleanReturnstrueif the suppliednoderepresents a list or an array, and therefore theget(Object, int)method is likely to be relevant.protected abstract booleanReturnstrueif the suppliednoderepresents a map, and therefore theget(Object, String)method is likely to be relevant.Returns anIteratorover the names of the suppliednode's child nodes, or an emptyIteratorif the suppliednodeis not a map node.protected abstract booleanReturnstrueif the suppliednodeisnullor represents an explicitly setnullvalue.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 aPathfor a newValuethat 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 aQualifiersderived from the suppliedqualifiersNode.protected abstract Nqualifiers(N node) Returns a node possibly containing qualifiers applicable to the supplied node, ornull.protected abstract BiFunction<? super N,? super Type, ?> Returns aBiFunctionaccepting a node and aTypeand returning the result of reading an object of that type, ornullif no suchBiFunctioncould be sourced.protected abstract Nprotected abstract intReturns the number of child nodes the suppliednodehas, 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 newAbstractTreeBasedProviderwith no lower type bound. -
AbstractTreeBasedProvider
Creates a newAbstractTreeBasedProviderwith the supplied lower type bound.- Parameters:
lowerTypeBound- the lower type bound; may benull
-
-
Method Details
-
size
Returns the number of child nodes the suppliednodehas, which may be (and often is)0.If the supplied
nullisnull, absent or a scalar, an override of this method must return0.- Parameters:
node- the parent node; may benullin which case0must be returned- Returns:
- the number of child nodes the supplied
nodehas, 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 anIteratorover the names of the suppliednode's child nodes, or an emptyIteratorif the suppliednodeis not a map node.- Parameters:
node- the parent node; may benullin which case an emptyIteratormust 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 parentnodeidentified by the suppliedname, ornullif either the child does not exist ornodeis not a map node.- Parameters:
node- the parent node; may benullin which casenullmust be returnedname- the name of the child; must not benull- Returns:
- the child node of the supplied parent
nodeidentified by the suppliedname, ornullif either the child does not exist ornodeis not a map node - Throws:
NullPointerException- ifnameisnull- 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 parentnodeidentified by the suppliedindex, ornullif either the child does not exist ornodeis not a list node.- Parameters:
node- the parent node; may benullin which casenullmust be returnedindex- the zero-based index of the child- Returns:
- the child node of the supplied parent
nodeidentified by the suppliedname, ornullif either the child does not exist ornodeis not a map node - Throws:
NullPointerException- ifnameisnullIndexOutOfBoundsException- ifindexis 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
Returnstrueif the suppliednodeisnull, absent or synthetic.- Parameters:
node- the node to test; may benullin which casetruemust be returned- Returns:
trueif the suppliednodeisnull, 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
Returnstrueif the suppliednodeisnullor represents an explicitly setnullvalue.- Parameters:
node- the node to test; may benullin which casetruemust be returned- Returns:
trueif the suppliednodeisnullor represents an explicitly setnullvalue- 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
Returnstrueif the suppliednoderepresents a map, and therefore theget(Object, String)method is likely to be relevant.- Parameters:
node- the node to test; may benullin which casefalsemust be returned- Returns:
trueif the suppliednoderepresents 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
Returnstrueif the suppliednoderepresents a list or an array, and therefore theget(Object, int)method is likely to be relevant.- Parameters:
node- the node to test; may benullin which casefalsemust be returned- Returns:
trueif the suppliednoderepresents 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 benullin which casefalsemust be returned- Returns:
trueifnodeis 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 aBiFunctionaccepting a node and aTypeand returning the result of reading an object of that type, ornullif no suchBiFunctioncould be sourced.- Parameters:
requestor- theLoadercurrently executing a request; must not benullabsolutePath- the path being requested; must not benulland must be absolute- Returns:
- a
BiFunctionaccepting a node and aTypeand returning the result of reading an object of that type, ornullif no suchBiFunctioncould 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 suppliedLoaderandPath, ornullif no tree is suitable.- Parameters:
requestor- theLoadercurrently executing a request; must not benullabsolutePath- the path being requested; must not benulland 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 benullin which casenullmust 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 deterministicSuppliersuitable for the current request, represented by the suppliedabsolutePath, as being executed by the suppliedLoader, ornullif no suchSupplieris or ever will be suitable.- Specified by:
findin classAbstractProvider- Parameters:
requestor- theLoadercurrently executing a request; must not benullabsolutePath- the path being requested; must not benulland 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:
pathin classAbstractProvider- Type Parameters:
T- the type of both the supplied and returnedPaths- Parameters:
requestor- theLoadercurrently executing a request; must not benullabsolutePath- the path being requested; must not benulland must be absolute- Returns:
- a
Paththat will be used to build aValueto be returned by theAbstractProvider.get(Loader, Path)method; ifnull, then theAbstractProvider.get(Loader, Path)method will returnnullas well - Throws:
NullPointerException- ifabsolutePathorreaderisnull- 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 aPathfor a newValuethat will be returned by theAbstractProvider.get(Loader, Path)method.The default implementation of this method attempts to build a
Pathwith the same sizze as the suppliedPathand differing, perhaps, only in theQualifiersassigned 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 suppliedPathand the returnedPath- Parameters:
requestor- theLoadercurrently executing a request; must not benullabsolutePath- the path being requested; must not benulland must be absolutereader- aBiFunctionaccepting a node and aTypeand returning the result of reading an object of that type; may benull- Returns:
- a
Path; nevernull; sometimes simply the suppliedabsolutePath - Throws:
NullPointerException- ifabsolutePathorreaderisnull- 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 aQualifiersderived from the suppliedqualifiersNode.- Parameters:
reader- aBiFunctionaccepting a node and aTypeand returning the result of reading an object of that type; may benullqualifiersNode- a node containing qualifier entries; may benullnextPathElementName- 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.
-