T
- The annotation type createdpublic final class AnnotationBuilder<T extends Annotation> extends Object
AnnotationBuilder is a "builder" for creating proxy Annotation instances.
This is useful when configuring dependency injection to match a qualifier
annotation that defines attributes, such as the Named
qualifier. As
an example, AnnotationBuilder can be used to construct a Named instance that
matches particular applications of that annotation:
Named proxy = new AnnotationBuilder<Named>(Named.class) .set("value", "name") .build();
The above snippet creates an instance of Named that returns the String,
"name", from its value() method. All other methods declared by
Annotation
are implemented correctly given the values configured by
the builder, or the defaults declared in the annotation definition.
This lets developers define attribute-based qualifiers easily without being forced to provide an actual annotation implementation that can be used to create instances.
The proxies returned by this builder are immutable and serializable, like
those returned by AnnotatedElement
.
Constructor and Description |
---|
AnnotationBuilder(Class<T> annotType)
Create a new AnnotationBuilder without any assigned values, that will
create annotations of the given class type.
|
Modifier and Type | Method and Description |
---|---|
T |
build()
Build an Annotation instance of type T that is configured to return the
values assigned by the various set() methods for its defined attributes.
|
static <T extends Annotation> |
of(Class<T> annotType)
Constructor method to allow the builder type to be inferred.
|
<A extends Annotation> |
set(String name,
A[] value)
As
set(String, boolean) but assigns an Annotation array to the
value. |
AnnotationBuilder<T> |
set(String name,
Annotation value)
As
set(String, boolean) but assigns an Annotation instance to
the value. |
AnnotationBuilder<T> |
set(String name,
boolean value)
Set the annotation defined member given by name to the boolean
value.
|
AnnotationBuilder<T> |
set(String name,
boolean[] value)
As
set(String, boolean) but assigns a boolean[] value. |
AnnotationBuilder<T> |
set(String name,
byte value)
As
set(String, boolean) but assigns a byte value. |
AnnotationBuilder<T> |
set(String name,
byte[] value)
As
set(String, boolean) but assigns a byte[] value. |
AnnotationBuilder<T> |
set(String name,
char value)
As
set(String, boolean) but assigns a char value. |
AnnotationBuilder<T> |
set(String name,
char[] value)
As
set(String, boolean) but assigns a char[] value. |
AnnotationBuilder<T> |
set(String name,
Class<? extends Class> value)
As
set(String, Class) but 'assigns an class value'
.A NullPointerException is thrown if value is null. |
AnnotationBuilder<T> |
set(String name,
double value)
As
set(String, boolean) but assigns a double value. |
AnnotationBuilder<T> |
set(String name,
double[] value)
As
set(String, boolean) but assigns a double[] value. |
AnnotationBuilder<T> |
set(String name,
Enum<? extends Enum> value)
As
set(String, boolean) but 'assigns an enum value'
.A NullPointerException is thrown if value is null. |
AnnotationBuilder<T> |
set(String name,
float value)
As
set(String, boolean) but assigns a float value. |
AnnotationBuilder<T> |
set(String name,
float[] value)
As
set(String, boolean) but assigns a float[] value. |
AnnotationBuilder<T> |
set(String name,
int value)
As
set(String, boolean) but assigns an int value. |
AnnotationBuilder<T> |
set(String name,
int[] value)
As
set(String, boolean) but assigns a int[] value. |
AnnotationBuilder<T> |
set(String name,
long value)
As
set(String, boolean) but assigns a long value. |
AnnotationBuilder<T> |
set(String name,
long[] value)
As
set(String, boolean) but assigns a long[] value. |
AnnotationBuilder<T> |
set(String name,
short value)
As
set(String, boolean) but assigns a short value. |
AnnotationBuilder<T> |
set(String name,
short[] value)
As
set(String, boolean) but assigns a short[] value. |
AnnotationBuilder<T> |
set(String name,
String value)
As
set(String, boolean) but assigns a String value. |
AnnotationBuilder<T> |
set(String name,
String[] value)
As
set(String, boolean) but assigns a String[] value. |
<A extends Annotation> |
setValue(A value)
Set the 'value' attribute to the given annotation.
|
<A extends Annotation> |
setValue(A[] value)
Set the 'value' attribute to the given annotation array.
|
AnnotationBuilder<T> |
setValue(boolean value)
Set the 'value' attribute to the given boolean value.
|
AnnotationBuilder<T> |
setValue(boolean[] value)
Set the 'value' attribute to the given boolean array.
|
AnnotationBuilder<T> |
setValue(byte value)
Set the 'value' attribute to the given byte value.
|
AnnotationBuilder<T> |
setValue(byte[] value)
Set the 'value' attribute to the given byte array.
|
AnnotationBuilder<T> |
setValue(char value)
Set the 'value' attribute to the given char value.
|
AnnotationBuilder<T> |
setValue(char[] value)
Set the 'value' attribute to the given char array.
|
AnnotationBuilder<T> |
setValue(Class<? extends Class> value)
Set the 'value' attribute to the given class
|
AnnotationBuilder<T> |
setValue(double value)
Set the 'value' attribute to the given double value.
|
AnnotationBuilder<T> |
setValue(double[] value)
Set the 'value' attribute to the given double array.
|
AnnotationBuilder<T> |
setValue(Enum<? extends Enum> value)
Set the 'value' attribute to the given enum.
|
AnnotationBuilder<T> |
setValue(float value)
Set the 'value' attribute to the given float value.
|
AnnotationBuilder<T> |
setValue(float[] value)
Set the 'value' attribute to the given float array.
|
AnnotationBuilder<T> |
setValue(int value)
Set the 'value' attribute to the given int value.
|
AnnotationBuilder<T> |
setValue(int[] value)
Set the 'value' attribute to the given int array.
|
AnnotationBuilder<T> |
setValue(long value)
Set the 'value' attribute to the given long value.
|
AnnotationBuilder<T> |
setValue(long[] value)
Set the 'value' attribute to the given long array.
|
AnnotationBuilder<T> |
setValue(short value)
Set the 'value' attribute to the given short value.
|
AnnotationBuilder<T> |
setValue(short[] value)
Set the 'value' attribute to the given short array.
|
AnnotationBuilder<T> |
setValue(String value)
Set the 'value' attribute to the given String value.
|
AnnotationBuilder<T> |
setValue(String[] value)
Set the 'value' attribute to the given String array.
|
public AnnotationBuilder(Class<T> annotType)
annotType
- The annotation class typeNullPointerException
- if annotType is nullIllegalArgumentException
- if annotType is not an Annotation classpublic static <T extends Annotation> AnnotationBuilder<T> of(Class<T> annotType)
T
- The type of annotation to build (type parameter).annotType
- The annotation type to build.public AnnotationBuilder<T> set(String name, boolean value)
name
- The name of the annotation attribute or member to assignvalue
- The value to assign to the specified memberNullPointerException
- if name is nullIllegalArgumentException
- if name is not a defined member in the
annotation type for this builder, or if the type is not
booleanpublic AnnotationBuilder<T> set(String name, byte value)
set(String, boolean)
but assigns a byte value.name
- value
- public AnnotationBuilder<T> set(String name, short value)
set(String, boolean)
but assigns a short value.name
- value
- public AnnotationBuilder<T> set(String name, int value)
set(String, boolean)
but assigns an int value.name
- value
- public AnnotationBuilder<T> set(String name, long value)
set(String, boolean)
but assigns a long value.name
- value
- public AnnotationBuilder<T> set(String name, char value)
set(String, boolean)
but assigns a char value.name
- value
- public AnnotationBuilder<T> set(String name, float value)
set(String, boolean)
but assigns a float value.name
- value
- public AnnotationBuilder<T> set(String name, double value)
set(String, boolean)
but assigns a double value.name
- value
- public AnnotationBuilder<T> set(String name, String value)
set(String, boolean)
but assigns a String value. Throws a
NullPointerException if value is null.name
- value
- public AnnotationBuilder<T> set(String name, Annotation value)
set(String, boolean)
but assigns an Annotation instance to
the value. A NullPointerException is thrown if value is null.name
- value
- public AnnotationBuilder<T> set(String name, boolean[] value)
set(String, boolean)
but assigns a boolean[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, byte[] value)
set(String, boolean)
but assigns a byte[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, short[] value)
set(String, boolean)
but assigns a short[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, int[] value)
set(String, boolean)
but assigns a int[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, long[] value)
set(String, boolean)
but assigns a long[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, char[] value)
set(String, boolean)
but assigns a char[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, float[] value)
set(String, boolean)
but assigns a float[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, double[] value)
set(String, boolean)
but assigns a double[] value. A
NullPointerException is thrown if the array is null.name
- value
- public AnnotationBuilder<T> set(String name, String[] value)
set(String, boolean)
but assigns a String[] value. A
NullPointerException is thrown if the array is null.name
- value
- public <A extends Annotation> AnnotationBuilder<T> set(String name, A[] value)
set(String, boolean)
but assigns an Annotation array to the
value. The array must be a proper array over the parameterized type, and
not a cast of Object[], etc. A NullPointerException is thrown if the
array is null.name
- value
- public AnnotationBuilder<T> set(String name, Enum<? extends Enum> value)
set(String, boolean)
but 'assigns an enum value'
.A NullPointerException is thrown if value is null.name
- value
- public AnnotationBuilder<T> set(String name, Class<? extends Class> value)
set(String, Class)
but 'assigns an class value'
.A NullPointerException is thrown if value is null.name
- value
- public AnnotationBuilder<T> setValue(boolean value)
value
- The boolean valuepublic AnnotationBuilder<T> setValue(byte value)
value
- The byte valuepublic AnnotationBuilder<T> setValue(short value)
value
- The short valuepublic AnnotationBuilder<T> setValue(int value)
value
- The int valuepublic AnnotationBuilder<T> setValue(long value)
value
- The long valuepublic AnnotationBuilder<T> setValue(double value)
value
- The double valuepublic AnnotationBuilder<T> setValue(float value)
value
- The float valuepublic AnnotationBuilder<T> setValue(char value)
value
- The char valuepublic AnnotationBuilder<T> setValue(String value)
value
- The String valuepublic <A extends Annotation> AnnotationBuilder<T> setValue(A value)
value
- The annotation valuepublic AnnotationBuilder<T> setValue(boolean[] value)
value
- The boolean arraypublic AnnotationBuilder<T> setValue(byte[] value)
value
- The byte arraypublic AnnotationBuilder<T> setValue(short[] value)
value
- The short arraypublic AnnotationBuilder<T> setValue(int[] value)
value
- The int arraypublic AnnotationBuilder<T> setValue(long[] value)
value
- The long arraypublic AnnotationBuilder<T> setValue(double[] value)
value
- The double arraypublic AnnotationBuilder<T> setValue(float[] value)
value
- The float arraypublic AnnotationBuilder<T> setValue(char[] value)
value
- The char arraypublic AnnotationBuilder<T> setValue(String[] value)
value
- The String arraypublic <A extends Annotation> AnnotationBuilder<T> setValue(A[] value)
value
- The annotation arraypublic AnnotationBuilder<T> setValue(Enum<? extends Enum> value)
value
- The enum type annotationpublic AnnotationBuilder<T> setValue(Class<? extends Class> value)
value
- The class type annotationpublic T build()
IllegalStateException
- if there are attributes with no default
that have not been assigned explicit valuesCopyright © 2016 GroupLens Research. All rights reserved.