public class LookupChain extends Object implements IContextLookup
IContextLookupChainLink
s.EMPTY_CONTEXT_LOOKUP
Constructor and Description |
---|
LookupChain() |
Modifier and Type | Method and Description |
---|---|
<TContext,TResult> |
add(Class<TContext> contextType,
Class<TResult> resultType,
BiFunction<TContext,TResult,TResult> wrapperFactory)
A convenience method that adds a
IContextLookupChainLink to the given chain that is based on a
BiFunction . |
<TContext,TResult> |
add(Class<TContext> contextType,
Class<TResult> resultType,
BiFunction<TContext,TResult,TResult> wrapperFactory,
boolean decorateNull)
A convenience method that adds a
IContextLookupChainLink to the given chain that is based on a
BiFunction . |
<TContext,TResult> |
add(Class<TContext> contextType,
Class<TResult> resultType,
Function<TContext,TResult> factory)
A convenience method that adds a
IContextLookupChainLink to the given chain that is based on a
Function . |
<TContext,TResult> |
add(Class<TContext> contextType,
Class<TResult> resultType,
Function<TContext,TResult> factory,
boolean nullIsFallback)
A convenience method that adds a
IContextLookupChainLink to the given chain that is based on a
Function . |
void |
add(IContextLookupChainLink lookup)
Adds the given link to the end of the chain.
|
<TResult> IContextLookupChainLink |
addConstant(Class<TResult> resultType,
TResult result)
Convenience method that can be used instead of the
add(IContextLookupChainLink) method to easily add a lookup
implementation for a given type that always yields a constant result. |
void |
addPropertyChangedListener(IEventHandler<PropertyChangedEventArgs> propertyChangedEvent)
Adds the given listener for the
PropertyChanged event that occurs when the lookup of this instance has changed
for some or all of the types or items. |
Object |
lookup(Object item,
Class type)
Performs the actual lookup operation.
|
void |
notifyChange()
Can be called by client code to trigger the
PropertyChanged event
manually. |
protected void |
onPropertyChanged(PropertyChangedEventArgs eventArgs)
Notifies client code that the lookup of this instance might have changed.
|
void |
remove(IContextLookupChainLink link)
Removes the link that has previously been added to this instance from this chain.
|
void |
removePropertyChangedListener(IEventHandler<PropertyChangedEventArgs> propertyChangedEvent)
Removes the given listener for the
PropertyChanged event that occurs when the lookup of this instance has
changed for some or all of the types or items. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
lookup, lookup, lookup, safeLookup
public final <TContext,TResult> IContextLookupChainLink add(Class<TContext> contextType, Class<TResult> resultType, BiFunction<TContext,TResult,TResult> wrapperFactory)
IContextLookupChainLink
to the given chain that is based on a
BiFunction
.
Depending on decorateNull
, null
results of the underlying chain will be passed to the
wrapperFactory
, or simply yielded as the final result.
TContext
- The type of the context.TResult
- The type of the result.wrapperFactory
- The wrapper factory that will be called for queries to TResult
to wrap the result of the query to the remainder
of the chain.public <TContext,TResult> IContextLookupChainLink add(Class<TContext> contextType, Class<TResult> resultType, BiFunction<TContext,TResult,TResult> wrapperFactory, boolean decorateNull)
IContextLookupChainLink
to the given chain that is based on a
BiFunction
.
Depending on decorateNull
, null
results of the underlying chain will be passed to the
wrapperFactory
, or simply yielded as the final result.
TContext
- The type of the context.TResult
- The type of the result.wrapperFactory
- The wrapper factory that will be called for queries to TResult
to wrap the result of the query to the remainder
of the chain.decorateNull
- if set to true
null
return values of the remainder of the chain will be passed to the wrapper factory so
that it can decorate the null, otherwise null will be yielded as the final result.public final <TContext,TResult> IContextLookupChainLink add(Class<TContext> contextType, Class<TResult> resultType, Function<TContext,TResult> factory)
IContextLookupChainLink
to the given chain that is based on a
Function
.
Depending on nullIsFallback
, null
return values of the factory
will be interpreted as the final
result or indicate to the implementation that the chain should be queried for the result.
TContext
- The type of the context.TResult
- The type of the result.factory
- The factory that will be called for queries to TResult
.public <TContext,TResult> IContextLookupChainLink add(Class<TContext> contextType, Class<TResult> resultType, Function<TContext,TResult> factory, boolean nullIsFallback)
IContextLookupChainLink
to the given chain that is based on a
Function
.
Depending on nullIsFallback
, null
return values of the factory
will be interpreted as the final
result or indicate to the implementation that the chain should be queried for the result.
TContext
- The type of the context.TResult
- The type of the result.factory
- The factory that will be called for queries to TResult
.nullIsFallback
- If set to true
, null
return values of the factory method will be interpreted as the final result,
otherwise the request will propagate down the chain.public final void add(IContextLookupChainLink lookup)
lookup
- The link to add.remove(IContextLookupChainLink)
public <TResult> IContextLookupChainLink addConstant(Class<TResult> resultType, TResult result)
add(IContextLookupChainLink)
method to easily add a lookup
implementation for a given type that always yields a constant result.
Note that in order to work correctly, the type parameter (TResult
) should be specified instead of being inferred
by the compiler, because the parameter is used to compare with the query type in the IContextLookup.lookup(Object, Class)
call.
TResult
- The type of the query, which is a base type or the type of the result.result
- The constant value to yield if the chain is queried for an implementation of type TResult
.IContextLookupChainLink
instance that has been added to the chain.public final void addPropertyChangedListener(IEventHandler<PropertyChangedEventArgs> propertyChangedEvent)
PropertyChanged
event that occurs when the lookup of this instance has changed
for some or all of the types or items.propertyChangedEvent
- The listener to add.removePropertyChangedListener(IEventHandler)
public final Object lookup(Object item, Class type)
This call will traverse the chain to satisfy the query.
lookup
in interface IContextLookup
item
- The item to use as the context.type
- The type of the query.ILookup.lookup(Class)
public void notifyChange()
PropertyChanged
event
manually.protected void onPropertyChanged(PropertyChangedEventArgs eventArgs)
eventArgs
- The argumentspublic final void remove(IContextLookupChainLink link)
link
- The link to remove.public final void removePropertyChangedListener(IEventHandler<PropertyChangedEventArgs> propertyChangedEvent)
PropertyChanged
event that occurs when the lookup of this instance has
changed for some or all of the types or items.propertyChangedEvent
- The listener to remove.addPropertyChangedListener(IEventHandler)