T
- The typepublic interface BeanProvider<T>
extends java.lang.Iterable<T>
Modifier and Type | Method and Description |
---|---|
static <T1> Argument<BeanProvider<T1>> |
argumentOf(java.lang.Class<T1> type)
Create an argument for the given type to aid with bean provider lookup.
|
T |
get() |
default T |
get(Qualifier<T> qualifier) |
default void |
ifPresent(java.util.function.Consumer<T> consumer)
Executes the given logic if the bean is present.
|
default void |
ifResolvable(java.util.function.Consumer<T> consumer)
Executes the given logic if the bean is resolvable.
|
default boolean |
isPresent()
Determines if there is a bean that matches the required type and qualifiers.
|
default boolean |
isResolvable()
Is the bean resolvable using the
get() or ifPresent(Consumer) methods. |
default boolean |
isUnique()
Determines if more than one bean matches the specified type and qualifiers.
|
default java.util.Iterator<T> |
iterator() |
default T |
orElse(T alternative)
Allows selecting an alternative bean if the backing bean is not present.
|
default java.util.stream.Stream<T> |
stream()
When called, provides back a Stream of the beans available in this provider.
|
@NonNull default T get(@Nullable Qualifier<T> qualifier)
qualifier
- The qualifier to use.@NonNull default java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
default java.util.stream.Stream<T> stream()
When called, provides back a Stream of the beans available in this provider. If no beans are found, it returns an empty stream.
Stream
representing the beans associated with this BeanProvider
objectdefault boolean isUnique()
Determines if more than one bean matches the specified type and qualifiers.
>true
if only one bean matches.default boolean isPresent()
Determines if there is a bean that matches the required type and qualifiers.
default boolean isResolvable()
get()
or ifPresent(Consumer)
methods.
A bean is said to be resolvable when it is both unique (see isUnique()
) and present (see isPresent()
)
default void ifPresent(@NonNull java.util.function.Consumer<T> consumer)
get()
to obtain the bean which may result in a NonUniqueBeanException
if the bean is not unique.consumer
- the consumerNonUniqueBeanException
- if the bean is not uniqueisPresent()
default void ifResolvable(@NonNull java.util.function.Consumer<T> consumer)
isResolvable()
.consumer
- the consumerisResolvable()
@NonNull static <T1> Argument<BeanProvider<T1>> argumentOf(@NonNull java.lang.Class<T1> type)
T1
- The generic typetype
- The type