public class AnnotationAttributes extends LinkedHashMap<String,Object>
LinkedHashMap subclass representing annotation attribute
key-value pairs as read by AnnotationUtils,
AnnotatedElementUtils, and Spring's reflection- and ASM-based
AnnotationMetadata implementations.
Provides 'pseudo-reification' to avoid noisy Map generics in the calling code as well as convenience methods for looking up annotation attributes in a type-safe fashion.
AnnotationUtils.getAnnotationAttributes(java.lang.annotation.Annotation),
AnnotatedElementUtils,
Serialized FormAbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
AnnotationAttributes()
Create a new, empty
AnnotationAttributes instance. |
AnnotationAttributes(AnnotationAttributes other)
Create a new
AnnotationAttributes instance, wrapping the provided
map and all its key-value pairs. |
AnnotationAttributes(Class<? extends Annotation> annotationType)
Create a new, empty
AnnotationAttributes instance for the
specified annotationType. |
AnnotationAttributes(int initialCapacity)
Create a new, empty
AnnotationAttributes instance with the
given initial capacity to optimize performance. |
AnnotationAttributes(Map<String,Object> map)
Create a new
AnnotationAttributes instance, wrapping the provided
map and all its key-value pairs. |
AnnotationAttributes(String annotationType,
ClassLoader classLoader)
Create a new, empty
AnnotationAttributes instance for the
specified annotationType. |
| Modifier and Type | Method and Description |
|---|---|
Class<? extends Annotation> |
annotationType()
Get the type of annotation represented by this
AnnotationAttributes instance. |
static AnnotationAttributes |
fromMap(Map<String,Object> map)
Return an
AnnotationAttributes instance based on the given map. |
Class<?>[] |
getAliasedClassArray(String attributeName,
Class<? extends Annotation> annotationType,
Object annotationSource)
Deprecated.
as of Spring 4.3.2, in favor of built-in alias resolution
in
getClassArray(java.lang.String) itself |
String |
getAliasedString(String attributeName,
Class<? extends Annotation> annotationType,
Object annotationSource)
Deprecated.
as of Spring 4.3.2, in favor of built-in alias resolution
in
getString(java.lang.String) itself |
String[] |
getAliasedStringArray(String attributeName,
Class<? extends Annotation> annotationType,
Object annotationSource)
Deprecated.
as of Spring 4.3.2, in favor of built-in alias resolution
in
getStringArray(java.lang.String) itself |
AnnotationAttributes |
getAnnotation(String attributeName)
Get the
AnnotationAttributes stored under the specified
attributeName. |
<A extends Annotation> |
getAnnotation(String attributeName,
Class<A> annotationType)
Get the annotation of type
annotationType stored under the
specified attributeName. |
AnnotationAttributes[] |
getAnnotationArray(String attributeName)
Get the array of
AnnotationAttributes stored under the specified
attributeName. |
<A extends Annotation> |
getAnnotationArray(String attributeName,
Class<A> annotationType)
Get the array of type
annotationType stored under the specified
attributeName. |
boolean |
getBoolean(String attributeName)
Get the value stored under the specified
attributeName as a boolean. |
<T> Class<? extends T> |
getClass(String attributeName)
Get the value stored under the specified
attributeName as a class. |
Class<?>[] |
getClassArray(String attributeName)
Get the value stored under the specified
attributeName as an
array of classes. |
<E extends Enum<?>> |
getEnum(String attributeName)
Get the value stored under the specified
attributeName as an enum. |
<N extends Number> |
getNumber(String attributeName)
Get the value stored under the specified
attributeName as a number. |
String |
getString(String attributeName)
Get the value stored under the specified
attributeName as a
string. |
String[] |
getStringArray(String attributeName)
Get the value stored under the specified
attributeName as an
array of strings. |
Object |
putIfAbsent(String key,
Object value)
Store the supplied
value in this map under the specified
key, unless a value is already stored under the key. |
String |
toString() |
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesclone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, remove, remove, replace, replace, sizeequals, hashCodepublic AnnotationAttributes()
AnnotationAttributes instance.public AnnotationAttributes(int initialCapacity)
AnnotationAttributes instance with the
given initial capacity to optimize performance.initialCapacity - initial size of the underlying mappublic AnnotationAttributes(Class<? extends Annotation> annotationType)
AnnotationAttributes instance for the
specified annotationType.annotationType - the type of annotation represented by this
AnnotationAttributes instance; never nullpublic AnnotationAttributes(String annotationType, ClassLoader classLoader)
AnnotationAttributes instance for the
specified annotationType.annotationType - the annotation type name represented by this
AnnotationAttributes instance; never nullclassLoader - the ClassLoader to try to load the annotation type on,
or null to just store the annotation type namepublic AnnotationAttributes(Map<String,Object> map)
AnnotationAttributes instance, wrapping the provided
map and all its key-value pairs.map - original source of annotation attribute key-value pairsfromMap(Map)public AnnotationAttributes(AnnotationAttributes other)
AnnotationAttributes instance, wrapping the provided
map and all its key-value pairs.other - original source of annotation attribute key-value pairsfromMap(Map)public Class<? extends Annotation> annotationType()
AnnotationAttributes instance.null if unknownpublic String getString(String attributeName)
attributeName as a
string.attributeName - the name of the attribute to get; never
null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected type@Deprecated public String getAliasedString(String attributeName, Class<? extends Annotation> annotationType, Object annotationSource)
getString(java.lang.String) itselfattributeName as a
string, taking into account alias semantics defined via
@AliasFor.
If there is no value stored under the specified attributeName
but the attribute has an alias declared via @AliasFor, the
value of the alias will be returned.
attributeName - the name of the attribute to get; never
null or emptyannotationType - the type of annotation represented by this
AnnotationAttributes instance; never nullannotationSource - the source of the annotation represented by
this AnnotationAttributes (e.g., the AnnotatedElement);
or null if unknownIllegalArgumentException - if the attribute and its alias do
not exist or are not of type StringAnnotationConfigurationException - if the attribute and its
alias are both present with different non-empty valuespublic String[] getStringArray(String attributeName)
attributeName as an
array of strings.
If the value stored under the specified attributeName is
a string, it will be wrapped in a single-element array before
returning it.
attributeName - the name of the attribute to get; never
null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected type@Deprecated public String[] getAliasedStringArray(String attributeName, Class<? extends Annotation> annotationType, Object annotationSource)
getStringArray(java.lang.String) itselfattributeName as an
array of strings, taking into account alias semantics defined via
@AliasFor.
If there is no value stored under the specified attributeName
but the attribute has an alias declared via @AliasFor, the
value of the alias will be returned.
attributeName - the name of the attribute to get; never
null or emptyannotationType - the type of annotation represented by this
AnnotationAttributes instance; never nullannotationSource - the source of the annotation represented by
this AnnotationAttributes (e.g., the AnnotatedElement);
or null if unknownIllegalArgumentException - if the attribute and its alias do
not exist or are not of type String[]AnnotationConfigurationException - if the attribute and its
alias are both present with different non-empty valuespublic boolean getBoolean(String attributeName)
attributeName as a boolean.attributeName - the name of the attribute to get;
never null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic <N extends Number> N getNumber(String attributeName)
attributeName as a number.attributeName - the name of the attribute to get;
never null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic <E extends Enum<?>> E getEnum(String attributeName)
attributeName as an enum.attributeName - the name of the attribute to get;
never null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic <T> Class<? extends T> getClass(String attributeName)
attributeName as a class.attributeName - the name of the attribute to get;
never null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic Class<?>[] getClassArray(String attributeName)
attributeName as an
array of classes.
If the value stored under the specified attributeName is a class,
it will be wrapped in a single-element array before returning it.
attributeName - the name of the attribute to get;
never null or emptyIllegalArgumentException - if the attribute does not exist or
if it is not of the expected type@Deprecated public Class<?>[] getAliasedClassArray(String attributeName, Class<? extends Annotation> annotationType, Object annotationSource)
getClassArray(java.lang.String) itselfattributeName as an
array of classes, taking into account alias semantics defined via
@AliasFor.
If there is no value stored under the specified attributeName
but the attribute has an alias declared via @AliasFor, the
value of the alias will be returned.
attributeName - the name of the attribute to get; never
null or emptyannotationType - the type of annotation represented by this
AnnotationAttributes instance; never nullannotationSource - the source of the annotation represented by
this AnnotationAttributes (e.g., the AnnotatedElement);
or null if unknownIllegalArgumentException - if the attribute and its alias do
not exist or are not of type Class[]AnnotationConfigurationException - if the attribute and its
alias are both present with different non-empty valuespublic AnnotationAttributes getAnnotation(String attributeName)
AnnotationAttributes stored under the specified
attributeName.
Note: if you expect an actual annotation, invoke
getAnnotation(String, Class) instead.
attributeName - the name of the attribute to get; never
null or emptyAnnotationAttributesIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic <A extends Annotation> A getAnnotation(String attributeName, Class<A> annotationType)
annotationType stored under the
specified attributeName.attributeName - the name of the attribute to get;
never null or emptyannotationType - the expected annotation type; never nullIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic AnnotationAttributes[] getAnnotationArray(String attributeName)
AnnotationAttributes stored under the specified
attributeName.
If the value stored under the specified attributeName is
an instance of AnnotationAttributes, it will be wrapped in
a single-element array before returning it.
Note: if you expect an actual array of annotations, invoke
getAnnotationArray(String, Class) instead.
attributeName - the name of the attribute to get;
never null or emptyAnnotationAttributesIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic <A extends Annotation> A[] getAnnotationArray(String attributeName, Class<A> annotationType)
annotationType stored under the specified
attributeName.
If the value stored under the specified attributeName is
an Annotation, it will be wrapped in a single-element array
before returning it.
attributeName - the name of the attribute to get;
never null or emptyannotationType - the expected annotation type; never nullIllegalArgumentException - if the attribute does not exist or
if it is not of the expected typepublic Object putIfAbsent(String key, Object value)
value in this map under the specified
key, unless a value is already stored under the key.putIfAbsent in interface Map<String,Object>putIfAbsent in class HashMap<String,Object>key - the key under which to store the valuevalue - the value to storenull if no
value was previously stored in this mapLinkedHashMap.get(java.lang.Object),
HashMap.put(K, V)public String toString()
toString in class AbstractMap<String,Object>public static AnnotationAttributes fromMap(Map<String,Object> map)
AnnotationAttributes instance based on the given map.
If the map is already an AnnotationAttributes instance, it
will be cast and returned immediately without creating a new instance.
Otherwise a new instance will be created by passing the supplied map
to the AnnotationAttributes(Map) constructor.
map - original source of annotation attribute key-value pairs