public final class Feature extends Object implements 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
See article for more details on this class.
Modifier and Type | Class and Description |
---|---|
static class |
Feature.Builder
Allows the incremental creation of a
Feature object. |
Modifier and Type | Method and Description |
---|---|
Feature.Builder |
asBuilder()
Returns this
Feature as a Feature.Builder . |
void |
close() |
boolean |
equals(Object other) |
protected void |
finalize() |
Geometry |
findGeometry()
Tries to find a geometry for this feature.
|
DataType |
getDataType()
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 this
Feature has an id. |
static Feature.Builder |
newBuilder()
|
public void close()
close
in interface AutoCloseable
@NotNull public static Feature.Builder newBuilder()
@NotNull public Feature.Builder asBuilder()
Feature
as a Feature.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 the Feature
. Otherwise a java.lang.IllegalStateException will be thrown.
Feature
as a Feature.Builder
.public boolean hasId()
Feature
has an id.
If this method returns false, it is not allowed to call Feature#getId
.
Feature
has an id.Feature.Builder#id
public long getId() throws IllegalStateException
A feature id should be unique across a model.
When no id is set
, this method will throw an exception.
IllegalStateException
- when the feature has no id.@NotNull public DataType getDataType()
@Nullable public Geometry findGeometry()
If this feature's data type is annotated with GeometryDataAnnotation
, the value of the corresponding property is returned. Otherwise, the result will be null
.
null
.GeometryDataAnnotation#getPropertyPath
@Nullable public <T> T getValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException
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.
T
- the supported types are java.lang.Boolean
, java.lang.Integer
, java.lang.Long
, java.lang.Float
, java.lang.Double
, java.lang.String
, Geometry
or a subtype of Geometry
.propertyPath
- the property for which to return a valueDataType
, but is not set for this particular feature, null
is returned.IllegalArgumentException
- when the property is not of a known type, if it doesn't exist in the DataType
, or when the type of the value doesn't correspond with the provided type parameter (for example when the property value is a Point
geometry, but it is requested using ArcBand
as type parameter).