Class AnnotationUsageCache

java.lang.Object
com.helger.commons.cache.AnnotationUsageCache

@NotThreadSafe public class AnnotationUsageCache extends Object
A simple cache for the usage of a certain annotation class at other classes.
Note: cannot use Cache because it would need a Class<?> as a key and this would be a hard wired reference.
Since 10.1.3 the class is no longer read-write-locked, as the performance overhead is too big for reading only, compared to the penalty of double annotation determination.
Author:
Philip Helger
  • Constructor Details

    • AnnotationUsageCache

      public AnnotationUsageCache(@Nonnull Class<? extends Annotation> aAnnotationClass)
      Constructor
      Parameters:
      aAnnotationClass - The annotation class to store the existence of. It must have the RetentionPolicy.RUNTIME to be usable within this class!
  • Method Details

    • getAnnotationClass

      @Nonnull public final Class<? extends Annotation> getAnnotationClass()
      Returns:
      The annotation class passed in the constructor. Never null.
    • hasAnnotation

      public boolean hasAnnotation(@Nonnull Object aObject)
      Check if the class of the passed object has the annotation provided in the constructor.
      Parameters:
      aObject - The object. To be checked. May not be null.
      Returns:
      true if the owning class has the annotation, false if not.
      See Also:
    • hasAnnotation

      public boolean hasAnnotation(@Nonnull Class<?> aClass)
      Check if the provided class has the annotation from the constructor or not. If the value is not yet in the cache, it will be determined.
      Parameters:
      aClass - The class to check. May not be null.
      Returns:
      true if the provided class has the annotation, false if not.
    • setAnnotation

      public void setAnnotation(@Nonnull Class<?> aClass, boolean bHasAnnotation)
      In case the knowledge was gathered on the outside, remember the wisdom in this class.
      Parameters:
      aClass - The class that it is about.
      bHasAnnotation - true to indicate the presence, false to
    • clearCache

      public void clearCache()
      Remove all entries from the cache. That is mainly of interested for testing purposes, to provide a clean state.
    • toString

      public String toString()
      Overrides:
      toString in class Object