Class TLcdDataType
- All Implemented Interfaces:
ILcdAnnotatedElement
A representation of the type of a data object. A type describes the structure of a data object as a list of properties. Each of these properties is itself of a certain type.
A type always has a super type. The only exception to this rule is the Object
type, which has no super type. A type (recursively) inherits all properties from its super type.
A type can't redefine these inherited properties, they are always inherited as is.
A type is either a primitive type or a data object type. Primitive types are types which have no
internal structure (no properties) and typically represent simple objects such as strings,
numbers, dates etc. All primitive types either extend from another primitive type or directly from
. All data object types either extend
from another data object type or from TLcdCoreDataTypes.OBJECT_TYPE
.TLcdCoreDataTypes.DATA_OBJECT_TYPE
Types are always defined in the context of a TLcdDataModel
. Within
a certain data model, types are uniquely defined by their name. As such, two types
are equal if their data models are equal and they have the same name.
Types are mapped directly onto Java classes. This is a many-to-one mapping; each type is mapped on one Java class, but the same Java class can be represented by different types. Instances of a type are always instances of the type's Java class.
New types can be defined by first creating a TLcdDataModelBuilder
and then defining types within that data
model using TLcdDataTypeBuilder
. See TLcdDataModelBuilder
for a brief example.
Existing types can be retrieved via the TLcdDataModel
in 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:
-
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 data model that defines this type.Returns the list of all properties that are declared on this type.getDeclaredProperty
(String aPropertyName) Returns the first property in the list of declared properties with the given name.Returns a displayable name for this type, suitable for usage in user interfaces.getDisplayName
(Object aValue) Returns a displayable name for the specified value of this type, suitable for usage in user interfaces.Class
<?> Returns the Java class onto which instances of this type are mapped.getName()
Returns the name of this type.Set
<?> Returns a collection containing all possible instances for this type.Returns a (unmodifiable) list of all properties of this type.getProperty
(String aPropertyName) Returns a property in the list of properties with the given name.Returns the super type from which this type inherits.final boolean
hasDeclaredProperty
(TLcdDataProperty aProperty) Determines if the given property has been declared by this data type.int
hashCode()
final boolean
hasProperty
(TLcdDataProperty aProperty) Determines if the given property is a property of this data type, including properties inherited from supertypes.boolean
Returns if this type is abstract.boolean
isAnnotationPresent
(Class<? extends ILcdAnnotation> aAnnotationType) Returns true if an annotation for the specified class is present on this element, else false.boolean
isAssignableFrom
(TLcdDataType aType) Determines if the type represented by thisTLcdDataType
object is either the same as, or is a superclass of, the type represented by the specifiedTLcdDataType
parameter.boolean
Returns if this type is a data object type.boolean
Returns if this type is an enumeration type.boolean
isInstance
(Object aObject) Returns if the given object is an instance of this type.boolean
Returns if this type is a primitive type.Creates a new instance of this type.<T extends ILcdAnnotation>
TremoveAnnotation
(Class<T> aAnnotationClass) Removes the annotation of the given class from this element.toString()
-
Method Details
-
getSuperType
Returns the super type from which this type inherits. Only returnsnull
for theTLcdCoreDataTypes.OBJECT_TYPE
.- Returns:
- the super type of this type
-
getDeclaredProperties
Returns the list of all properties that are declared on this type. This list is a sub list of all the properties of this type.- Returns:
- the list of all properties declared on this type
- See Also:
-
getInstanceClass
Returns the Java class onto which instances of this type are mapped. This can be an interface.- Returns:
- the Java class of its instances
-
getDataModel
Returns the data model that defines this type.- Returns:
- the data model that defines this type
-
getName
Returns the name of this type. This name is unique within the type's data model.- Returns:
- the name of this type
-
getProperties
Returns a (unmodifiable) list of all properties of this type. This list is the union of getSuperType().getProperties() and getDeclaredProperties().
- Returns:
- an unmodifiable list of all properties of this type
- See Also:
-
getDeclaredProperty
Returns the first property in the list of declared properties with the given name. In case the type has no such property,null
is returned.- Parameters:
aPropertyName
- the name of the property that should be returned. Property names are case sensitive- Returns:
- a declared property with the given name
-
getProperty
Returns a property in the list of properties with the given name. In case multiple such properties exist, returns the last one (this corresponds to the property which is declared in the most specific subtype). In case the type has no such property,null
is returned. This method looks both at thename
andsource name
of the properties. It returns the last property of which either of those names matches the given name.- Parameters:
aPropertyName
- the name of the property that should be returned. Property names are case-sensitive. Both a property'sname
andsource name
are accepted.- Returns:
- a property with the given name
-
isAbstract
public boolean isAbstract()Returns if this type is abstract. Trying to create a new instance of an abstract type will result in anIllegalArgumentException
being thrown.- Returns:
- if this type is abstract
-
isPrimitive
public boolean isPrimitive()Returns if this type is a primitive type. Primitive types never have properties and are not assignable from
TLcdCoreDataTypes.DATA_OBJECT_TYPE
. A type is either a primitive type or a data object type. The only exception to this rule isTLcdCoreDataTypes.OBJECT_TYPE
which is neither primitive nor data object type.Most primitive types don't allow the creation of new instances using the
newInstance()
method. This is typically because instances can't be created using a default constructor (think for instance of String, Integer, etc.).- Returns:
- if this type is a primitive type
-
isDataObjectType
public boolean isDataObjectType()Returns if this type is a data object type. Data object types are by definition assignable from
TLcdCoreDataTypes.DATA_OBJECT_TYPE
. A type is either a primitive type or a data object type. The only exception to this rule isTLcdCoreDataTypes.DATA_OBJECT_TYPE
which is neither primitive nor data object type.New instances of data object types can be created using the
newInstance()
method.- Returns:
- if this type is a primitive type
-
isInstance
Returns if the given object is an instance of this type.
- Parameters:
aObject
- the object to be checked- Returns:
- the
boolean
value indicating whether the object aObject is an instance of this type
-
isAssignableFrom
Determines if the type represented by this
TLcdDataType
object is either the same as, or is a superclass of, the type represented by the specifiedTLcdDataType
parameter. It returnstrue
if so; otherwise it returnsfalse
.This is very much similar to
Class.isAssignableFrom(Class)
.- Parameters:
aType
- thetype
object to be checked- Returns:
- the
boolean
value indicating whether instances of the typeaType
can be assigned to instances of this type
-
newInstance
Creates a new instance of this type.
Note that this is only supported for data object types. There is no generic mechanism to create a new instance of a primitive type. This is because many of the primitive types are immutable (for instance String, Double, etc.) and as such require additional arguments to create an instance.
- Returns:
- a new instance of this type
- Throws:
IllegalArgumentException
- in case the type is abstract or a primitive type
-
isEnumeration
public boolean isEnumeration()Returns if this type is an enumeration type. An enumeration type is always a primitive type and has a limited number of possible instances. A typical example is a primitive type that represents a Java enumeration class.- Returns:
- if this type is an enumeration type
-
getAnnotation
Description copied from interface: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.- Specified by:
getAnnotation
in 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: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.- Specified by:
isAnnotationPresent
in 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:ILcdAnnotatedElement
Returns all annotations present on this element as an unmodifiable collection.- Specified by:
getAnnotations
in interfaceILcdAnnotatedElement
- Returns:
- all annotations present on this element
-
addAnnotation
Description copied from interface:ILcdAnnotatedElement
Adds the given annotation to this element.- Specified by:
addAnnotation
in 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: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.- Specified by:
removeAnnotation
in 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.
-
getPossibleValues
Returns a collection containing all possible instances for this type. In case the type is not an enumeration,null
is returned.- Returns:
- a collection containing all possible instances for this type
-
toString
-
hashCode
public int hashCode() -
equals
-
getDisplayName
Returns a displayable name for this type, suitable for usage in user interfaces.- Returns:
- a displayable name for the type.
- See Also:
-
getDisplayName
Returns a displayable name for the specified value of this type, suitable for usage in user interfaces. If no displayable name is available,aValue.toString()
will be returned.- Parameters:
aValue
- a value within the value domain of this type.- Returns:
- a displayable name for
aValue
. - Throws:
NullPointerException
- ifaValue == null
.IllegalArgumentException
- ifaValue
is not within this type's value domain.- See Also:
-
hasProperty
Determines if the given property is a property of this data type, including properties inherited from supertypes.- Parameters:
aProperty
- the property to validate- Returns:
- true if the given property is a property of this data type; false otherwise
- Since:
- 2014.0
-
hasDeclaredProperty
Determines if the given property has been declared by this data type.- Parameters:
aProperty
- the property to validate- Returns:
- true if the given property is declared in this data type; false otherwise
- Since:
- 2014.0
-