-
- All Known Implementing Classes:
ManualDiscoverer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Discoverer
Discovers implementations of a given type.- Author:
- Gabriel Selzer
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <T> List<Discoverer>all(Function<Class<T>,? extends Iterable<T>> func)Gets allDiscoverers made available throughIterable, as well as aDiscovererthat is itself backed by theIterable.<U> List<U>discover(Class<U> c)Discovers implementations of someClassc.default <U extends Comparable<U>>
Optional<U>discoverMax(Class<U> c)Finds the maximum implementation of anyComparablec.default <U extends Comparable<U>>
Optional<U>discoverMin(Class<U> c)Finds the minimum implementation of anyComparablec.default Discovererexcept(Class<?>... classes)default DiscovereronlyFor(Class<?>... classes)static Discovererunion(Iterable<Discoverer> discoverers)Accumulates multipleDiscoverers into one mega-Discovererstatic <T> Discovererusing(Function<Class<T>,? extends Iterable<T>> func)Creates aDiscovereroperating viaFunction.
-
-
-
Method Detail
-
using
static <T> Discoverer using(Function<Class<T>,? extends Iterable<T>> func)
Creates aDiscovereroperating viaFunction.NB: The
Functioninput is extremely important for e.g. JPMS compatibility. This puts the code loading the services into the user's module, allowing access to all of the services exposed to (andused by) the calling module. Otherwise, all service interfaces would have to beused by this module, which is not extensible.
-
all
static <T> List<Discoverer> all(Function<Class<T>,? extends Iterable<T>> func)
Gets allDiscoverers made available throughIterable, as well as aDiscovererthat is itself backed by theIterable.It is highly recommended to call this method using
List<Discoverer> discoverers = Discoverers.all(ServiceLoader::load);- Type Parameters:
T- theClasswe attempt to discover, and consequently the supertype of all implementations contained in theIterable- Parameters:
func- theFunctiongenerating aIterableof implementations provided aClass. Notably, this callback has the module scope of the caller, which is useful for circumnavigating module permissions when using e.g. JPMS. If we instead usedServiceLoader.load(Class)directly, we'd only be able to discover implementations whose interface wasused bymodule org.scijava.discovery.It is in the user's best interest to make this
Functionas general as possible.- Returns:
- A
ListofDiscoverers, including aDiscovererbacked byfunc, and allDiscoverers found byfunc
-
union
static Discoverer union(Iterable<Discoverer> discoverers)
Accumulates multipleDiscoverers into one mega-Discoverer- Parameters:
discoverers- theDiscoverers to be wrapped- Returns:
- the mega-
Discoverer
-
onlyFor
default Discoverer onlyFor(Class<?>... classes)
- Parameters:
classes- theClasses- Returns:
- the wrapping
-
except
default Discoverer except(Class<?>... classes)
- Parameters:
classes- theClasses- Returns:
- the wrapping
-
discoverMax
default <U extends Comparable<U>> Optional<U> discoverMax(Class<U> c)
Finds the maximum implementation of anyComparablec.- Type Parameters:
U- theTypeofc- Parameters:
c- theClass, extendingComparablethat the returned implementation must implement- Returns:
- the maximum implementation of
c
-
discoverMin
default <U extends Comparable<U>> Optional<U> discoverMin(Class<U> c)
Finds the minimum implementation of anyComparablec.- Type Parameters:
U- theTypeofc- Parameters:
c- theClass, extendingComparablethat the returned implementation must implement- Returns:
- the minimum implementation of
c
-
-