Class AnnotationContext<A extends java.lang.annotation.Annotation>

java.lang.Object
org.proto4j.swing.annotation.AnnotationContext<A>
Type Parameters:
A - the annotation type

public abstract class AnnotationContext<A extends java.lang.annotation.Annotation>
extends java.lang.Object
The base class for the internal Annotation handling. Two implementations are provided by default: SingleAnnotationContext and MultipleAnnotationContext.

This interface provides some utility methods when working with annotated elements and their annotations.

Since:
1.0
  • Constructor Summary

    Constructors 
    Constructor Description
    AnnotationContext​(java.lang.Class<A> type)  
  • Method Summary

    Modifier and Type Method Description
    java.lang.Class<A> annotationType()  
    abstract A annotationValue()  
    static AnnotationContext<?>[] collect​(java.lang.reflect.AnnotatedElement ae)
    Collects all AnnotationContext instances from the given annotated element nad stores them into an array.
    static <R extends java.lang.annotation.Annotation>
    AnnotationContext<R>
    exchange​(java.lang.Class<R> cls, java.lang.reflect.AnnotatedElement ae)
    Retrieves an AnnotationContext from the given annotation type and the dedicated AnnotatedElement.
    void ifPresent​(java.util.function.Consumer<? super A> consumer)
    If a value is present, performs the given action with the value, otherwise does nothing.
    void ifPresentProcess​(java.util.function.Consumer<? super A> consumer)
    If a value array is present, performs the given action with every value in that array, otherwise does nothing.
    abstract boolean isPresent()  
    abstract void requireNonNull()
    Checks that the stored annotation value or array is not null.
    abstract A[] toArray()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • exchange

      public static <R extends java.lang.annotation.Annotation> AnnotationContext<R> exchange​(java.lang.Class<R> cls, java.lang.reflect.AnnotatedElement ae) throws java.lang.ReflectiveOperationException
      Retrieves an AnnotationContext from the given annotation type and the dedicated AnnotatedElement.
      Type Parameters:
      R - the type of the annotation
      Parameters:
      cls - the annotation type
      ae - the annotated element
      Returns:
      a new Single- or MultipleAnnotationContext
      Throws:
      java.lang.ReflectiveOperationException - if an error occurs
    • collect

      public static AnnotationContext<?>[] collect​(java.lang.reflect.AnnotatedElement ae)
      Collects all AnnotationContext instances from the given annotated element nad stores them into an array.
      Parameters:
      ae - the annotated element
      Returns:
      a new array storing all AnnotationContext instances.
    • annotationType

      public java.lang.Class<A> annotationType()
      Returns:
      The annotation type of this context
    • annotationValue

      public abstract A annotationValue()
      Returns:
      the stored annotation instance
    • toArray

      public abstract A[] toArray()
      Returns:
      the stored annotations as an array
    • isPresent

      public abstract boolean isPresent()
      Returns:
      true when the annotation value is not null or the array length is greater that 0; false otherwise
    • requireNonNull

      public abstract void requireNonNull() throws java.lang.NullPointerException
      Checks that the stored annotation value or array is not null.
      Throws:
      java.lang.NullPointerException - if no value is present
    • ifPresent

      public void ifPresent​(java.util.function.Consumer<? super A> consumer)
      If a value is present, performs the given action with the value, otherwise does nothing.
      Parameters:
      consumer - the action to be performed, if a value is present
      Throws:
      java.lang.NullPointerException - if value is present and the given action is null
    • ifPresentProcess

      public void ifPresentProcess​(java.util.function.Consumer<? super A> consumer)
      If a value array is present, performs the given action with every value in that array, otherwise does nothing.
      Parameters:
      consumer - the action to be performed, if a value is present
      Throws:
      java.lang.NullPointerException - if value is present and the given action is null