Class Feature.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
Feature
Feature object.
Make sure to
- configure the
dataType()before callingvalue() - configure the
id()anddataType()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.<T> Feature.Buildervalue(DataPropertyPath propertyPath, T value) Sets the value associated with the given property.
-
Constructor Details
-
Builder
-
-
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
-
value
@NotNull public <T> Feature.Builder value(@NotNull DataPropertyPath propertyPath, @NotNull T value) throws IllegalArgumentException Sets the value associated with the given property.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);- Type Parameters:
T- the supported types arejava.lang.Boolean,java.lang.Integer,java.lang.Long,java.lang.Float,java.lang.Double,java.lang.StringandGeometry- Parameters:
propertyPath- the property for which to set the valuevalue- the value- Returns:
- this builder
- Throws:
IllegalArgumentException- when the dataType has not been configured yet, the property is not of a known type, or if it doesn't exist in theDataType.
-
resetValue
@NotNull public Feature.Builder resetValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException Resets the value associated with the given property.Calling this method will cause the built
Featureto return an empty optional for the given property.Note that for a newly created
Feature.Builderusing theFeature#newBuilder()method, all values will be empty by default. This method is less useful in that case. It is mainly useful when using theFeature#asBuilder()method.- Parameters:
propertyPath- the property for which to reset the value- Returns:
- this builder
- Throws:
IllegalArgumentException- when the dataType has not been configured yet, the property is not of a known type, or if it doesn't exist in theDataType.
-