Interface InstanceProvider<T>

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

public interface InstanceProvider<T> extends Iterable<T>, jakarta.inject.Provider<T>, 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:
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Retrieve the first available instance
    default T
    Retrieve the instance or null if no instance is available
    boolean
    Determines if there is more than one available implementation for the required type and qualifiers
    default boolean
    Determines if there is more than one available implementation for the required type and qualifiers.
    default boolean
    Indicates if at least one matching provider is found
    default boolean
    Equivalent to isUnsatisfied()
    boolean
    Determines if there is no available implementation for the required type and qualifiers.
    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
    Identifies the constraints used to select matches
    default Stream<T>
    Adapt this set of providers to a Stream instance

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • get

      T get()
      Retrieve the first available instance
      Specified by:
      get in interface jakarta.inject.Provider<T>
      Specified by:
      get in interface 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

      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 Iterable<T>
      Returns:
      The set of available providers
    • stream

      default 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