Interface InstanceProvider<T>

  • Type Parameters:
    T - The type of the service that was located
    All Superinterfaces:
    java.lang.Iterable<T>, jakarta.inject.Provider<T>, java.util.function.Supplier<T>
    All Known Implementing Classes:
    DeferredInstanceProvider, ResolvedInstances

    public interface InstanceProvider<T>
    extends java.lang.Iterable<T>, jakarta.inject.Provider<T>, java.util.function.Supplier<T>
    Provider specialization that provides the ability to:
    • determine if a provider implementation was found, via isUnsatisfied()
    • determine if there are multiple implementations found, via isAmbiguous()
    • Iterate over the available implementations, via iterator()
    • Stream through available implementations, via stream()
    Author:
    cdivilly
    See Also:
    InstanceLocator
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      T get()
      Retrieve the first available instance
      default T getOrNull()
      Retrieve the instance or null if no instance is available
      boolean hasMultiple()
      Determines if there is more than one available implementation for the required type and qualifiers
      default boolean isAmbiguous()
      Determines if there is more than one available implementation for the required type and qualifiers.
      default boolean isAvailable()
      Indicates if at least one matching provider is found
      default boolean isUnavailable()
      Equivalent to isUnsatisfied()
      boolean isUnsatisfied()
      Determines if there is no available implementation for the required type and qualifiers.
      java.util.Iterator<T> iterator()
      When a service has multiple providers (which can be determined by calling isAmbiguous()) this iterator enumerates each of the available providers
      default T orElse​(T value)
      Retrieve the instance or the specified default value if no instance is available
      TypeQualifier<T> qualifier()
      Identifies the constraints used to select matches
      default java.util.stream.Stream<T> stream()
      Adapt this set of providers to a Stream instance
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • get

        T get()
        Retrieve the first available instance
        Specified by:
        get in interface jakarta.inject.Provider<T>
        Specified by:
        get in interface java.util.function.Supplier<T>
        Returns:
        the first available instance
        Throws:
        TypeDependencyNotAvailableException - if no instance is available
      • orElse

        default T orElse​(T value)
        Retrieve the instance or the specified default value if no instance is available
        Parameters:
        value - The default value to provide if no instance is available
        Returns:
        The first available instance or the provided default value
      • getOrNull

        default T getOrNull()
        Retrieve the instance or null if no instance is available
        Returns:
        The first available instance or null if no instance is available
      • hasMultiple

        boolean hasMultiple()
        Determines if there is more than one available implementation for the required type and qualifiers
        Returns:
        true if there are multiple providers, false otherwise
        Since:
        19.3.0
      • isAmbiguous

        default boolean isAmbiguous()
        Determines if there is more than one available implementation for the required type and qualifiers. Synonym for hasMultiple()
        Returns:
        true if there are multiple providers, false otherwise
      • isAvailable

        default boolean isAvailable()
        Indicates if at least one matching provider is found
        Returns:
        true if one or more providers is available, false otherwise
        Since:
        19.3.0
      • isUnavailable

        default boolean isUnavailable()
        Equivalent to isUnsatisfied()
        Returns:
        true if no matching provider is available, false otherwise
        Since:
        19.3.0
      • isUnsatisfied

        boolean isUnsatisfied()
        Determines if there is no available implementation for the required type and qualifiers. If this method returns true, then calling get() will raise a RuntimeException
        Returns:
        true if there is no provider, false otherwise
      • iterator

        java.util.Iterator<T> iterator()
        When a service has multiple providers (which can be determined by calling isAmbiguous()) this iterator enumerates each of the available providers
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        The set of available providers
      • stream

        default java.util.stream.Stream<T> stream()
        Adapt this set of providers to a Stream instance
        Returns:
        Stream of provider instances
        Since:
        20.3.0
      • qualifier

        TypeQualifier<T> qualifier()
        Identifies the constraints used to select matches
        Returns:
        TypeQualifier instance
        Since:
        19.3.0