Class AnnotationSet

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.annotation.Annotation>

    public class AnnotationSet
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.annotation.Annotation>
    Immutable set of Annotation instances
    Since:
    19.3.0
    Author:
    cdivilly
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.reflect.AnnotatedElement element()
      The element which is annotated with these Annotations
      boolean equals​(java.lang.Object obj)  
      static AnnotationSet from​(java.lang.reflect.AnnotatedElement element)
      Generate the set of annotations that this element is annotated with
      <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.Class<T> annotationClass)
      Returns this element's annotation for the specified type if such an annotation is present, else null.
      int hashCode()  
      boolean isAnnotationPresent​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
      Returns true if an annotation for the specified type is present on this element, else false.
      boolean isEmpty()
      Indicates if this annotation set is empty
      java.util.Iterator<java.lang.annotation.Annotation> iterator()  
      java.util.Set<java.lang.annotation.Annotation> qualifiers()
      Gives the subset of Annotations that represent Qualifier annotations
      java.lang.annotation.Annotation scope()
      Indicates the Scope annotation if any is present
      int size()
      Indicates the number of annotations present
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • element

        public java.lang.reflect.AnnotatedElement element()
        The element which is annotated with these Annotations
        Returns:
        AnnotatedElement instance
      • isAnnotationPresent

        public boolean isAnnotationPresent​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
        Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations.

        The truth value returned by this method is equivalent to: getAnnotation(annotationClass) != null

        The body of the default method is specified to be the code above.

        Parameters:
        annotationClass - the Class object corresponding to the annotation type
        Returns:
        true if an annotation for the specified annotation type is present on this element, else false
        Throws:
        java.lang.NullPointerException - if the given annotation class is null
      • getAnnotation

        public <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.Class<T> annotationClass)
        Returns this element's annotation for the specified type if such an annotation is present, else null.
        Type Parameters:
        T - the type of the annotation to query for and return if present
        Parameters:
        annotationClass - the Class object corresponding to the annotation type
        Returns:
        this element's annotation for the specified annotation type if present on this element, else null
        Throws:
        java.lang.NullPointerException - if the given annotation class is null
      • equals

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

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

        public boolean isEmpty()
        Indicates if this annotation set is empty
        Returns:
        true if the set is empty, false otherwise
      • iterator

        public java.util.Iterator<java.lang.annotation.Annotation> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.annotation.Annotation>
      • qualifiers

        public java.util.Set<java.lang.annotation.Annotation> qualifiers()
        Gives the subset of Annotations that represent Qualifier annotations
      • scope

        public java.lang.annotation.Annotation scope()
        Indicates the Scope annotation if any is present
        Returns:
        Annotation annotated with Scope or null if no such annotation is present
      • size

        public int size()
        Indicates the number of annotations present
        Returns:
        The number of annotations in this set
      • toString

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

        public static AnnotationSet from​(java.lang.reflect.AnnotatedElement element)
        Generate the set of annotations that this element is annotated with
        Parameters:
        element - The element to examine
        Returns:
        AnnotationSet for the element