Class DataType.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
DataType
Builder that allows DataType instances to be created.
Typical usage would be create a DataType.Builder using DataType#newBuilder, specifying the data type's name. Then add the necessary DataProperty(s) and finally build() the data type. The following snippet shows how this is done for a simple example data type:
return DataType.newBuilder()
.name("TestDataType")
.addProperty(TestFeatureModelFactory.SomeProperty)
.addProperty(geometryProperty)
.addAnnotation(new GeometryDataAnnotationFactory(geometryProperty))
.build();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation(DataAnnotation annotation) The annotation to add to the data type under construction.addAnnotation(IDataAnnotationFactory annotationFactory) Adds an annotation factory that is invoked when build is called.addBooleanProperty(String name) Adds a scalar property with the given name andDataType#getBooleanType()as its value type.addDoubleProperty(String name) Adds a scalar property with the given name andDataType#getDoubleType()as its value type.addFloatProperty(String name) Adds a scalar property with the given name andDataType#getFloatType()as its value type.addGeometryProperty(String name, boolean mainGeometry) Adds a property with the given name andDataType#getGeometryType()as its value type, marking it as this type's main geometry when mainGeometry istrue.addIntProperty(String name) Adds a scalar property with the given name andDataType#getIntType()as its value type.addLongProperty(String name) Adds a scalar property with the given name andDataType#getLongType()as its value type.addProperty(DataProperty property) The property to add to the data type under construction.addStringProperty(String name) Adds a scalar property with the given name andDataType#getStringType()as its value type.build()Build the data type, including the properties and annotations that were added to this builder.voidclose()protected voidfinalize()The name of the new data type.
-
Constructor Details
-
Builder
Copy constructor.- Parameters:
other- the builder to copy.
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
build
Build the data type, including the properties and annotations that were added to this builder.After calling this function, this builder should no longer be used.
- Returns:
- the data type.
- Throws:
IllegalStateException- If not all mandatory parameters are set, or if the data type ends up with more than oneGeometryDataAnnotation. A data type has at most one main geometry.
-
addProperty
The property to add to the data type under construction.- Parameters:
property- the property to add to the data type under construction.- Returns:
- this builder.
-
addGeometryProperty
@NotNull public DataType.Builder addGeometryProperty(@NotNull String name, boolean mainGeometry) throws IllegalStateException Adds a property with the given name andDataType#getGeometryType()as its value type, marking it as this type's main geometry when mainGeometry istrue.If the data type has a single geometry, always pass
true. A type needs a main geometry forFeature#findGeometry()and for the default painters to know which property holds the shape to draw. Only a type with several geometry properties needsfalse, for the ones that are not its main geometry.For the main geometry, a
GeometryDataAnnotationfor the property is wired internally, so there is no need to create that annotation through anIDataAnnotationFactory.A data type has at most one main geometry. Calling this again with
truethrows an exception, andbuild()additionally rejects a type of which the secondGeometryDataAnnotationcame fromaddAnnotation()rather than from here.The annotated case is shorthand for adding the property and then attaching its
GeometryDataAnnotationthrough anIDataAnnotationFactory, shown below:DataProperty geometryProperty = DataProperty.newBuilder().name("geometry").valueType(DataType.getGeometryType()).build(); DataType dataType = DataType.newBuilder() .name("MyType") .addProperty(geometryProperty) .addAnnotation(new GeometryDataAnnotationFactory(geometryProperty)) .build();- Parameters:
name- the name of the geometry property.mainGeometry- whether the property is this type's main geometry, annotated with aGeometryDataAnnotation. Passtrueunless the data type has more than one geometry property.- Returns:
- this builder.
- Throws:
IllegalStateException- if this data type already has a main geometry and mainGeometry is true.- Since:
- 2026.1
-
addIntProperty
Adds a scalar property with the given name andDataType#getIntType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addLongProperty
Adds a scalar property with the given name andDataType#getLongType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addFloatProperty
Adds a scalar property with the given name andDataType#getFloatType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addDoubleProperty
Adds a scalar property with the given name andDataType#getDoubleType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addStringProperty
Adds a scalar property with the given name andDataType#getStringType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addBooleanProperty
Adds a scalar property with the given name andDataType#getBooleanType()as its value type.Use
addProperty()for anything more specific.- Parameters:
name- the name of the property.- Returns:
- this builder.
- Since:
- 2026.1
-
addAnnotation
@NotNull public DataType.Builder addAnnotation(@NotNull DataAnnotation annotation) throws NullPointerException The annotation to add to the data type under construction.- Parameters:
annotation- the annotation to add to the data type under construction.- Returns:
- this builder.
- Throws:
NullPointerException- when anullvalue is passed.
-
addAnnotation
@NotNull public DataType.Builder addAnnotation(@NotNull IDataAnnotationFactory annotationFactory) throws NullPointerException Adds an annotation factory that is invoked when build is called.The factory is provided with the type that is being built. This can be useful when the created annotation needs access to the type, for instance when the annotation requires a
DataPropertyPath.An example usage is:
class GeometryDataAnnotationFactory(private val property: DataProperty) : IDataAnnotationFactory { override fun createAnnotation(dataType: DataType): DataAnnotation { return GeometryDataAnnotation( DataPropertyPath.newBuilder().originType(dataType).property(property).build() ) } }DataProperty geometryProperty = DataProperty.newBuilder().name("geometry").valueType(DataType.getGeometryType()).build(); DataType dataType = DataType.newBuilder() .name("MyType") .addProperty(geometryProperty) .addAnnotation(new GeometryDataAnnotationFactory(geometryProperty)) .build();- Parameters:
annotationFactory- the factory object.- Returns:
- this builder.
- Throws:
NullPointerException- when anullvalue is passed.
-
name
The name of the new data type.Calling this function is mandatory.
- Parameters:
name- name of the new data type.- Returns:
- this builder.
-