@Retention(value=RUNTIME) public @interface DefaultValue
Note that the default value of a property is the value that is set for the property after the default constructor was called. Obviously, the value defined by the annotation should be equal to the real default value to guarantee a correct GraphML round-trip.
To define a default value for GraphML serialization, simply annotate the getter method for that property with this annotation. For example, to define a simple default value for an integer property, you could write the following:
public class Adult { private int age = 18; @DefaultValue(intValue = 18, valueType = DefaultValue.ValueType.INT_TYPE) public int getAge() { return age; } public void setAge(final int age) { this.age = age; } }The annotation specifies that the value type of this property is of the primitive integer type with the integer value of 18. The output of the serialized class with
age
set to 18
would be:
<Adult/>Opposed to the output with
age
set to 21
:
<Adult age="21"/>
classValue()
must be specified with the enum class as well
as the name of the enum constant using the stringValue()
field.valueType()
= STRING_CONVERTED_TYPE, the default value of this field),
the stringValue()
as well as the classValue()
are needed again.
As an example with a string converted type as default value, consider the previous example with an arbitrary type as property:
import java.awt.Color; public class Adult { private Color eyeColor; @DefaultValue(stringValue = "Green", classValue = Color.class) public Color getEyeColor() { return eyeColor; } public void setEyeColor(final Color eyeColor) { this.eyeColor = eyeColor; } }The annotation defines the value "Green" of the class
Color
. To resolve this, the ColorValueSerializer
is used
to convert the string "Green" to a Color
object. This value serializer is already part of the yFiles library standard value serializers,
however, you can always add your own to serialize/deserialize your model.
The output of the serialized class with eyeColor
set to Color.GREEN
would be:
<Adult/>Opposed to the output with
eyeColor
set to #FFA7E9
:
<Adult eyeColor="#FFA7E9"/>
Modifier and Type | Optional Element and Description |
---|---|
boolean |
booleanValue
Holds the boolean default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#BOOLEAN_TYPE . |
byte |
byteValue
Holds the byte default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#BYTE_TYPE . |
char |
charValue
Holds the char default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#CHAR_TYPE . |
Class<?> |
classValue
This field serves multiple purposes.
|
double |
doubleValue
Holds the double default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#DOUBLE_TYPE . |
float |
floatValue
Holds the float default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#FLOAT_TYPE . |
int |
intValue
Holds the integer default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#INT_TYPE . |
long |
longValue
Holds the long default value for DefaultValues which have their
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#LONG_TYPE . |
String |
stringValue
Holds the
String default value for DefaultValues which have their com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_TYPE . |
DefaultValue.ValueType |
valueType
Defines the type of the value defined by the
@DefaultValue annotation. |
public abstract boolean booleanValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#BOOLEAN_TYPE
.
The default value of this is false
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#BOOLEAN_TYPE
public abstract byte byteValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#BYTE_TYPE
.
The default value of this is 0
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#BYTE_TYPE
public abstract char charValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#CHAR_TYPE
.
The default value of this is 0
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#CHAR_TYPE
public abstract Class<?> classValue
Firstly, it holds the class default value for DefaultValues which have their com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#CLASS_TYPE
.
Secondly, it holds the enum class that is required for parsing the enum field for DefaultValues which
have their com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#ENUM_TYPE
.
And lastly, if the com.yworks.yfiles.annotations.DefaultValue#valueType()
is set to its default value (com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_CONVERTED_TYPE
)
then the value returned by this fields determines which ValueSerializer
is chosen to convert the string defined in stringValue()
to
an object of the same type.
The default value of this is Object.class
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#CLASS_TYPE
,
com.yworks.yfiles.annotations.DefaultValue.ValueType#ENUM_TYPE
,
com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_CONVERTED_TYPE
public abstract double doubleValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#DOUBLE_TYPE
.
The default value of this is 0.0d
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#DOUBLE_TYPE
public abstract float floatValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#FLOAT_TYPE
.
The default value of this is 0.0f
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#FLOAT_TYPE
public abstract int intValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#INT_TYPE
.
The default value of this is 0
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#INT_TYPE
public abstract long longValue
com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#LONG_TYPE
.
The default value of this is 0
.
com.yworks.yfiles.annotations.DefaultValue.ValueType#LONG_TYPE
public abstract String stringValue
String
default value for DefaultValues which have their com.yworks.yfiles.annotations.DefaultValue#valueType()
set to com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_TYPE
.
The default value of this is the empty string.
com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_TYPE
public abstract DefaultValue.ValueType valueType
@DefaultValue
annotation.
Note that the chosen value type should match with the value defined in the annotation fields to ensure a correct (de-)serialization.
The default value of this is com.yworks.yfiles.annotations.DefaultValue.ValueType#STRING_CONVERTED_TYPE
com.yworks.yfiles.annotations.DefaultValue.ValueType