Interface Lookup

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 
     
    static class 
     
    static interface 
    Interface to be implemented by all types that provide access to a Lookup.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Lookup
    An empty Lookup
    static final Lookup
    A system-wide Lookup, that by default delegates to ServiceLoader.
  • Method Summary

    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 Details

    • EMPTY

      static final Lookup EMPTY
      An empty Lookup
    • SYSTEM

      static final Lookup SYSTEM
      A system-wide Lookup, that by default delegates to ServiceLoader. The implementation can be overridden or extended by registering a Lookup subclass to be found using ServiceLoader.
  • Method Details

    • find

      <T> Optional<T> find(Class<T> type)
      Search for the first implementation of the given type. Returns an Optional wrapping an instance of the given Class, or Optional.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 from
      instances - collection of objects
      Returns:
      lookup