Class MatchArgumentQualifier<T>

java.lang.Object
io.micronaut.inject.qualifiers.MatchArgumentQualifier<T>
Type Parameters:
T - The type
All Implemented Interfaces:
Qualifier<T>

@Internal public final class MatchArgumentQualifier<T> extends Object implements Qualifier<T>
A Qualifier that filters beans according to the type arguments.
Since:
4.6
Author:
Denis Stepanov
  • Method Details

    • ofArgument

      public static <T> MatchArgumentQualifier<T> ofArgument(Argument<?> argument)
    • covariant

      @NonNull public static <T> @NonNull MatchArgumentQualifier<T> covariant(@NonNull @NonNull Class<T> beanType, @NonNull @NonNull Argument<?> genericArgument)
      Finds matches of a type with a covariant generic type (types that extend the type or are equal to it). The generic argument is assignable from the candidate generic type. Use-cases are generic deserializers, readers.
       Java example:
       MyReader<ArrayList<String>> candidate = ...; 
       MyReader<? extends List<String>> aMatch = candidate; 
       
      Type Parameters:
      T - The bean type
      Parameters:
      beanType - The type of the beans
      genericArgument - The generic argument of the bean type
      Returns:
      The qualifier
    • contravariant

      @NonNull public static <T> @NonNull MatchArgumentQualifier<T> contravariant(@NonNull @NonNull Class<T> beanType, @NonNull @NonNull Argument<?> genericArgument)
      Finds matches of a type with a contravariant generic type (types that is a super type or are equal to it). The candidate generic type is assignable from the generic argument. Use-cases are generic serializers, writers.
       Java example:
       MyWriter<String> candidate = ...; 
       MyWriter<? super CharSequence> aMatch = candidate; 
       
      Type Parameters:
      T - The bean type
      Parameters:
      beanType - The type of the beans
      genericArgument - The generic argument of the bean type
      Returns:
      The qualifier
    • reduce

      public <BT extends BeanType<T>> Stream<BT> reduce(Class<T> beanType, Stream<BT> candidates)
      Specified by:
      reduce in interface Qualifier<T>
      Type Parameters:
      BT - The bean type subclass
      Parameters:
      beanType - The bean type
      candidates - The candidates
      Returns:
      The qualified candidate or null it cannot be qualified
    • doesQualify

      public boolean doesQualify(Class<T> beanType, Collection<? extends BeanType<T>> candidates)
      Description copied from interface: Qualifier
      Check if at least one candidate qualifies.
      Specified by:
      doesQualify in interface Qualifier<T>
      Parameters:
      beanType - The bean type
      candidates - The candidates
      Returns:
      true if qualifies
    • doesQualify

      public boolean doesQualify(Class<T> beanType, BeanType<T> candidate)
      Description copied from interface: Qualifier
      Check if the candidate qualifies.
      Specified by:
      doesQualify in interface Qualifier<T>
      Parameters:
      beanType - The bean type
      candidate - The candidate
      Returns:
      true if matches
    • filter

      public <BT extends BeanType<T>> Collection<BT> filter(Class<T> beanType, Collection<BT> candidates)
      Description copied from interface: Qualifier
      Filter the candidates.
      Specified by:
      filter in interface Qualifier<T>
      Type Parameters:
      BT - The bean type subclass
      Parameters:
      beanType - The bean type
      candidates - The candidates
      Returns:
      The filtered candidates
    • toString

      public String toString()
      Overrides:
      toString in class Object