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) |
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
<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.
|
boolean |
equals(Object obj) |
<T> Optional<T> |
get(CharSequence member,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name.
|
<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. |
<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.
|
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 integer value of the given member.
|
static Class<?>[] |
resolveClassValues(Object value)
The classes class values for the given 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<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 value of the given member.
|
String[] |
stringValues(String member,
Function<Object,Object> valueMapper)
The string values for the given member and mapper.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
booleanValue, classValues, enumValue, longValue, stringValues
get, get, get
public AnnotationValue(String annotationName, Map<CharSequence,Object> values)
annotationName
- The annotation namevalues
- The valuespublic AnnotationValue(String annotationName, Map<CharSequence,Object> values, Map<String,Object> defaultValues)
annotationName
- The annotation namevalues
- The valuesdefaultValues
- The default valuespublic AnnotationValue(String annotationName)
annotationName
- The annotation namepublic 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 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 AnnotationValueResolver
E
- 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 value@Nonnull public Optional<Class<?>> classValue()
classValue
in interface AnnotationValueResolver
Optional
classpublic Optional<Class<?>> classValue(@Nonnull String member)
classValue
in interface AnnotationValueResolver
member
- The annotation memberOptional
classpublic <T> Optional<Class<? extends T>> classValue(@Nonnull String member, @Nonnull Class<T> requiredType)
classValue
in interface AnnotationValueResolver
T
- 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)
AnnotationValueResolver
stringValues
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public String[] stringValues(@Nonnull String member, Function<Object,Object> valueMapper)
member
- The membervalueMapper
- The mapperpublic Class<?>[] classValues(@Nonnull String member)
AnnotationValueResolver
classValues
in interface AnnotationValueResolver
member
- The annotation memberOptional
classpublic OptionalInt intValue(@Nonnull String member)
intValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public OptionalInt intValue(@Nonnull String member, @Nullable Function<Object,Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalInt
public OptionalInt intValue()
intValue
in interface AnnotationValueResolver
OptionalInt
public OptionalLong longValue(@Nonnull String member)
AnnotationValueResolver
longValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalLong
public OptionalLong longValue(@Nonnull String member, @Nullable Function<Object,Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalInt
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 AnnotationValueResolver
member
- The annotation memberOptionalDouble
public OptionalDouble doubleValue(@Nonnull String member, @Nullable Function<Object,Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalDouble
public OptionalDouble doubleValue()
doubleValue
in interface AnnotationValueResolver
OptionalDouble
public Optional<String> stringValue(@Nonnull String member)
stringValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public Optional<String> stringValue(@Nonnull String member, @Nullable Function<Object,Object> valueMapper)
member
- The annotation membervalueMapper
- An optional raw value mapperOptionalInt
public Optional<String> stringValue()
stringValue
in interface AnnotationValueResolver
OptionalInt
public Optional<Boolean> booleanValue(@Nonnull String member)
AnnotationValueResolver
booleanValue
in interface AnnotationValueResolver
member
- The annotation memberOptional
booleanpublic final boolean isPresent(CharSequence member)
isPresent
in interface AnnotationValueResolver
member
- The memberpublic boolean isTrue()
isTrue
in interface AnnotationValueResolver
public boolean isTrue(String member)
isTrue
in interface AnnotationValueResolver
member
- The memberpublic boolean isTrue(@Nonnull String member, @Nullable Function<Object,Object> valueMapper)
member
- The membervalueMapper
- The value mapperpublic boolean isFalse()
isFalse
in interface AnnotationValueResolver
public boolean isFalse(String member)
isFalse
in interface AnnotationValueResolver
member
- 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)
ValueResolver
get
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 final <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 final <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 final <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 typepublic static <T extends Annotation> AnnotationValueBuilder<T> builder(String annotationName)
T
- The annotation typeannotationName
- The annotation namepublic static <T extends Annotation> AnnotationValueBuilder<T> builder(Class<T> annotation)
T
- The annotation typeannotation
- The annotation name@Internal @Nullable public static String[] resolveStringValues(@Nullable Object value, @Nullable Function<Object,Object> valueMapper)
value
- The valuevalueMapper
- The value mapper@Internal public static String[] resolveStringArray(String[] strs, @Nullable Function<Object,Object> valueMapper)
strs
- The stringsvalueMapper
- The value mapper