public interface ILookup
LookupExtensions
.DictionaryLookup
Modifier and Type | Field and Description |
---|---|
static ILookup |
EMPTY
An
ILookup instance that always returns null . |
Modifier and Type | Method and Description |
---|---|
static ILookup |
createDictionaryLookup(HashMap<Class,Object> backingDictionary)
Creates a simple mutable
ILookup implementation that is backed by a dictionary. |
static ILookup |
createDynamic(Object subject)
Creates a dynamic lookup implementation that for each type that the given subject can be assigned to yields that
subject.
|
static <T> ILookup |
createSingle(Class<T> tType,
T subject)
Creates a simple lookup implementation that yields
subject if type is queried. |
static ILookup |
createSingle(Object subject,
Class type)
Creates a simple lookup implementation that yields
subject if type is queried. |
static ILookup |
createWrapped(ILookup basicLookup,
ILookup additionalLookup)
Creates a lookup implementation that wraps an existing
ILookup instance using an additional lookup
implementations. |
<T> T |
lookup(Class<T> type)
Returns an instance that implements the given type or
null . |
static <T> T |
lookup(Class<T> tType,
ILookup lookup)
|
static <T> T |
lookup(Class<T> tType,
ILookup lookup,
T fallback)
Utility method that helps keeping code more clean when using
ILookup lookup(Class) calls. |
default <T> T |
safeLookup(Class<T> type)
Typesafe convenience method for the
lookup(Class) method. |
static final ILookup EMPTY
ILookup
instance that always returns null
.static ILookup createDictionaryLookup(HashMap<Class,Object> backingDictionary)
static ILookup createDynamic(Object subject)
subject
- the subject to yield if it is assignable to the type in the lookup querysubject
or null
static <T> ILookup createSingle(Class<T> tType, T subject)
subject
if type
is queried.T
- The type of the subject that will be used as a key for the lookup process.tType
- The type of the subject that will be used as a key for the lookup process.subject
- the subject to yieldstatic ILookup createSingle(Object subject, Class type)
subject
if type
is queried.subject
- the subject to yieldtype
- the type that should yield the subjectstatic ILookup createWrapped(ILookup basicLookup, ILookup additionalLookup)
ILookup
instance using an additional lookup
implementations.
For each lookup call that the additionalLookup
would yield null
, the basicLookup
will be queried
instead.
basicLookup
- the fallback lookup implementationadditionalLookup
- the lookup that has precedence over the fallback<T> T lookup(Class<T> type)
null
.
Typically, this method will be called in order to obtain a different view or
aspect of the current instance. This is quite similar to casting or using
a super type or interface of this instance, but is not limited to inheritance or
compile time constraints. An instance implementing this method is not
required to return non-null
implementations for the types, nor does it
have to return the same instance any time. Also it depends on the
type and context whether the instance returned stays up to date or needs to
be reobtained for subsequent use.type
- the type for which an instance shall be returnednull
static <T> T lookup(Class<T> tType, ILookup lookup)
ILookup
()
calls.
This code can be referenced in places where otherwise it would be used like this:
TheInterface result = lookup.lookup(TheInterface.class);
The replacement is
TheInterface result = Lookups.get<TheInterface>(lookup);
and will save you from doing the cast and using the class
field.
T
- The type that is the target of the lookup.tType
- The type that is the target of the lookup.lookup
- The actual lookup provider.lookup
which may be null
.static <T> T lookup(Class<T> tType, ILookup lookup, T fallback)
ILookup
lookup(Class)
calls.
This code can be referenced in places where otherwise it would be used like this:
TheInterface result = lookup.lookup(TheInterface.class); if (result == null){ result = myFallbackImplementation; }
The replacement is
TheInterface result = Lookups.get(lookup, myFallbackImplementation);
and will save you from doing the cast and using the class
field.
T
- The type that is the target of the lookup.tType
- The type that is the target of the lookup.lookup
- The actual lookup provider.fallback
- The fallback value to use if the lookup yields null
lookup
or fallback
if the former yields null
.default <T> T safeLookup(Class<T> type)
lookup(Class)
method.NoSuchElementException
- If the lookup did not yield a non-null
result for the type.T
- The type to query, this is passed to the lookup(Class)
method
using
typeof
. The result of the query will be converted to this type.type
- The type to query, this is passed to the lookup(Class)
method
using
typeof
. The result of the query will be converted to this type.null
.