T
- The type of the initial context object, which must implement BreadcrumbContextI
.U
- The base type of the business object.public class DefaultBreadcrumbFinder<T extends BreadcrumbContextI<T,U>,U extends BOI> extends java.lang.Object implements BreadcrumbFinderI<U>
This class serves as a public-facing facade, allowing clients to perform
searches without knowing the internal details of the BreadcrumbContextI
implementation.
Constructor and Description |
---|
DefaultBreadcrumbFinder(T startContext)
Creates a new finder instance for a specific starting context.
|
Modifier and Type | Method and Description |
---|---|
boolean |
clearContext(T forContext)
Clears the starting context for this finder instance, if it matches the passed context.
|
java.util.Optional<U> |
findFirst()
Returns the first business object found by walking up the chain from the initial context.
|
U |
findFirstBO()
Returns the first business object found by walking up the chain from the initial context, returning the value directly.
|
<V extends U> |
findFirstBOOfType(java.lang.Class<V> objectType)
Returns the first business object of a specific type found in the parent chain, returning the value directly.
|
U |
findFirstBOWhere(java.util.function.Predicate<U> predicate)
Returns the first business object that matches the given predicate, found in the parent chain, returning the value directly.
|
<V extends U> |
findFirstOfType(java.lang.Class<V> objectType)
Returns the first business object of a specific type found in the parent chain.
|
java.util.Optional<U> |
findFirstWhere(java.util.function.Predicate<U> predicate)
Returns the first business object that matches the given predicate, found in the parent chain.
|
java.util.Optional<U> |
findParent()
Returns the business object of the immediate parent of the initial context.
|
U |
findParentBO()
Returns the business object of the immediate parent of the initial context, returning the value directly.
|
boolean |
isEmpty()
Determines if this finder instance is empty, i.e. it has no context yet.
|
boolean |
setContextIfEmpty(T newContext)
Sets the starting context for this finder instance only if the context is currently empty.
|
public DefaultBreadcrumbFinder(T startContext)
startContext
- The context from which the search should begin.public boolean setContextIfEmpty(T newContext)
This method is designed to be called when entering a new breadcrumb context. It prevents overwriting an existing context, which is crucial for nested accessor calls, as only the initial starting point in the structure shall be the starting point of the breadcrumb navigation. It also keeps a count of how many times a given context has been set to support nested calls where the same context instance is entered multiple times.
If the context is successfully set, this method also updates the thread-local finder in the
Breadcrumb
convenience class to allow easy access from static contexts.
newContext
- The new context from which to begin a search.true
if the context was successfully set; false
if the context was already set.public boolean clearContext(T forContext)
This method uses an internal counter to handle nested set/clear calls for the same context. The context is only truly cleared, and the thread-local finder is removed, on the final call that matches the initial set call, preventing premature clearing in nested scenarios.
forContext
- The context to compare against our internal start context.true
if the starting context was cleared; false
otherwise.public boolean isEmpty()
true
if the starting context is null; false
otherwise.public java.util.Optional<U> findParent()
findParent
in interface BreadcrumbFinderI<U extends BOI>
Optional
containing the parent's business object, or empty if not found.public java.util.Optional<U> findFirst()
findFirst
in interface BreadcrumbFinderI<U extends BOI>
Optional
containing the first found business object, or empty if not found.public <V extends U> java.util.Optional<V> findFirstOfType(java.lang.Class<V> objectType)
findFirstOfType
in interface BreadcrumbFinderI<U extends BOI>
V
- The specific type of the object.objectType
- The Class
of the business object to find.Optional
containing the first found business object of the specified type.public java.util.Optional<U> findFirstWhere(java.util.function.Predicate<U> predicate)
findFirstWhere
in interface BreadcrumbFinderI<U extends BOI>
predicate
- The Predicate
to test the business object.Optional
containing the first business object that satisfies the predicate.public U findParentBO()
findParentBO
in interface BreadcrumbFinderI<U extends BOI>
null
if not found.public U findFirstBO()
findFirstBO
in interface BreadcrumbFinderI<U extends BOI>
null
if not found.public <V extends U> V findFirstBOOfType(java.lang.Class<V> objectType)
findFirstBOOfType
in interface BreadcrumbFinderI<U extends BOI>
V
- The specific type of the object.objectType
- The Class
of the business object to find.null
if not found.public U findFirstBOWhere(java.util.function.Predicate<U> predicate)
findFirstBOWhere
in interface BreadcrumbFinderI<U extends BOI>
predicate
- The Predicate
to test the business object.null
if not found.Copyright © 2000-2025 OAshi S.à r.l. All Rights Reserved.