A
- The annotation typepublic class AnnotationValue<A extends java.lang.annotation.Annotation> extends java.lang.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,
java.util.Map<java.lang.String,java.lang.Object> defaultValues,
ConvertibleValues<java.lang.Object> convertibleValues,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
Internal copy constructor.
|
|
AnnotationValue(java.lang.String annotationName) |
|
AnnotationValue(java.lang.String annotationName,
ConvertibleValues<java.lang.Object> convertibleValues) |
|
AnnotationValue(java.lang.String annotationName,
java.util.Map<java.lang.CharSequence,java.lang.Object> values) |
|
AnnotationValue(java.lang.String annotationName,
java.util.Map<java.lang.CharSequence,java.lang.Object> values,
java.util.Map<java.lang.String,java.lang.Object> defaultValues) |
|
AnnotationValue(java.lang.String annotationName,
java.util.Map<java.lang.CharSequence,java.lang.Object> values,
java.util.Map<java.lang.String,java.lang.Object> defaultValues,
java.lang.annotation.RetentionPolicy retentionPolicy) |
|
AnnotationValue(java.lang.String annotationName,
java.util.Map<java.lang.CharSequence,java.lang.Object> values,
java.lang.annotation.RetentionPolicy retentionPolicy) |
Modifier and Type | Method and Description |
---|---|
java.util.Optional<AnnotationClassValue<?>> |
annotationClassValue(java.lang.String member)
The
AnnotationClassValue instance for the given member. |
AnnotationClassValue<?>[] |
annotationClassValues(java.lang.String member)
The
AnnotationClassValue instances for the given member. |
java.util.Optional<java.lang.Boolean> |
booleanValue(java.lang.String member)
The boolean value of the given member.
|
java.util.Optional<java.lang.Boolean> |
booleanValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The boolean value of the given member.
|
static <T extends java.lang.annotation.Annotation> |
builder(AnnotationValue<T> annotation,
java.lang.annotation.RetentionPolicy retentionPolicy)
Start building a new annotation existing value and retention policy.
|
static <T extends java.lang.annotation.Annotation> |
builder(java.lang.Class<T> annotation)
Start building a new annotation for the given name.
|
static <T extends java.lang.annotation.Annotation> |
builder(java.lang.String annotationName)
Start building a new annotation for the given name.
|
java.util.Optional<java.lang.Class<?>> |
classValue()
The value of the annotation as a Class.
|
java.util.Optional<java.lang.Class<?>> |
classValue(java.lang.String member)
The value of the given annotation member as a Class.
|
<T> java.util.Optional<java.lang.Class<? extends T>> |
classValue(java.lang.String member,
java.lang.Class<T> requiredType)
The value of the given annotation member as a Class.
|
java.util.Optional<java.lang.Class<?>> |
classValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The value of the given annotation member as a Class.
|
java.lang.Class<?>[] |
classValues(java.lang.String member)
The value of the given annotation member as a Class.
|
boolean |
contains(java.lang.String member)
Whether a particular member is present.
|
java.util.OptionalDouble |
doubleValue()
The double value of the given member.
|
java.util.OptionalDouble |
doubleValue(java.lang.String member)
The double value of the given member.
|
java.util.OptionalDouble |
doubleValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The double value of the given member.
|
<E extends java.lang.Enum> |
enumValue(java.lang.String member,
java.lang.Class<E> enumType)
Return the enum value of the given member of the given enum type.
|
<E extends java.lang.Enum> |
enumValue(java.lang.String member,
java.lang.Class<E> enumType,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
Return the enum value of the given member of the given enum type.
|
<E extends java.lang.Enum> |
enumValues(java.lang.String member,
java.lang.Class<E> enumType)
Return the enum values of the given member of the given enum type.
|
boolean |
equals(java.lang.Object obj) |
<T> java.util.Optional<T> |
get(java.lang.CharSequence member,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name.
|
<T extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.String member,
java.lang.Class<T> type)
Gets a list of
AnnotationValue for the given member. |
java.lang.String |
getAnnotationName()
The annotation name.
|
<T extends java.lang.annotation.Annotation> |
getAnnotations(java.lang.String member)
Gets a list of
AnnotationValue for the given member. |
<T extends java.lang.annotation.Annotation> |
getAnnotations(java.lang.String member,
java.lang.Class<T> type)
Gets a list of
AnnotationValue for the given member. |
ConvertibleValues<java.lang.Object> |
getConvertibleValues() |
java.util.Set<java.lang.CharSequence> |
getMemberNames()
Resolves the names of all the present annotation members.
|
java.util.Map<java.lang.String,java.lang.String> |
getProperties(java.lang.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.
|
java.util.Map<java.lang.String,java.lang.String> |
getProperties(java.lang.String member,
java.lang.String keyMember)
Resolve properties with a custom key member.
|
<T> T |
getRequiredValue(java.lang.Class<T> type)
Get the value of the
value member of the annotation. |
<T> T |
getRequiredValue(java.lang.String member,
java.lang.Class<T> type)
Get the value of the
value member of the annotation. |
java.lang.annotation.RetentionPolicy |
getRetentionPolicy() |
<T> java.util.Optional<T> |
getValue(Argument<T> argument)
Get the value of the
value member of the annotation. |
<T> java.util.Optional<T> |
getValue(ArgumentConversionContext<T> conversionContext)
Get the value of the
value member of the annotation. |
<T> java.util.Optional<T> |
getValue(java.lang.Class<T> type)
Get the value of the
value member of the annotation. |
java.util.Map<java.lang.CharSequence,java.lang.Object> |
getValues() |
int |
hashCode() |
java.util.OptionalInt |
intValue()
The integer value of the given member.
|
java.util.OptionalInt |
intValue(java.lang.String member)
The integer value of the given member.
|
java.util.OptionalInt |
intValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The integer value of the given member.
|
boolean |
isFalse() |
boolean |
isFalse(java.lang.String member) |
boolean |
isPresent(java.lang.CharSequence member)
Is the given member present.
|
boolean |
isTrue() |
boolean |
isTrue(java.lang.String member) |
boolean |
isTrue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper) |
java.util.OptionalLong |
longValue(java.lang.String member)
The long value of the given member.
|
java.util.OptionalLong |
longValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The integer value of the given member.
|
static java.lang.Class<?>[] |
resolveClassValues(java.lang.Object value)
The classes class values for the given value.
|
static <E extends java.lang.Enum> |
resolveEnumValues(java.lang.Class<E> enumType,
java.lang.Object rawValue)
The enum values for the given enum type and raw value.
|
static java.lang.String[] |
resolveStringArray(java.lang.String[] strs,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The string[] values for the given value.
|
static java.lang.String[] |
resolveStringValues(java.lang.Object value,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The string values for the given value.
|
java.util.Optional<java.lang.String> |
stringValue()
The double value of the given member.
|
java.util.Optional<java.lang.String> |
stringValue(java.lang.String member)
The string value of the given member.
|
java.util.Optional<java.lang.String> |
stringValue(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The string value of the given member.
|
java.lang.String[] |
stringValues(java.lang.String member)
The string value of the given member.
|
java.lang.String[] |
stringValues(java.lang.String member,
java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
The string values for the given member and mapper.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
booleanValue, classValues, enumValue, enumValues, longValue, stringValues
get, get, get
public AnnotationValue(java.lang.String annotationName, java.util.Map<java.lang.CharSequence,java.lang.Object> values)
annotationName
- The annotation namevalues
- The valuespublic AnnotationValue(java.lang.String annotationName, java.util.Map<java.lang.CharSequence,java.lang.Object> values, java.lang.annotation.RetentionPolicy retentionPolicy)
annotationName
- The annotation namevalues
- The valuesretentionPolicy
- The retention policypublic AnnotationValue(java.lang.String annotationName, java.util.Map<java.lang.CharSequence,java.lang.Object> values, java.util.Map<java.lang.String,java.lang.Object> defaultValues)
annotationName
- The annotation namevalues
- The valuesdefaultValues
- The default valuespublic AnnotationValue(java.lang.String annotationName, java.util.Map<java.lang.CharSequence,java.lang.Object> values, java.util.Map<java.lang.String,java.lang.Object> defaultValues, java.lang.annotation.RetentionPolicy retentionPolicy)
annotationName
- The annotation namevalues
- The valuesdefaultValues
- The default valuesretentionPolicy
- The retention policypublic AnnotationValue(java.lang.String annotationName)
annotationName
- The annotation namepublic AnnotationValue(java.lang.String annotationName, ConvertibleValues<java.lang.Object> convertibleValues)
annotationName
- The annotation nameconvertibleValues
- The convertible values@Internal protected AnnotationValue(AnnotationValue<A> target, java.util.Map<java.lang.String,java.lang.Object> defaultValues, ConvertibleValues<java.lang.Object> convertibleValues, java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
target
- The targetdefaultValues
- The default valuesconvertibleValues
- The convertible valuesvalueMapper
- The value mapper@NonNull public final java.lang.annotation.RetentionPolicy getRetentionPolicy()
@NonNull public java.util.Map<java.lang.String,java.lang.String> getProperties(@NonNull java.lang.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 java.util.Map<java.lang.String,java.lang.String> getProperties(@NonNull java.lang.String member, java.lang.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 java.lang.Enum> java.util.Optional<E> enumValue(@NonNull java.lang.String member, @NonNull java.lang.Class<E> enumType)
enumValue
in interface AnnotationValueResolver
E
- The enum typemember
- The annotation memberenumType
- The required typeOptional
of the enum valuepublic <E extends java.lang.Enum> java.util.Optional<E> enumValue(@NonNull java.lang.String member, @NonNull java.lang.Class<E> enumType, java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
E
- The enum typemember
- The annotation memberenumType
- The required typevalueMapper
- The value mapperOptional
of the enum valuepublic <E extends java.lang.Enum> E[] enumValues(@NonNull java.lang.String member, @NonNull java.lang.Class<E> enumType)
enumValues
in interface AnnotationValueResolver
E
- The enum typemember
- The annotation memberenumType
- The required type@NonNull public java.util.Optional<java.lang.Class<?>> classValue()
classValue
in interface AnnotationValueResolver
Optional
classpublic java.util.Optional<java.lang.Class<?>> classValue(@NonNull java.lang.String member)
classValue
in interface AnnotationValueResolver
member
- The annotation memberOptional
classpublic <T> java.util.Optional<java.lang.Class<? extends T>> classValue(@NonNull java.lang.String member, @NonNull java.lang.Class<T> requiredType)
classValue
in interface AnnotationValueResolver
T
- The required typemember
- The annotation memberrequiredType
- The required typeOptional
classpublic java.util.Optional<java.lang.Class<?>> classValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- The raw value mapperOptional
class@NonNull public java.lang.String[] stringValues(@NonNull java.lang.String member)
AnnotationValueResolver
stringValues
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public java.lang.String[] stringValues(@NonNull java.lang.String member, java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The membervalueMapper
- The mapperpublic java.lang.Class<?>[] classValues(@NonNull java.lang.String member)
AnnotationValueResolver
classValues
in interface AnnotationValueResolver
member
- The annotation member@NonNull public AnnotationClassValue<?>[] annotationClassValues(@NonNull java.lang.String member)
AnnotationValueResolver
AnnotationClassValue
instances for the given member. Unlike AnnotationValueResolver.classValues(String)
this may
include classes that are no the classpath.annotationClassValues
in interface AnnotationValueResolver
member
- The annotation memberpublic java.util.Optional<AnnotationClassValue<?>> annotationClassValue(@NonNull java.lang.String member)
AnnotationValueResolver
AnnotationClassValue
instance for the given member.annotationClassValue
in interface AnnotationValueResolver
member
- The annotation memberpublic java.util.OptionalInt intValue(@NonNull java.lang.String member)
intValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public java.util.OptionalInt intValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalInt
public java.util.OptionalInt intValue()
intValue
in interface AnnotationValueResolver
OptionalInt
public java.util.OptionalLong longValue(@NonNull java.lang.String member)
AnnotationValueResolver
longValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalLong
public java.util.OptionalLong longValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalInt
public java.util.Optional<java.lang.Boolean> booleanValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptional
booleanpublic java.util.OptionalDouble doubleValue(@NonNull java.lang.String member)
doubleValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalDouble
public java.util.OptionalDouble doubleValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- The value mapperOptionalDouble
public java.util.OptionalDouble doubleValue()
doubleValue
in interface AnnotationValueResolver
OptionalDouble
public java.util.Optional<java.lang.String> stringValue(@NonNull java.lang.String member)
stringValue
in interface AnnotationValueResolver
member
- The annotation memberOptionalInt
public java.util.Optional<java.lang.String> stringValue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The annotation membervalueMapper
- An optional raw value mapperOptionalInt
public java.util.Optional<java.lang.String> stringValue()
stringValue
in interface AnnotationValueResolver
OptionalInt
public java.util.Optional<java.lang.Boolean> booleanValue(@NonNull java.lang.String member)
AnnotationValueResolver
booleanValue
in interface AnnotationValueResolver
member
- The annotation memberOptional
booleanpublic final boolean isPresent(java.lang.CharSequence member)
isPresent
in interface AnnotationValueResolver
member
- The memberpublic boolean isTrue()
isTrue
in interface AnnotationValueResolver
public boolean isTrue(java.lang.String member)
isTrue
in interface AnnotationValueResolver
member
- The memberpublic boolean isTrue(@NonNull java.lang.String member, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
member
- The membervalueMapper
- The value mapperpublic boolean isFalse()
isFalse
in interface AnnotationValueResolver
public boolean isFalse(java.lang.String member)
isFalse
in interface AnnotationValueResolver
member
- The member@NonNull public final java.lang.String getAnnotationName()
public final boolean contains(java.lang.String member)
member
- The member@NonNull public final java.util.Set<java.lang.CharSequence> getMemberNames()
@NonNull public java.util.Map<java.lang.CharSequence,java.lang.Object> getValues()
getValues
in interface AnnotationValueResolver
@NonNull public ConvertibleValues<java.lang.Object> getConvertibleValues()
public <T> java.util.Optional<T> get(java.lang.CharSequence member, ArgumentConversionContext<T> conversionContext)
ValueResolver
get
in interface ValueResolver<java.lang.CharSequence>
T
- The concrete typemember
- The nameconversionContext
- The conversion contextpublic <T> java.util.Optional<T> getValue(ArgumentConversionContext<T> conversionContext)
value
member of the annotation.T
- The typeconversionContext
- The conversion contextpublic final <T> java.util.Optional<T> getValue(Argument<T> argument)
value
member of the annotation.T
- The typeargument
- The argumentpublic final <T> java.util.Optional<T> getValue(java.lang.Class<T> type)
value
member of the annotation.T
- The typetype
- The type@NonNull public final <T> T getRequiredValue(java.lang.Class<T> type)
value
member of the annotation.T
- The typetype
- The typejava.lang.IllegalStateException
- If no member is available that conforms to the given type@NonNull public final <T> T getRequiredValue(java.lang.String member, java.lang.Class<T> type)
value
member of the annotation.T
- The typemember
- The membertype
- The typejava.lang.IllegalStateException
- If no member is available that conforms to the given name and type@NonNull public final <T extends java.lang.annotation.Annotation> java.util.List<AnnotationValue<T>> getAnnotations(java.lang.String member, java.lang.Class<T> type)
AnnotationValue
for the given member.T
- The typemember
- The membertype
- The typejava.lang.IllegalStateException
- If no member is available that conforms to the given name and type@NonNull public final <T extends java.lang.annotation.Annotation> java.util.List<AnnotationValue<T>> getAnnotations(java.lang.String member)
AnnotationValue
for the given member.T
- The typemember
- The memberjava.lang.IllegalStateException
- If no member is available that conforms to the given name and type@NonNull public final <T extends java.lang.annotation.Annotation> java.util.Optional<AnnotationValue<T>> getAnnotation(java.lang.String member, java.lang.Class<T> type)
AnnotationValue
for the given member.T
- The typemember
- The membertype
- The typejava.lang.IllegalStateException
- If no member is available that conforms to the given name and typepublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public static <T extends java.lang.annotation.Annotation> AnnotationValueBuilder<T> builder(java.lang.String annotationName)
T
- The annotation typeannotationName
- The annotation namepublic static <T extends java.lang.annotation.Annotation> AnnotationValueBuilder<T> builder(java.lang.Class<T> annotation)
T
- The annotation typeannotation
- The annotation namepublic static <T extends java.lang.annotation.Annotation> AnnotationValueBuilder<T> builder(@NonNull AnnotationValue<T> annotation, @Nullable java.lang.annotation.RetentionPolicy retentionPolicy)
T
- The annotation typeannotation
- The annotation nameretentionPolicy
- The retention policy. Defaults to runtime.@Internal @Nullable public static java.lang.String[] resolveStringValues(@Nullable java.lang.Object value, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
value
- The valuevalueMapper
- The value mapper@Internal @NonNull public static <E extends java.lang.Enum> E[] resolveEnumValues(@NonNull java.lang.Class<E> enumType, @Nullable java.lang.Object rawValue)
E
- The enum generic typeenumType
- The enum typerawValue
- The raw value@Internal public static java.lang.String[] resolveStringArray(java.lang.String[] strs, @Nullable java.util.function.Function<java.lang.Object,java.lang.Object> valueMapper)
strs
- The stringsvalueMapper
- The value mapper@Internal @Nullable public static java.lang.Class<?>[] resolveClassValues(@Nullable java.lang.Object value)
value
- The value