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
Modifier and TypeClassDescriptionstatic final class
Allows the incremental creation of aFeature
object. -
Method Summary
Modifier and TypeMethodDescriptionReturns thisFeature
as aFeature.Builder
.void
close()
boolean
protected void
finalize()
Tries to find a geometry for this feature.Returns the data type describing the feature properties.long
getId()
Returns the id of this feature.<T> T
getValue
(DataPropertyPath propertyPath) Accesses the value for the given property.int
hashCode()
boolean
hasId()
Returns if thisFeature
has an id.static Feature.Builder
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
newBuilder
-
asBuilder
Returns thisFeature
as 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
Feature
as aFeature.Builder
.
-
hasId
public boolean hasId()Returns if thisFeature
has an id.If this method returns false, it is not allowed to call
Feature#getId
.- Returns:
- if this
Feature
has 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 -> null
Note: a ClassCastException may be thrown when trying to retrieve a geometry property value using a
Geometry
sub-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
,Geometry
or 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,null
is 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 aPoint
geometry, but it is requested usingArcBand
as type parameter).
-