Interface Discoverer

  • 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 Detail

      • discover

        <U> List<U> discover​(Class<U> c)
        Discovers implementations of some Class c.
        Type Parameters:
        U - the Type of the Class being searched for
        Parameters:
        c - the Class being searched for
        Returns:
        a List of implementations of c
      • using

        static <T> Discoverer using​(Function<Class<T>,​? extends Iterable<T>> func)
        Creates a Discoverer operating via Function.

        NB: The Function input 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 (and used by) the calling module. Otherwise, all service interfaces would have to be used by this module, which is not extensible.

        Type Parameters:
        T - the Class we attempt to discover, and consequently the supertype of all implementations contained in the Iterable
        Parameters:
        func - the Function generating a Iterable of implementations provided a Class
        Returns:
        A Discoverer backed by func
      • all

        static <T> List<Discoverer> all​(Function<Class<T>,​? extends Iterable<T>> func)
        Gets all Discoverers made available through Iterable, as well as a Discoverer that is itself backed by the Iterable.

        It is highly recommended to call this method using List<Discoverer> discoverers = Discoverers.all(ServiceLoader::load);

        Type Parameters:
        T - the Class we attempt to discover, and consequently the supertype of all implementations contained in the Iterable
        Parameters:
        func - the Function generating a Iterable of implementations provided a Class. 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 used ServiceLoader.load(Class) directly, we'd only be able to discover implementations whose interface was used by module org.scijava.discovery.

        It is in the user's best interest to make this Function as general as possible.

        Returns:
        A List of Discoverers, including a Discoverer backed by func, and all Discoverers found by func
      • onlyFor

        default Discoverer onlyFor​(Class<?>... classes)
        Wraps up this Discoverer into a Discoverer that only discoverers classes classes
        Parameters:
        classes - the Classes
        Returns:
        the wrapping
      • except

        default Discoverer except​(Class<?>... classes)
        Wraps up this Discoverer into a Discoverer that only discoverers classes classes
        Parameters:
        classes - the Classes
        Returns:
        the wrapping
      • discoverMax

        default <U extends Comparable<U>> Optional<U> discoverMax​(Class<U> c)
        Finds the maximum implementation of any Comparable c.
        Type Parameters:
        U - the Type of c
        Parameters:
        c - the Class, extending Comparable that 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 any Comparable c.
        Type Parameters:
        U - the Type of c
        Parameters:
        c - the Class, extending Comparable that the returned implementation must implement
        Returns:
        the minimum implementation of c