Package com.helger.commons.cache
Class AnnotationUsageCache
java.lang.Object
com.helger.commons.cache.AnnotationUsageCache
A simple cache for the usage of a certain annotation class at other classes.
Note: cannot use
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.
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 Summary
ConstructorsConstructorDescriptionAnnotationUsageCache(Class<? extends Annotation> aAnnotationClass) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidRemove all entries from the cache.final Class<? extends Annotation> 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.toString()
-
Constructor Details
-
AnnotationUsageCache
Constructor- Parameters:
aAnnotationClass- The annotation class to store the existence of. It must have theRetentionPolicy.RUNTIMEto be usable within this class!
-
-
Method Details
-
getAnnotationClass
- Returns:
- The annotation class passed in the constructor. Never
null.
-
hasAnnotation
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
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
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. -
toString
-