Class QualifiedType<T>

  • Type Parameters:
    T - the type that is qualified

    public final class QualifiedType<T>
    extends java.lang.Object
    A Type qualified by a set of qualifier annotations. Two qualified types are equal to each other if their getType() and getQualifiers() properties are equal.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int hashCode  
      private java.util.Set<java.lang.annotation.Annotation> qualifiers  
      private java.lang.reflect.Type type  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private QualifiedType​(java.lang.reflect.Type type, java.util.Set<java.lang.annotation.Annotation> qualifiers)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.util.Optional<QualifiedType<?>> flatMapType​(java.util.function.Function<java.lang.reflect.Type,​java.util.Optional<java.lang.reflect.Type>> mapper)
      Apply the provided mapping function to the type, and if non-empty is returned, return an Optional<QualifiedType<?>> with the returned type, and the same qualifiers as this instance.
      java.util.Set<java.lang.annotation.Annotation> getQualifiers()
      Returns a set of qualifying annotations.
      java.lang.reflect.Type getType()
      Returns the qualified type.
      int hashCode()  
      boolean hasQualifier​(java.lang.Class<? extends java.lang.annotation.Annotation> qualifier)
      Returns true if this type contains the given qualifier.
      QualifiedType<?> mapType​(java.util.function.Function<java.lang.reflect.Type,​java.lang.reflect.Type> mapper)
      Apply the provided mapping function to the type, and if non-empty is returned, return an Optional<QualifiedType<?>> with the returned type, and the same qualifiers as this instance.
      static <T> QualifiedType<T> of​(java.lang.Class<T> clazz)
      Creates a QualifiedType<T> for a Class<T> with no qualifiers.
      static QualifiedType<?> of​(java.lang.reflect.Type type)
      Creates a wildcard QualifiedType<?> for a Type with no qualifiers.
      static <T> QualifiedType<T> of​(GenericType<T> type)
      Creates a QualifiedType<T> for a GenericType<T> with no qualifiers.
      java.lang.String toString()  
      QualifiedType<T> with​(java.lang.annotation.Annotation... newQualifiers)
      Returns a QualifiedType that has the same type as this instance, but with only the given qualifiers.
      QualifiedType<T> with​(java.lang.Class<? extends java.lang.annotation.Annotation>... newQualifiers)
      Returns a QualifiedType that has the same type as this instance, but with only the given qualifiers.
      QualifiedType<T> withAnnotationClasses​(java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> newQualifiers)
      Creates a QualifiedType with the same type as this instance and new qualifiers.
      QualifiedType<T> withAnnotations​(java.lang.Iterable<? extends java.lang.annotation.Annotation> newQualifiers)
      Creates a QualifiedType with the same type as this instance and new qualifiers.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • type

        private final java.lang.reflect.Type type
      • qualifiers

        private final java.util.Set<java.lang.annotation.Annotation> qualifiers
      • hashCode

        private int hashCode
    • Constructor Detail

      • QualifiedType

        private QualifiedType​(java.lang.reflect.Type type,
                              java.util.Set<java.lang.annotation.Annotation> qualifiers)
    • Method Detail

      • of

        public static <T> QualifiedType<T> of​(java.lang.Class<T> clazz)
        Creates a QualifiedType<T> for a Class<T> with no qualifiers.
        Parameters:
        clazz - the unqualified type
        Returns:
        the unqualified QualifiedType
        See Also:
        to then qualify your type
      • of

        public static QualifiedType<?> of​(java.lang.reflect.Type type)
        Creates a wildcard QualifiedType<?> for a Type with no qualifiers.
        Parameters:
        type - the unqualified type
        Returns:
        the unqualified QualifiedType
        See Also:
        to then qualify your type
      • of

        public static <T> QualifiedType<T> of​(GenericType<T> type)
        Creates a QualifiedType<T> for a GenericType<T> with no qualifiers.
        Parameters:
        type - the unqualified type
        Returns:
        the unqualified QualifiedType
        See Also:
        to then qualify your type
      • with

        public QualifiedType<T> with​(java.lang.annotation.Annotation... newQualifiers)
        Returns a QualifiedType that has the same type as this instance, but with only the given qualifiers.
        Parameters:
        newQualifiers - the qualifiers for the new qualified type.
        Returns:
        the QualifiedType
      • with

        @SafeVarargs
        public final QualifiedType<T> with​(java.lang.Class<? extends java.lang.annotation.Annotation>... newQualifiers)
        Returns a QualifiedType that has the same type as this instance, but with only the given qualifiers.
        Parameters:
        newQualifiers - the qualifiers for the new qualified type.
        Returns:
        the QualifiedType
        Throws:
        java.lang.IllegalArgumentException - if any of the given qualifier types have annotation attributes.
      • withAnnotations

        public QualifiedType<T> withAnnotations​(java.lang.Iterable<? extends java.lang.annotation.Annotation> newQualifiers)
        Creates a QualifiedType with the same type as this instance and new qualifiers. Old qualifiers are discarded.
        Parameters:
        newQualifiers - the qualifiers for the new qualified type.
        Returns:
        a QualifiedType that has the same type as this instance, but with only the given qualifiers.
      • withAnnotationClasses

        public QualifiedType<T> withAnnotationClasses​(java.lang.Iterable<java.lang.Class<? extends java.lang.annotation.Annotation>> newQualifiers)
        Creates a QualifiedType with the same type as this instance and new qualifiers. Old qualifiers are discarded.
        Parameters:
        newQualifiers - the qualifiers for the new qualified type.
        Returns:
        a QualifiedType that has the same type as this instance, but with only the given qualifiers.
      • getType

        public java.lang.reflect.Type getType()
        Returns the qualified type.
        Returns:
        the type being qualified.
      • getQualifiers

        public java.util.Set<java.lang.annotation.Annotation> getQualifiers()
        Returns a set of qualifying annotations.
        Returns:
        the type qualifiers.
      • mapType

        public QualifiedType<?> mapType​(java.util.function.Function<java.lang.reflect.Type,​java.lang.reflect.Type> mapper)
        Apply the provided mapping function to the type, and if non-empty is returned, return an Optional<QualifiedType<?>> with the returned type, and the same qualifiers as this instance.
        Parameters:
        mapper - a mapping function to apply to the type
        Returns:
        an optional qualified type with the mapped type and the same qualifiers
      • flatMapType

        public java.util.Optional<QualifiedType<?>> flatMapType​(java.util.function.Function<java.lang.reflect.Type,​java.util.Optional<java.lang.reflect.Type>> mapper)
        Apply the provided mapping function to the type, and if non-empty is returned, return an Optional<QualifiedType<?>> with the returned type, and the same qualifiers as this instance.
        Parameters:
        mapper - a mapping function to apply to the type
        Returns:
        an optional qualified type with the mapped type and the same qualifiers
      • hasQualifier

        public boolean hasQualifier​(java.lang.Class<? extends java.lang.annotation.Annotation> qualifier)
        Returns true if this type contains the given qualifier.
        Parameters:
        qualifier - qualifier to check for.
        Returns:
        true if this instance contains the given qualifier.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object