public final class TLcdDataProperty extends Object implements ILcdAnnotatedElement
Represents a property of a type. A property always belongs to a certain type (called
its declaring type) and also has a certain type (called its type). Many-valued properties
have a CollectionType
that defines what kind of collection (list, set or map) is
represented. The combination of the property's type and its CollectionType
constrain
the values that a property can have for a data object as follows:
getType()
.CollectionType
.
java.util.List
. The elements of the list
are instances of the type returned by getType()
.java.util.Set
. The elements of the set
are instances of the type returned by getType()
.java.util.Map
. The values of the map are
instances of the type returned by getType()
. The keys are instances of
the type returned by getMapKeyType()
.Properties can be defined by first creating a TLcdDataModelBuilder
, then defining types within that data
model using TLcdDataTypeBuilder
, and finally defining properties on these types using
TLcdDataPropertyBuilder
. See TLcdDataModelBuilder
for a brief example.
Existing properties can be retrieved via the TLcdDataType
on which they are defined.
Instances of this class are thread safe. Once an instance has been created, there is no public API to modify it. The only exception is the annotations and these are thread safe.
TLcdDataModel
,
TLcdDataType
,
TLcdDataModelBuilder
,
TLcdDataTypeBuilder
,
TLcdDataPropertyBuilder
Modifier and Type | Class and Description |
---|---|
static class |
TLcdDataProperty.CollectionType
Enumeration that defines the different collection types that are supported for
multi-valued properties.
|
Modifier and Type | Method and Description |
---|---|
<T extends ILcdAnnotation> |
addAnnotation(ILcdAnnotation aAnnotation)
Adds the given annotation to this element.
|
boolean |
equals(Object obj) |
<T extends ILcdAnnotation> |
getAnnotation(Class<T> aAnnotationType)
Returns the element's annotation for the specified class if such an annotation is present,
else null.
|
Collection<ILcdAnnotation> |
getAnnotations()
Returns all annotations present on this element as an unmodifiable collection.
|
TLcdDataProperty.CollectionType |
getCollectionType()
Returns the collection type of this property.
|
TLcdDataType |
getDeclaringType()
Returns the type that declares this property.
|
Object |
getDefaultValue()
Returns the default value for this property.
|
String |
getDisplayName()
Returns a displayable name for this property, suitable for usage in user interfaces.
|
int |
getIndex()
Returns the index of this property in the list of properties of its declaring type.
|
TLcdDataType |
getMapKeyType()
For properties of which the collection type is
MAP , returns the type of the keys. |
String |
getName()
Returns the name of this property.
|
TLcdDataType |
getType()
Returns the type of this property.
|
boolean |
hasDefaultValue()
Determines if this property has a default value or not.
|
int |
hashCode() |
boolean |
isAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType)
Returns true if an annotation for the specified class is present on this element,
else false.
|
boolean |
isCollection()
Determines if the property is many-valued.
|
boolean |
isContained()
Determines if this property represents composition (as opposed to mere aggregation).
|
boolean |
isNullable()
Determines if
null values are acceptable for this property. |
<T extends ILcdAnnotation> |
removeAnnotation(Class<T> aAnnotationClass)
Removes the annotation of the given class from this element.
|
String |
toString() |
public TLcdDataType getDeclaringType()
getDeclaringType().getDeclaredProperties().contains( this )
always
holds true.public boolean hasDefaultValue()
public Object getDefaultValue()
null
is returned. null
may also be the default value for this property.
hasDefaultValue()
can be used to disambiguate between null
as default value and
null
as indication of no default value.hasDefaultValue()
public int getIndex()
Returns the index of this property in the list of properties of its declaring type.
Expressed in pseudo-code, this would look like getDeclaringType().getProperties().indexOf( this )
.
This method is provided to allow simple but efficient implementations of the ILcdDataObject
interface.
public String getName()
public TLcdDataType getType()
public boolean isCollection()
getCollectionType() != null
.
Note that values for many-valued properties not necessarily
implement java.util.Collection
as Map
is not an extension of
Collection
.
getCollectionType()
public TLcdDataProperty.CollectionType getCollectionType()
null
is returned. The collection type defines
which values are valid for this property.
LIST
: valid values for this property implement java.util.List
SET
: valid values for this property implement java.util.Set
MAP
: valid values for this property implement java.util.Map
public TLcdDataType getMapKeyType()
MAP
, returns the type of the keys.
Otherwise
returns null
. The values in the map are of the type returned by
getType()
.public boolean isNullable()
null
values are acceptable for this property. In case of collection properties,
determines if the collection can be empty.null
values or empty collections are acceptablepublic <T extends ILcdAnnotation> T getAnnotation(Class<T> aAnnotationType)
ILcdAnnotatedElement
Returns the element's annotation for the specified class if such an annotation is present, else null.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
null
is returned.
getAnnotation
in interface ILcdAnnotatedElement
aAnnotationType
- - the Class object corresponding to the annotation typepublic boolean isAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType)
ILcdAnnotatedElement
Returns true if an annotation for the specified class is present on this element, else false. This method is designed primarily for convenient access to marker annotations.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
false
is returned.
isAnnotationPresent
in interface ILcdAnnotatedElement
aAnnotationType
- the Class object corresponding to the annotation classpublic Collection<ILcdAnnotation> getAnnotations()
ILcdAnnotatedElement
getAnnotations
in interface ILcdAnnotatedElement
public <T extends ILcdAnnotation> T addAnnotation(ILcdAnnotation aAnnotation)
ILcdAnnotatedElement
addAnnotation
in interface ILcdAnnotatedElement
aAnnotation
- the annotation to addpublic <T extends ILcdAnnotation> T removeAnnotation(Class<T> aAnnotationClass)
ILcdAnnotatedElement
Removes the annotation of the given class from this element.
Note that the exact annotation class needs to be passed as parameter.
In other words, in case the element
is only annotated with instances of subclasses of the given annotation class,
nothing is removed and null
is returned.
removeAnnotation
in interface ILcdAnnotatedElement
aAnnotationClass
- the class of annotation to removepublic boolean isContained()
public String getDisplayName()
ILcdDataModelDisplayNameProvider