-
- All Known Implementing Classes:
Lookup.Empty
,Lookup.ObjectLookup
public interface Lookup
A general type-safe registry by which clients can access implementations of various services (eg. implementations of a specific interface). It is inspired by the similarly named feature in the Apache NetBeans platform, but is generally simpler and more lightweight.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Lookup.Empty
static class
Lookup.ObjectLookup
static interface
Lookup.Provider
Interface to be implemented by all types that provide access to a Lookup.
-
Field Summary
Fields Modifier and Type Field Description static Lookup
EMPTY
An empty Lookupstatic Lookup
SYSTEM
A system-wide Lookup, that by default delegates toServiceLoader
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> Optional<T>
find(Class<T> type)
Search for the first implementation of the given type.<T> Stream<T>
findAll(Class<T> type)
Search for all implementations of the given type.static Lookup
of(Object... instances)
Create a Lookup wrapping the given Objects.static Lookup
of(Lookup parent, Object... instances)
Create a Lookup wrapping the given Objects and results from the provided parent Lookup.
-
-
-
Field Detail
-
EMPTY
static final Lookup EMPTY
An empty Lookup
-
SYSTEM
static final Lookup SYSTEM
A system-wide Lookup, that by default delegates toServiceLoader
. The implementation can be overridden or extended by registering a Lookup subclass to be found using ServiceLoader.
-
-
Method Detail
-
find
<T> Optional<T> find(Class<T> type)
Search for the first implementation of the given type. Returns anOptional
wrapping an instance of the given Class, orOptional.EMPTY
if none exists.- Type Parameters:
T
- service type to lookup- Parameters:
type
- class of service to lookup- Returns:
- Optional wrapping first instance of type, or an empty Optional if not found
-
findAll
<T> Stream<T> findAll(Class<T> type)
Search for all implementations of the given type.- Type Parameters:
T
- service type to lookup- Parameters:
type
- class of service to lookup- Returns:
- Stream of all implementations of the given type
-
of
static Lookup of(Object... instances)
Create a Lookup wrapping the given Objects. Searches will maintain the order of the provided instances.- Parameters:
instances
- collection of objects- Returns:
- lookup
-
of
static Lookup of(Lookup parent, Object... instances)
Create a Lookup wrapping the given Objects and results from the provided parent Lookup. Searches will maintain the order of the provided instances. Instances registered directly will take priority over the parent.- Parameters:
parent
- lookup to include results frominstances
- collection of objects- Returns:
- lookup
-
-