Package com.helger.commons.cache
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 useCachebecause it would need aClass<?>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 Summary
Constructors Constructor Description AnnotationUsageCache(Class<? extends Annotation> aAnnotationClass)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearCache()Remove all entries from the cache.Class<? extends Annotation>getAnnotationClass()booleanhasAnnotation(Class<?> aClass)Check if the provided class has the annotation from the constructor or not.booleanhasAnnotation(Object aObject)Check if the class of the passed object has the annotation provided in the constructor.voidsetAnnotation(Class<?> aClass, boolean bHasAnnotation)In case the knowledge was gathered on the outside, remember the wisdom in this class.StringtoString()
-
-
-
Constructor Detail
-
AnnotationUsageCache
public AnnotationUsageCache(@Nonnull Class<? extends Annotation> aAnnotationClass)
Constructor- Parameters:
aAnnotationClass- The annotation class to store the existence of. It must have theRetentionPolicy.RUNTIMEto be usable within this class!
-
-
Method Detail
-
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 benull.- Returns:
trueif the owning class has the annotation,falseif not.- See Also:
hasAnnotation(Class)
-
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 benull.- Returns:
trueif the provided class has the annotation,falseif 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-trueto indicate the presence,falseto
-
clearCache
public void clearCache()
Remove all entries from the cache. That is mainly of interested for testing purposes, to provide a clean state.
-
-