Class AnnotationAttributes
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<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.
- Since:
- 3.1.1
- Author:
- Chris Beams, Sam Brannen, Juergen Hoeller
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new, emptyAnnotationAttributesinstance.AnnotationAttributes(int initialCapacity) Create a new, emptyAnnotationAttributesinstance with the given initial capacity to optimize performance.AnnotationAttributes(Class<? extends Annotation> annotationType) Create a new, emptyAnnotationAttributesinstance for the specifiedannotationType.AnnotationAttributes(String annotationType, ClassLoader classLoader) Create a new, emptyAnnotationAttributesinstance for the specifiedannotationType.AnnotationAttributes(Map<String, Object> map) Create a newAnnotationAttributesinstance, wrapping the provided map and all its key-value pairs.Create a newAnnotationAttributesinstance, wrapping the provided map and all its key-value pairs.
- 
Method SummaryModifier and TypeMethodDescriptionClass<? extends Annotation>Get the type of annotation represented by thisAnnotationAttributes.static AnnotationAttributesReturn anAnnotationAttributesinstance based on the given map.getAnnotation(String attributeName) Get theAnnotationAttributesstored under the specifiedattributeName.<A extends Annotation>
 AgetAnnotation(String attributeName, Class<A> annotationType) Get the annotation of typeannotationTypestored under the specifiedattributeName.getAnnotationArray(String attributeName) Get the array ofAnnotationAttributesstored under the specifiedattributeName.<A extends Annotation>
 A[]getAnnotationArray(String attributeName, Class<A> annotationType) Get the array of typeannotationTypestored under the specifiedattributeName.booleangetBoolean(String attributeName) Get the value stored under the specifiedattributeNameas a boolean.<T> Class<? extends T>Get the value stored under the specifiedattributeNameas a class.Class<?>[]getClassArray(String attributeName) Get the value stored under the specifiedattributeNameas an array of classes.<E extends Enum<?>>
 EGet the value stored under the specifiedattributeNameas an enum.<N extends Number>
 NGet the value stored under the specifiedattributeNameas a number.Get the value stored under the specifiedattributeNameas a string.String[]getStringArray(String attributeName) Get the value stored under the specifiedattributeNameas an array of strings.toString()Methods inherited from class java.util.LinkedHashMapclear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMapclone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMapequals, hashCodeMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
- 
Constructor Details- 
AnnotationAttributespublic AnnotationAttributes()Create a new, emptyAnnotationAttributesinstance.
- 
AnnotationAttributespublic AnnotationAttributes(int initialCapacity) Create a new, emptyAnnotationAttributesinstance with the given initial capacity to optimize performance.- Parameters:
- initialCapacity- initial size of the underlying map
 
- 
AnnotationAttributesCreate a newAnnotationAttributesinstance, wrapping the provided map and all its key-value pairs.- Parameters:
- map- original source of annotation attribute key-value pairs
- See Also:
 
- 
AnnotationAttributesCreate a newAnnotationAttributesinstance, wrapping the provided map and all its key-value pairs.- Parameters:
- other- original source of annotation attribute key-value pairs
- See Also:
 
- 
AnnotationAttributesCreate a new, emptyAnnotationAttributesinstance for the specifiedannotationType.- Parameters:
- annotationType- the type of annotation represented by this- AnnotationAttributesinstance; never- null
- Since:
- 4.2
 
- 
AnnotationAttributesCreate a new, emptyAnnotationAttributesinstance for the specifiedannotationType.- Parameters:
- annotationType- the annotation type name represented by this- AnnotationAttributesinstance; never- null
- classLoader- the ClassLoader to try to load the annotation type on, or- nullto just store the annotation type name
- Since:
- 4.3.2
 
 
- 
- 
Method Details- 
annotationTypeGet the type of annotation represented by thisAnnotationAttributes.- Returns:
- the annotation type, or nullif unknown
- Since:
- 4.2
 
- 
getStringGet the value stored under the specifiedattributeNameas a string.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getStringArrayGet the value stored under the specifiedattributeNameas an array of strings.If the value stored under the specified attributeNameis a string, it will be wrapped in a single-element array before returning it.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getBooleanGet the value stored under the specifiedattributeNameas a boolean.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getNumberGet the value stored under the specifiedattributeNameas a number.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getEnumGet the value stored under the specifiedattributeNameas an enum.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getClassGet the value stored under the specifiedattributeNameas a class.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getClassArrayGet the value stored under the specifiedattributeNameas an array of classes.If the value stored under the specified attributeNameis a class, it will be wrapped in a single-element array before returning it.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the value
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getAnnotationGet theAnnotationAttributesstored under the specifiedattributeName.Note: if you expect an actual annotation, invoke getAnnotation(String, Class)instead.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the AnnotationAttributes
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getAnnotationGet the annotation of typeannotationTypestored under the specifiedattributeName.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- annotationType- the expected annotation type; never- null
- Returns:
- the annotation
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
- Since:
- 4.2
 
- 
getAnnotationArrayGet the array ofAnnotationAttributesstored under the specifiedattributeName.If the value stored under the specified attributeNameis an instance ofAnnotationAttributes, 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.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- Returns:
- the array of AnnotationAttributes
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
 
- 
getAnnotationArrayGet the array of typeannotationTypestored under the specifiedattributeName.If the value stored under the specified attributeNameis anAnnotation, it will be wrapped in a single-element array before returning it.- Parameters:
- attributeName- the name of the attribute to get; never- nullor empty
- annotationType- the expected annotation type; never- null
- Returns:
- the annotation array
- Throws:
- IllegalArgumentException- if the attribute does not exist or if it is not of the expected type
- Since:
- 4.2
 
- 
toString- Overrides:
- toStringin class- AbstractMap<String,- Object> 
 
- 
fromMapReturn anAnnotationAttributesinstance based on the given map.If the map is already an AnnotationAttributesinstance, 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 theAnnotationAttributes(Map)constructor.- Parameters:
- map- original source of annotation attribute key-value pairs
 
 
-