Class Feature
- All Implemented Interfaces:
AutoCloseable
Feature is a (partial) copy of a domain object.
It allows the rest of the API to easily access the domain object's properties, including any geometry. If you do a query on the model, and retrieve a Feature from it, the caller of the query receives ownership of the Feature. I.e. the caller can decide what to do with it, and when to dispose it.
This means that the Map and Layer API's are allowed to keep references to a Feature and have unrestricted lock-less access to its properties. The caller of the IFeatureModel#query method is responsible for managing the lifetime of a Feature.
To make Feature instances easy to use in a multi-threaded environment, they are
- immutable
- thread safe for reading
See article for more details on this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAllows the incremental creation of aFeatureobject. -
Method Summary
Modifier and TypeMethodDescriptionReturns thisFeatureas aFeature.Builder.voidclose()booleanprotected voidfinalize()Tries to find a geometry for this feature.Returns the data type describing the feature properties.longgetId()Returns the id of this feature.<T> TgetValue(DataPropertyPath propertyPath) Accesses the value for the given property.inthashCode()booleanhasId()Returns if thisFeaturehas an id.static Feature.Builder
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
newBuilder
-
asBuilder
Returns thisFeatureas aFeature.Builder.This makes it possible to copy a
Feature, and modify values. Note that when using this builder, it is not possible to change the datatype. Only the values and the id of theFeature. Otherwise a java.lang.IllegalStateException will be thrown.- Returns:
- this
Featureas aFeature.Builder.
-
hasId
public boolean hasId()Returns if thisFeaturehas an id.If this method returns false, it is not allowed to call
Feature#getId.- Returns:
- if this
Featurehas an id. - See Also:
-
getId
Returns the id of this feature.A feature id should be unique across a model.
When no id is
set, this method will throw an exception.- Returns:
- the id of this feature.
- Throws:
IllegalStateException- when the feature has no id.
-
getDataType
Returns the data type describing the feature properties.- Returns:
- the data type describing the feature properties.
-
findGeometry
Tries to find a geometry for this feature.If this feature's data type is annotated with
GeometryDataAnnotation, the value of the corresponding property is returned. Otherwise, the result will benull.- Returns:
- the annotated geometry, if any, else
null. - See Also:
-
hashCode
public int hashCode() -
equals
-
getValue
@Nullable public <T> T getValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException Accesses the value for the given property.Example
Boolean optBoolean = feature.<Boolean>getValue(booleanPropertyPath); Integer optInteger = feature.<Integer>getValue(intPropertyPath); Long optLong = feature.<Long>getValue(longPropertyPath); Float optFloat = feature.<Float>getValue(floatPropertyPath); Double optDouble = feature.<Double>getValue(doublePropertyPath); String optString = feature.<String>getValue(stringPropertyPath); Geometry optGeometry = feature.<Geometry>getValue(geometryPropertyPath); String unsetValue = feature.<String>getValue(unsetPropertyPath); // Unset property -> nullNote: a ClassCastException may be thrown when trying to retrieve a geometry property value using a
Geometrysub-type parameter that doesn't correspond with the actual type of the geometry property value.- Type Parameters:
T- the supported types arejava.lang.Boolean,java.lang.Integer,java.lang.Long,java.lang.Float,java.lang.Double,java.lang.String,Geometryor a subtype ofGeometry.- Parameters:
propertyPath- the property for which to return a value- Returns:
- the value for the given property. If the property does exist in the
DataType, but is not set for this particular feature,nullis returned. - Throws:
IllegalArgumentException- when the property is not of a known type, if it doesn't exist in theDataType, or when the type of the value doesn't correspond with the provided type parameter (for example when the property value is aPointgeometry, but it is requested usingArcBandas type parameter).
-