Class DataObject.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
DataObject
DataObject.
Configure the dataType() before calling value(). After build() is invoked once, the builder can no longer be used.
Example
// A composite property holds a DataObject: build the nested object, then set it on the Feature.
DataObject address = DataObject.newBuilder().dataType(addressType).value(streetPath, "Main St").build();
Feature person = Feature.newBuilder().id(1L).dataType(personType).value(addressPath, address).build();
- Since:
- 2026.1
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theDataObjectusing the configured settings.voidclose()Configures the dataType of theDataObjectbeing built.protected voidfinalize()resetValue(DataPropertyPath propertyPath) Resets the value associated with the given property to empty.resetValue(String propertyName) Convenience overload of resetValue that resolves the property by name on the configured data type and resets its value.value(DataPropertyPath propertyPath, List<?> values) value(DataPropertyPath propertyPath, T value) Sets the value associated with the given property.Convenience overload of value that resolves the property by name on the configured data type and sets the value.
-
Constructor Details
-
Builder
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
build
Builds theDataObjectusing the configured settings.After this method is invoked once, this builder can no longer be used.
- Returns:
- the
DataObject. - Throws:
IllegalStateException- if the dataType is not configured.
-
dataType
Configures the dataType of theDataObjectbeing built.- Parameters:
dataType- the data type.- Returns:
- this builder.
-
resetValue
@NotNull public DataObject.Builder resetValue(@NotNull String propertyName) throws IllegalArgumentException Convenience overload of resetValue that resolves the property by name on the configured data type and resets its value.The value type does not need to be named: it is derived from the property.
The
dataType()must be configured before this is called.Performance note: this overload resolves the name on every call. To reset the same property on many data objects in a tight loop, build a
DataPropertyPathonce and use theDataPropertyPathoverload, which prevents the repeated lookup.- Parameters:
propertyName- the name of a property in the configured data type.- Returns:
- this builder.
- Throws:
IllegalArgumentException- when the dataType is not configured or no property with that name exists.- Since:
- 2026.1
-
value
@NotNull public <T> DataObject.Builder value(@NotNull DataPropertyPath propertyPath, @NotNull T value) throws IllegalArgumentException Sets the value associated with the given property.The type parameter T depends on the type of value this property contains:
- Scalar property: T is the element type.
- Composite property (value type is a non-primitive
DataType): T isDataObject, with aDataTypethat must equal the property's value type. - List property: T is the list type. One bulk set sizes and populates the list. Individual elements may be unset.
- List element: T is the element type (
DataObjectfor a composite element), and the single element is overwritten. The list must already have been bulk-set.
- Type Parameters:
T- the value type, chosen by property shape (see above).- Parameters:
propertyPath- the property for which to set the value.value- the value.- Returns:
- this builder.
- Throws:
IllegalArgumentException- when the dataType has not been configured, the property does not exist in theDataType, T does not match the path's leaf type, or the list is unset or the index is out-of-bounds for an indexed path.
-
value
@NotNull public DataObject.Builder value(@NotNull DataPropertyPath propertyPath, @NotNull List<?> values) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
resetValue
@NotNull public DataObject.Builder resetValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException Resets the value associated with the given property to empty.The effect on a list-typed property depends on the path:
- List path: the list is cleared (becomes unset).
- List element: that single element is set to empty. The list must already be populated.
- Parameters:
propertyPath- the property for which to reset the value.- Returns:
- this builder.
- Throws:
IllegalArgumentException- when the dataType has not been configured, the property doesn't exist, or the list is unset or the index is out-of-bounds for an indexed path.
-
value
@NotNull public <T> DataObject.Builder value(@NotNull String propertyName, @NotNull T value) throws IllegalArgumentException Convenience overload of value that resolves the property by name on the configured data type and sets the value.The
dataType()must be configured before this is called.Performance note: this overload resolves the name on every call. To set the same property on many data objects in a tight loop, build a
DataPropertyPathonce and use theDataPropertyPathoverload, which prevents the repeated lookup.- Type Parameters:
T- the value type, chosen by the property's shape (see theDataPropertyPathoverload).- Parameters:
propertyName- the name of a property in the configured data type.value- the value.- Returns:
- this builder.
- Throws:
IllegalArgumentException- when the dataType is not configured, no property with that name exists, or T does not match its type.- Since:
- 2026.1
-
value
@NotNull public DataObject.Builder value(@NotNull String propertyName, @NotNull List<?> values) throws IllegalArgumentException - Throws:
IllegalArgumentException
-