Class Feature.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
Feature
Feature object.
Make sure to
- configure the
dataType()before callingvalue() - configure the id and
dataType()before finishing theFeatureusingbuild()
Otherwise a java.lang.IllegalStateException will be thrown.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build the feature using the settings configured.voidclose()Configures the dataType of the feature being built.protected voidfinalize()id(long id) Configures the id of the feature being built.resetId()Resets the id.resetValue(DataPropertyPath propertyPath) Resets the value associated with the given property, such that the builtFeaturereturns an empty optional for it.resetValue(String propertyName) Convenience overload of resetValue that resolves the property by name on the configured data type and resets the value.value(DataPropertyPath propertyPath, List<?> values) <T> Feature.Buildervalue(DataPropertyPath propertyPath, T value) Sets the value associated with the given property.<T> Feature.BuilderConvenience overload of value that resolves the property by name on the configured data type and sets the value.
-
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 feature using the settings configured.After this method is invoked once, this builder can no longer be used.
- Returns:
- the feature
- Throws:
IllegalStateException- if the ID or dataType are not configured
-
id
Configures the id of the feature being built.A feature id should be unique across a model.
This method is not mandatory, though Features in a model must have an id. It is allowed to temporarily have features without id, for example during
Featurecreation. As soon as such a temporaryFeatureisaddedto a model, it must beassignedanidthough.When no id is set,
Feature#getIdwill throw an exception.- Parameters:
id- the id- Returns:
- this builder
-
resetId
Resets the id.Calling this method will cause the built
Featureto have no id, thus throwing an exception when callingFeature#getId.Features in a model must have an id. It is allowed to temporarily have features without id, for example during
Featurecreation. As soon as such a temporaryFeatureisaddedto a model, it must beassignedanidthough.Note that for a newly created
Feature.Builderusing theFeature#newBuilder()method, the id will be empty by default. This method is less useful in that case. It is mainly useful when using theFeature#asBuilder()method.- Returns:
- this builder
- Since:
- 2023.1
-
dataType
Configures the dataType of the feature being built.- Parameters:
dataType- the data type- Returns:
- this builder
-
resetValue
@NotNull public Feature.Builder resetValue(@NotNull String propertyName) throws IllegalArgumentException Convenience overload of resetValue that resolves the property by name on the configured data type and resets the 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 features in a tight loop, build a
DataPropertyPathonce and use theDataPropertyPathoverload, which avoids 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> Feature.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 (path with a terminal index step): T is the element type (
DataObjectfor a composite element), and the single element is overwritten. The list must already be populated by a bulk set: setting an element of an unset list, or at an out-of-bounds index, throws an exception.
Example
featureBuilder.value(booleanPropertyPath, booleanValue); featureBuilder.value(intPropertyPath, intValue); featureBuilder.value(longPropertyPath, longValue); featureBuilder.value(floatPropertyPath, floatValue); featureBuilder.value(doublePropertyPath, doubleValue); featureBuilder.value(stringPropertyPath, stringValue); featureBuilder.value(geometryPropertyPath, geometry);Setting a list-typed property (bulk set, then overwrite a single element):
// Bulk-set the list (a null element marks an unknown value), then overwrite one element through its indexed path. Feature feature = Feature.newBuilder().id(1L).dataType(trackType) .value(timePath, Arrays.asList(100L, null, 300L)) .value(firstTimePath, 150L) .build();- 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 Feature.Builder value(@NotNull DataPropertyPath propertyPath, @NotNull List<?> values) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
resetValue
@NotNull public Feature.Builder resetValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException Resets the value associated with the given property, such that the builtFeaturereturns an empty optional for it.For a newly created
Feature.Builder(Feature#newBuilder()) all values are empty by default, so this is mainly useful withFeature#asBuilder().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: resetting an element of an unset list, or at an out-of-bounds index, throws an exception.
- Parameters:
propertyPath- the property for which to reset the value.- Returns:
- this builder.
- Throws:
IllegalArgumentException- when the dataType has not been configured, the property does not exist in theDataType, or the list is unset, or the index is out-of-bounds for an indexed path.
-
value
@NotNull public <T> Feature.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 features in a tight loop, build a
DataPropertyPathonce and use theDataPropertyPathoverload, which avoids 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 Feature.Builder value(@NotNull String propertyName, @NotNull List<?> values) throws IllegalArgumentException - Throws:
IllegalArgumentException
-