Class TLcdDataProperty
- All Implemented Interfaces:
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:
- Values for single-valued properties are instances of the type returned by
getType(). - Values for many-valued properties are determined by the property's
CollectionType.- LIST: values are instances of
java.util.List. The elements of the list are instances of the type returned bygetType(). - SET: values are instances of
java.util.Set. The elements of the set are instances of the type returned bygetType(). - MAP: values are instances of
java.util.Map. The values of the map are instances of the type returned bygetType(). The keys are instances of the type returned bygetMapKeyType().
- LIST: values are instances of
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.
- Since:
- 10.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration that defines the different collection types that are supported for multi-valued properties. -
Method Summary
Modifier and TypeMethodDescription<T extends ILcdAnnotation>
TaddAnnotation(ILcdAnnotation aAnnotation) Adds the given annotation to this element.boolean<T extends ILcdAnnotation>
TgetAnnotation(Class<T> aAnnotationType) Returns the element's annotation for the specified class if such an annotation is present, else null.Returns all annotations present on this element as an unmodifiable collection.Returns the collection type of this property.Returns the type that declares this property.Returns the default value for this property.Returns a displayable name for this property, suitable for usage in user interfaces.intgetIndex()Returns the index of this property in the list of properties of its declaring type.For properties of which the collection type isMAP, returns the type of the keys.getName()Returns the name of this property.Returns the original name of this property, as it was defined in the source data.getType()Returns the type of this property.booleanDetermines if this property has a default value or not.inthashCode()booleanisAnnotationPresent(Class<? extends ILcdAnnotation> aAnnotationType) Returns true if an annotation for the specified class is present on this element, else false.booleanDetermines if the property is many-valued.booleanDetermines if this property represents composition (as opposed to mere aggregation).booleanDetermines ifnullvalues are acceptable for this property.<T extends ILcdAnnotation>
TremoveAnnotation(Class<T> aAnnotationClass) Removes the annotation of the given class from this element.toString()
-
Method Details
-
getDeclaringType
Returns the type that declares this property. The conditiongetDeclaringType().getDeclaredProperties().contains( this )always holds true.- Returns:
- the type on which this property is declared
-
hasDefaultValue
public boolean hasDefaultValue()Determines if this property has a default value or not.- Returns:
- true if this property has a default value; false otherwise
-
getDefaultValue
Returns the default value for this property. In case the property has no default value,nullis returned.nullmay also be the default value for this property.hasDefaultValue()can be used to disambiguate betweennullas default value andnullas indication of no default value.- Returns:
- the default value for this property
- See Also:
-
getIndex
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
ILcdDataObjectinterface.- Returns:
- the index of this property in this property's declaring type's properties
-
getName
Returns the name of this property. This name may differ from the property name as it was defined in the source data, because it can contain only alphanumeric characters and underscores and may have been sanitized. When this is the case, the original unaltered property name can still be retrieved throughgetSourceName().- Returns:
- the name of this property
- See Also:
-
getSourceName
Returns the original name of this property, as it was defined in the source data. This may differ from theactual nameof this property within theTLcdDataType, because that name can contain only alphanumeric characters and underscores and may have been sanitized.- Returns:
- the original name of this property, as it was defined in the source data.
- Since:
- 2024.0
- See Also:
-
getType
Returns the type of this property.- Returns:
- the type of this property
-
isCollection
public boolean isCollection()Determines if the property is many-valued. This method is equivalent togetCollectionType() != null.Note that values for many-valued properties not necessarily implement
java.util.CollectionasMapis not an extension ofCollection.- Returns:
- if the property is many-valued.
- See Also:
-
getCollectionType
Returns the collection type of this property. In case the property is single-valued,nullis returned. The collection type defines which values are valid for this property.LIST: valid values for this property implementjava.util.ListSET: valid values for this property implementjava.util.SetMAP: valid values for this property implementjava.util.Map
- Returns:
- the collection type for this property
-
getMapKeyType
For properties of which the collection type isMAP, returns the type of the keys. Otherwise returnsnull. The values in the map are of the type returned bygetType().- Returns:
- the type of the keys for map properties
-
isNullable
public boolean isNullable()Determines ifnullvalues are acceptable for this property. In case of collection properties, determines if the collection can be empty.- Returns:
- if
nullvalues or empty collections are acceptable
-
toString
-
getAnnotation
Description copied from interface:ILcdAnnotatedElementReturns 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,
nullis returned.- Specified by:
getAnnotationin interfaceILcdAnnotatedElement- Parameters:
aAnnotationType- - the Class object corresponding to the annotation type- Returns:
- this element's annotation for the specified annotation class if present on this element, else null
-
isAnnotationPresent
Description copied from interface:ILcdAnnotatedElementReturns 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,
falseis returned.- Specified by:
isAnnotationPresentin interfaceILcdAnnotatedElement- Parameters:
aAnnotationType- the Class object corresponding to the annotation class- Returns:
- true if an annotation for the specified annotation class is present on this element, else false
-
getAnnotations
Description copied from interface:ILcdAnnotatedElementReturns all annotations present on this element as an unmodifiable collection.- Specified by:
getAnnotationsin interfaceILcdAnnotatedElement- Returns:
- all annotations present on this element
-
addAnnotation
Description copied from interface:ILcdAnnotatedElementAdds the given annotation to this element.- Specified by:
addAnnotationin interfaceILcdAnnotatedElement- Parameters:
aAnnotation- the annotation to add- Returns:
- the previous annotation of the same class as the given annotation associated with this element, or null if there was no annotation for that class.
-
removeAnnotation
Description copied from interface:ILcdAnnotatedElementRemoves 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
nullis returned.- Specified by:
removeAnnotationin interfaceILcdAnnotatedElement- Parameters:
aAnnotationClass- the class of annotation to remove- Returns:
- the annotation of the given class that was associated with this element, or null if there was no annotation for that class.
-
isContained
public boolean isContained()Determines if this property represents composition (as opposed to mere aggregation). In other words, a data object has the lifetime responsibility for all the values of all properties that are contained.- Returns:
- if the value of this property is contained in the owning instance
-
hashCode
public int hashCode() -
equals
-
getDisplayName
Returns a displayable name for this property, suitable for usage in user interfaces.- Returns:
- a displayable name for the property.
- See Also:
-