A - The annotation typepublic class AnnotationValue<A extends Annotation> extends Object implements AnnotationValueResolver
This class implements the AnnotationValueResolver interface and methods such as ValueResolver.get(CharSequence, Class) can be used to retrieve the values of annotation members.
If a member is not present then the methods of the class will attempt to resolve the default value for a given annotation member. In this sense the behaviour of this class is similar to how
a implementation of Annotation behaves.
| Modifier | Constructor and Description |
|---|---|
protected |
AnnotationValue(AnnotationValue<A> target,
Map<String,Object> defaultValues,
ConvertibleValues<Object> convertibleValues,
Function<Object,Object> valueMapper)
Internal copy constructor.
|
|
AnnotationValue(String annotationName) |
|
AnnotationValue(String annotationName,
ConvertibleValues<Object> convertibleValues) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values,
Map<String,Object> defaultValues) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values,
Map<String,Object> defaultValues,
RetentionPolicy retentionPolicy) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values,
Map<String,Object> defaultValues,
RetentionPolicy retentionPolicy,
List<AnnotationValue<?>> stereotypes) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values,
RetentionPolicy retentionPolicy) |
|
AnnotationValue(String annotationName,
Map<CharSequence,Object> values,
RetentionPolicy retentionPolicy,
List<AnnotationValue<?>> stereotypes) |
| Modifier and Type | Method and Description |
|---|---|
Optional<AnnotationClassValue<?>> |
annotationClassValue(String member)
The
AnnotationClassValue instance for the given member. |
AnnotationClassValue<?>[] |
annotationClassValues(String member)
The
AnnotationClassValue instances for the given member. |
Optional<Boolean> |
booleanValue(String member)
The boolean value of the given member.
|
Optional<Boolean> |
booleanValue(String member,
Function<Object,Object> valueMapper)
The boolean value of the given member.
|
boolean[] |
booleanValues(String member)
The boolean[] value for the given member.
|
static <T extends Annotation> |
builder(AnnotationValue<T> annotation,
RetentionPolicy retentionPolicy)
Start building a new annotation existing value and retention policy.
|
static <T extends Annotation> |
builder(Class<T> annotation)
Start building a new annotation for the given name.
|
static <T extends Annotation> |
builder(String annotationName)
Start building a new annotation for the given name.
|
static <T extends Annotation> |
builder(String annotationName,
RetentionPolicy retentionPolicy)
Start building a new annotation for the given name.
|
Optional<Byte> |
byteValue(String member)
The byte value of the given member.
|
byte[] |
byteValues(String member)
The byte[] value for the given member.
|
Optional<Character> |
charValue(String member)
The char value of the given member.
|
char[] |
charValues(String member)
The char[] value for the given member.
|
Optional<Class<?>> |
classValue()
The value of the annotation as a Class.
|
Optional<Class<?>> |
classValue(String member)
The value of the given annotation member as a Class.
|
<T> Optional<Class<? extends T>> |
classValue(String member,
Class<T> requiredType)
The value of the given annotation member as a Class.
|
Optional<Class<?>> |
classValue(String member,
Function<Object,Object> valueMapper)
The value of the given annotation member as a Class.
|
Class<?>[] |
classValues(String member)
The value of the given annotation member as a Class.
|
boolean |
contains(String member)
Whether a particular member is present.
|
OptionalDouble |
doubleValue()
The double value of the given member.
|
OptionalDouble |
doubleValue(String member)
The double value of the given member.
|
OptionalDouble |
doubleValue(String member,
Function<Object,Object> valueMapper)
The double value of the given member.
|
double[] |
doubleValues(String member)
The double[] value for the given member.
|
<E extends Enum> |
enumValue(String member,
Class<E> enumType)
Return the enum value of the given member of the given enum type.
|
<E extends Enum> |
enumValue(String member,
Class<E> enumType,
Function<Object,Object> valueMapper)
Return the enum value of the given member of the given enum type.
|
<E extends Enum> |
enumValues(String member,
Class<E> enumType)
Return the enum values of the given member of the given enum type.
|
boolean |
equals(Object obj) |
Optional<Float> |
floatValue(String member)
The double value of the given member.
|
Optional<Float> |
floatValue(String member,
Function<Object,Object> valueMapper)
The double value of the given member.
|
float[] |
floatValues(String member)
The float[] value for the given member.
|
<T> Optional<T> |
get(CharSequence member,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name.
|
<T extends Annotation> |
getAnnotation(String member)
Gets a list of
AnnotationValue for the given member. |
<T extends Annotation> |
getAnnotation(String member,
Class<T> type)
Gets a list of
AnnotationValue for the given member. |
String |
getAnnotationName()
The annotation name.
|
<T extends Annotation> |
getAnnotations(String member)
Gets a list of
AnnotationValue for the given member. |
<T extends Annotation> |
getAnnotations(String member,
Class<T> type)
Gets a list of
AnnotationValue for the given member. |
ConvertibleValues<Object> |
getConvertibleValues() |
Set<CharSequence> |
getMemberNames()
Resolves the names of all the present annotation members.
|
Map<String,String> |
getProperties(String member)
Resolves a map of properties for a member that is an array of annotations that have members called "name" or "key" to represent the key and "value" to represent the value.
|
Map<String,String> |
getProperties(String member,
String keyMember)
Resolve properties with a custom key member.
|
<T> T |
getRequiredValue(Class<T> type)
Get the value of the
value member of the annotation. |
<T> T |
getRequiredValue(String member,
Class<T> type)
Get the value of the
value member of the annotation. |
RetentionPolicy |
getRetentionPolicy() |
List<AnnotationValue<?>> |
getStereotypes() |
<T> Optional<T> |
getValue(Argument<T> argument)
Get the value of the
value member of the annotation. |
<T> Optional<T> |
getValue(ArgumentConversionContext<T> conversionContext)
Get the value of the
value member of the annotation. |
<T> Optional<T> |
getValue(Class<T> type)
Get the value of the
value member of the annotation. |
Map<CharSequence,Object> |
getValues() |
int |
hashCode() |
OptionalInt |
intValue()
The integer value of the given member.
|
OptionalInt |
intValue(String member)
The integer value of the given member.
|
OptionalInt |
intValue(String member,
Function<Object,Object> valueMapper)
The integer value of the given member.
|
int[] |
intValues(String member)
The int[] value for the given member.
|
boolean |
isFalse() |
boolean |
isFalse(String member) |
boolean |
isPresent(CharSequence member)
Is the given member present.
|
boolean |
isTrue() |
boolean |
isTrue(String member) |
boolean |
isTrue(String member,
Function<Object,Object> valueMapper) |
OptionalLong |
longValue(String member)
The long value of the given member.
|
OptionalLong |
longValue(String member,
Function<Object,Object> valueMapper)
The long value of the given member.
|
long[] |
longValues(String member)
The long[] value for the given member.
|
static Class<?>[] |
resolveClassValues(Object value)
The classes class values for the given value.
|
static <E extends Enum> |
resolveEnumValues(Class<E> enumType,
Object rawValue)
The enum values for the given enum type and raw value.
|
static String[] |
resolveStringArray(String[] strs,
Function<Object,Object> valueMapper)
The string[] values for the given value.
|
static String[] |
resolveStringValues(Object value,
Function<Object,Object> valueMapper)
The string values for the given value.
|
Optional<Short> |
shortValue(String member)
The short value of the given member.
|
Optional<Short> |
shortValue(String member,
Function<Object,Object> valueMapper)
The short value of the given member.
|
short[] |
shortValues(String member)
The short[] value for the given member.
|
Optional<String> |
stringValue()
The double value of the given member.
|
Optional<String> |
stringValue(String member)
The string value of the given member.
|
Optional<String> |
stringValue(String member,
Function<Object,Object> valueMapper)
The string value of the given member.
|
String[] |
stringValues(String member)
The string values for the given member.
|
String[] |
stringValues(String member,
Function<Object,Object> valueMapper)
The string values for the given member and mapper.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitbooleanValue, booleanValues, byteValue, byteValues, charValue, charValues, classValues, doubleValues, enumValue, enumValues, floatValue, floatValues, intValues, longValue, longValues, shortValue, shortValues, stringValuesget, get, get@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values)
annotationName - The annotation namevalues - The values@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy)
annotationName - The annotation namevalues - The valuesretentionPolicy - The retention policy@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values, RetentionPolicy retentionPolicy, List<AnnotationValue<?>> stereotypes)
annotationName - The annotation namevalues - The valuesretentionPolicy - The retention policystereotypes - The stereotypes of the annotation@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values, Map<String,Object> defaultValues)
annotationName - The annotation namevalues - The valuesdefaultValues - The default values@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values, Map<String,Object> defaultValues, RetentionPolicy retentionPolicy)
annotationName - The annotation namevalues - The valuesdefaultValues - The default valuesretentionPolicy - The retention policy@Internal public AnnotationValue(String annotationName, Map<CharSequence,Object> values, Map<String,Object> defaultValues, RetentionPolicy retentionPolicy, List<AnnotationValue<?>> stereotypes)
annotationName - The annotation namevalues - The valuesdefaultValues - The default valuesretentionPolicy - The retention policystereotypes - The stereotypes of the annotation@Internal public AnnotationValue(String annotationName)
annotationName - The annotation name@Internal public AnnotationValue(String annotationName, ConvertibleValues<Object> convertibleValues)
annotationName - The annotation nameconvertibleValues - The convertible values@Internal protected AnnotationValue(AnnotationValue<A> target, Map<String,Object> defaultValues, ConvertibleValues<Object> convertibleValues, Function<Object,Object> valueMapper)
target - The targetdefaultValues - The default valuesconvertibleValues - The convertible valuesvalueMapper - The value mapper@NonNull public final RetentionPolicy getRetentionPolicy()
@Nullable public List<AnnotationValue<?>> getStereotypes()
@NonNull public Map<String,String> getProperties(@NonNull String member)
For example consider the following annotation definition:
@PropertySource({ @Property(name = "one", value = "1"), @Property(name = "two", value = "2")})
public class MyBean {
...
}
You can use this method to resolve the values of the PropertySource annotation such that the following assertion is true:
annotationValue.getProperties("value") == [one:1, two:2]
member - The memberpublic Map<String,String> getProperties(@NonNull String member, String keyMember)
member - The member to resolve the properties fromkeyMember - The member of the sub annotation that represents the key.getProperties(String)public <E extends Enum> Optional<E> enumValue(@NonNull String member, @NonNull Class<E> enumType)
enumValue in interface AnnotationValueResolverE - The enum typemember - The annotation memberenumType - The required typeOptional of the enum valuepublic <E extends Enum> Optional<E> enumValue(@NonNull String member, @NonNull Class<E> enumType, Function<Object,Object> valueMapper)
E - The enum typemember - The annotation memberenumType - The required typevalueMapper - The value mapperOptional of the enum valuepublic <E extends Enum> E[] enumValues(@NonNull String member, @NonNull Class<E> enumType)
enumValues in interface AnnotationValueResolverE - The enum typemember - The annotation memberenumType - The required type@NonNull public Optional<Class<?>> classValue()
classValue in interface AnnotationValueResolverOptional classpublic Optional<Class<?>> classValue(@NonNull String member)
classValue in interface AnnotationValueResolvermember - The annotation memberOptional classpublic <T> Optional<Class<? extends T>> classValue(@NonNull String member, @NonNull Class<T> requiredType)
classValue in interface AnnotationValueResolverT - The required typemember - The annotation memberrequiredType - The required typeOptional classpublic Optional<Class<?>> classValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The raw value mapperOptional class@NonNull public String[] stringValues(@NonNull String member)
AnnotationValueResolverstringValues in interface AnnotationValueResolvermember - The annotation memberStringpublic boolean[] booleanValues(String member)
AnnotationValueResolverbooleanValues in interface AnnotationValueResolvermember - The annotation memberbooleanpublic byte[] byteValues(String member)
AnnotationValueResolverbyteValues in interface AnnotationValueResolvermember - The annotation memberbytepublic char[] charValues(String member)
AnnotationValueResolvercharValues in interface AnnotationValueResolvermember - The annotation membercharpublic int[] intValues(String member)
AnnotationValueResolverintValues in interface AnnotationValueResolvermember - The annotation memberintpublic double[] doubleValues(String member)
AnnotationValueResolverdoubleValues in interface AnnotationValueResolvermember - The annotation memberdoublepublic long[] longValues(String member)
AnnotationValueResolverlongValues in interface AnnotationValueResolvermember - The annotation memberlongpublic float[] floatValues(String member)
AnnotationValueResolverfloatValues in interface AnnotationValueResolvermember - The annotation memberfloatpublic short[] shortValues(String member)
AnnotationValueResolvershortValues in interface AnnotationValueResolvermember - The annotation membershortpublic String[] stringValues(@NonNull String member, Function<Object,Object> valueMapper)
member - The membervalueMapper - The mapperpublic Class<?>[] classValues(@NonNull String member)
AnnotationValueResolverclassValues in interface AnnotationValueResolvermember - The annotation member@NonNull public AnnotationClassValue<?>[] annotationClassValues(@NonNull String member)
AnnotationValueResolverAnnotationClassValue instances for the given member. Unlike AnnotationValueResolver.classValues(String) this may
include classes that are no the classpath.annotationClassValues in interface AnnotationValueResolvermember - The annotation memberpublic Optional<AnnotationClassValue<?>> annotationClassValue(@NonNull String member)
AnnotationValueResolverAnnotationClassValue instance for the given member.annotationClassValue in interface AnnotationValueResolvermember - The annotation memberpublic OptionalInt intValue(@NonNull String member)
intValue in interface AnnotationValueResolvermember - The annotation memberOptionalIntpublic OptionalInt intValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The value mapperOptionalIntpublic Optional<Byte> byteValue(String member)
AnnotationValueResolverbyteValue in interface AnnotationValueResolvermember - The annotation memberOptional of Bytepublic Optional<Character> charValue(String member)
AnnotationValueResolvercharValue in interface AnnotationValueResolvermember - The annotation memberOptional of Characterpublic OptionalInt intValue()
intValue in interface AnnotationValueResolverOptionalIntpublic OptionalLong longValue(@NonNull String member)
AnnotationValueResolverlongValue in interface AnnotationValueResolvermember - The annotation memberOptionalLongpublic OptionalLong longValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The value mapperOptionalLongpublic Optional<Short> shortValue(@NonNull String member)
AnnotationValueResolvershortValue in interface AnnotationValueResolvermember - The annotation memberOptional of Shortpublic Optional<Short> shortValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
public Optional<Boolean> booleanValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The value mapperOptional booleanpublic OptionalDouble doubleValue(@NonNull String member)
doubleValue in interface AnnotationValueResolvermember - The annotation memberOptionalDoublepublic OptionalDouble doubleValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The value mapperOptionalDoublepublic Optional<Float> floatValue(String member)
AnnotationValueResolverfloatValue in interface AnnotationValueResolvermember - The annotation memberOptionalDoublepublic Optional<Float> floatValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - The value mapperOptionalDoublepublic OptionalDouble doubleValue()
doubleValue in interface AnnotationValueResolverOptionalDoublepublic Optional<String> stringValue(@NonNull String member)
stringValue in interface AnnotationValueResolvermember - The annotation memberOptionalIntpublic Optional<String> stringValue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The annotation membervalueMapper - An optional raw value mapperOptionalIntpublic Optional<String> stringValue()
stringValue in interface AnnotationValueResolverOptionalIntpublic Optional<Boolean> booleanValue(@NonNull String member)
AnnotationValueResolverbooleanValue in interface AnnotationValueResolvermember - The annotation memberOptional booleanpublic final boolean isPresent(CharSequence member)
isPresent in interface AnnotationValueResolvermember - The memberpublic boolean isTrue()
isTrue in interface AnnotationValueResolverpublic boolean isTrue(String member)
isTrue in interface AnnotationValueResolvermember - The memberpublic boolean isTrue(@NonNull String member, @Nullable Function<Object,Object> valueMapper)
member - The membervalueMapper - The value mapperpublic boolean isFalse()
isFalse in interface AnnotationValueResolverpublic boolean isFalse(String member)
isFalse in interface AnnotationValueResolvermember - The member@NonNull public final String getAnnotationName()
public final boolean contains(String member)
member - The member@NonNull public final Set<CharSequence> getMemberNames()
@NonNull public Map<CharSequence,Object> getValues()
getValues in interface AnnotationValueResolver@NonNull public ConvertibleValues<Object> getConvertibleValues()
public <T> Optional<T> get(CharSequence member, ArgumentConversionContext<T> conversionContext)
ValueResolverget in interface ValueResolver<CharSequence>T - The concrete typemember - The nameconversionContext - The conversion contextpublic <T> Optional<T> getValue(ArgumentConversionContext<T> conversionContext)
value member of the annotation.T - The typeconversionContext - The conversion contextpublic final <T> Optional<T> getValue(Argument<T> argument)
value member of the annotation.T - The typeargument - The argumentpublic final <T> Optional<T> getValue(Class<T> type)
value member of the annotation.T - The typetype - The type@NonNull public final <T> T getRequiredValue(Class<T> type)
value member of the annotation.T - The typetype - The typeIllegalStateException - If no member is available that conforms to the given type@NonNull public final <T> T getRequiredValue(String member, Class<T> type)
value member of the annotation.T - The typemember - The membertype - The typeIllegalStateException - If no member is available that conforms to the given name and type@NonNull public <T extends Annotation> List<AnnotationValue<T>> getAnnotations(String member, Class<T> type)
AnnotationValue for the given member.T - The typemember - The membertype - The typeIllegalStateException - If no member is available that conforms to the given name and type@NonNull public <T extends Annotation> List<AnnotationValue<T>> getAnnotations(String member)
AnnotationValue for the given member.T - The typemember - The memberIllegalStateException - If no member is available that conforms to the given name and type@NonNull public <T extends Annotation> Optional<AnnotationValue<T>> getAnnotation(String member, Class<T> type)
AnnotationValue for the given member.T - The typemember - The membertype - The typeIllegalStateException - If no member is available that conforms to the given name and type@NonNull public <T extends Annotation> Optional<AnnotationValue<T>> getAnnotation(@NonNull String member)
AnnotationValue for the given member.T - The typemember - The memberIllegalStateException - If no member is available that conforms to the given name and typepublic static <T extends Annotation> AnnotationValueBuilder<T> builder(String annotationName)
T - The annotation typeannotationName - The annotation namepublic static <T extends Annotation> AnnotationValueBuilder<T> builder(String annotationName, RetentionPolicy retentionPolicy)
T - The annotation typeannotationName - The annotation nameretentionPolicy - The retention policypublic static <T extends Annotation> AnnotationValueBuilder<T> builder(Class<T> annotation)
T - The annotation typeannotation - The annotation namepublic static <T extends Annotation> AnnotationValueBuilder<T> builder(@NonNull AnnotationValue<T> annotation, @Nullable RetentionPolicy retentionPolicy)
T - The annotation typeannotation - The annotation nameretentionPolicy - The retention policy. Defaults to runtime.@Internal @Nullable public static String[] resolveStringValues(@Nullable Object value, @Nullable Function<Object,Object> valueMapper)
value - The valuevalueMapper - The value mapper@Internal @NonNull public static <E extends Enum> E[] resolveEnumValues(@NonNull Class<E> enumType, @Nullable Object rawValue)
E - The enum generic typeenumType - The enum typerawValue - The raw value@Internal public static String[] resolveStringArray(String[] strs, @Nullable Function<Object,Object> valueMapper)
strs - The stringsvalueMapper - The value mapper