org.geotools.feature.simple
Class SimpleFeatureImpl

Object
  extended by SimpleFeatureImpl
All Implemented Interfaces:
Attribute, ComplexAttribute, Feature, Property, SimpleFeature
Direct Known Subclasses:
LenientFeature

public class SimpleFeatureImpl
extends Object
implements SimpleFeature

An implementation of SimpleFeature geared towards speed and backed by an Object[].

Author:
Justin, Andrea Aime

Field Summary
protected  Map<Object,Object>[] attributeUserData
          The set of user data attached to each attribute (lazily created)
protected  SimpleFeatureType featureType
           
protected  FeatureId id
           
protected  Map<String,Integer> index
          The attribute name -> position index
protected  Map<Object,Object> userData
          The set of user data attached to the feature (lazily created)
protected  boolean validating
          Whether this feature is self validating or not
protected  Object[] values
          The actual values held by this feature
 
Constructor Summary
SimpleFeatureImpl(List<Object> values, SimpleFeatureType featureType, FeatureId id)
          Builds a new feature based on the provided values and feature type
SimpleFeatureImpl(Object[] values, SimpleFeatureType featureType, FeatureId id, boolean validating)
          Fast construction of a new feature.
SimpleFeatureImpl(Object[] values, SimpleFeatureType featureType, FeatureId id, boolean validating, Map<String,Integer> index)
          Fast construction of a new feature.
 
Method Summary
 boolean equals(Object obj)
          override of equals.
 Object getAttribute(int index)
          Gets an attribute value by index.
 Object getAttribute(Name name)
          Gets an attribute value by name.
 Object getAttribute(String name)
          Gets an attribute value by name.
 int getAttributeCount()
          The number of attributes the feature is composed of.
 List<Object> getAttributes()
          Returns a list of the values of the attributes contained by the feature.
 BoundingBox getBounds()
          The bounds of this Feature, if available.
 Object getDefaultGeometry()
          Returns the value of the default geometry of the feature.
 GeometryAttribute getDefaultGeometryProperty()
          The default geometric attribute of the feature.
 AttributeDescriptor getDescriptor()
          Override of Property.getDescriptor() which type narrows to AttributeDescriptor.
 SimpleFeatureType getFeatureType()
          The type of the feature.
 String getID()
          Unique Identifier for the SimpleFeature This value is non-null and should be the same as getIdentifier().toString().
 FeatureId getIdentifier()
          A unique identifier for the feature.
 Name getName()
          The name of the property with respect to its descriptor.
 int getNumberOfAttributes()
           
 Collection<Property> getProperties()
          Complete collection of properties.
 Collection<Property> getProperties(Name name)
          Returns a subset of the properties of the complex attribute which match the specified name.
 Collection<Property> getProperties(String name)
          Returns a subset of the properties of the complex attribute which match the specified name.
 Property getProperty(Name name)
          Returns single property of the complex attribute which matches the specified name.
 Property getProperty(String name)
          Returns single property of the complex attribute which matches the specified name.
 SimpleFeatureType getType()
          Override and type narrow to SimpleFeatureType.
 Map<Object,Object> getUserData()
          A map of "user data" which enables applications to store "application-specific" information against a property.
 Collection<? extends Property> getValue()
          Override of Property.getValue() which returns the collection of Property which make up the value of the complex attribute.
 int hashCode()
          returns a unique code for this feature
 boolean isNillable()
          Flag indicating if null is an acceptable value for the property.
 void setAttribute(int index, Object value)
          Sets an attribute value by index.
 void setAttribute(Name name, Object value)
          Sets an attribute value by name.
 void setAttribute(String name, Object value)
          Sets an attribute value by name.
 void setAttributes(List<Object> values)
          Sets the values of the attributes contained by the feature.
 void setAttributes(Object[] values)
          Sets the values of the attributes contained by the feature.
 void setDefaultGeometry(Object geometry)
          Sets the value of the default geometry for the feature.
 void setDefaultGeometryProperty(GeometryAttribute geometryAttribute)
          Sets the default geometric attribute of the feature.
 void setValue(Collection<Property> values)
          Sets the contained properties of the complex attribute.
 void setValue(Object newValue)
          Sets the value or content of the property.
 String toString()
           
 void validate()
          Check the properties against the constraints provided by their AttributeDescriptors.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected FeatureId id

featureType

protected SimpleFeatureType featureType

values

protected Object[] values
The actual values held by this feature


index

protected Map<String,Integer> index
The attribute name -> position index


userData

protected Map<Object,Object> userData
The set of user data attached to the feature (lazily created)


attributeUserData

protected Map<Object,Object>[] attributeUserData
The set of user data attached to each attribute (lazily created)


validating

protected boolean validating
Whether this feature is self validating or not

Constructor Detail

SimpleFeatureImpl

public SimpleFeatureImpl(List<Object> values,
                         SimpleFeatureType featureType,
                         FeatureId id)
Builds a new feature based on the provided values and feature type

Parameters:
values -
featureType -
id -

SimpleFeatureImpl

public SimpleFeatureImpl(Object[] values,
                         SimpleFeatureType featureType,
                         FeatureId id,
                         boolean validating)
Fast construction of a new feature.

The object takes ownership of the provided value array, do not modify after calling the constructor

Parameters:
values -
featureType -
id -
validating -

SimpleFeatureImpl

public SimpleFeatureImpl(Object[] values,
                         SimpleFeatureType featureType,
                         FeatureId id,
                         boolean validating,
                         Map<String,Integer> index)
Fast construction of a new feature.

The object takes ownership of the provided value array, do not modify after calling the constructor

Parameters:
values -
featureType -
id -
validating -
index - - attribute name to value index mapping
Method Detail

getIdentifier

public FeatureId getIdentifier()
Description copied from interface: Feature
A unique identifier for the feature.

getType().isIdentifiable() must return true so this value must not return null.

Generation of the identifier is dependent on the underlying data storage medium. Often this identifier is not persistent. Mediums such shapefiles and database tables have "keys" built in which map naturally to persistent feature identifiers. But other mediums do not have such keys and may have to generate feature identifiers "on-the-fly". This means that client code being able to depend on this value as a persistent entity is dependent on which storage medium or data source is being used.

Specified by:
getIdentifier in interface Attribute
Specified by:
getIdentifier in interface Feature
Returns:
The feature identifier, never null.

getID

public String getID()
Description copied from interface: SimpleFeature
Unique Identifier for the SimpleFeature

This value is non-null and should be the same as getIdentifier().toString(). Please note that an ID may be provided

Specified by:
getID in interface SimpleFeature
Returns:
A unique identifier for the attribute, or null if the attribute is non-identifiable.

getNumberOfAttributes

public int getNumberOfAttributes()

getAttribute

public Object getAttribute(int index)
                    throws IndexOutOfBoundsException
Description copied from interface: SimpleFeature
Gets an attribute value by index.

This method is a convenience for:

 Property p = ((List)getProperties()).get( i ) ;
 return p.getValue();
 

Specified by:
getAttribute in interface SimpleFeature
Parameters:
index - The index of the attribute whose value to get.
Returns:
The attribute value at the specified index.
Throws:
IndexOutOfBoundsException - If the specified index is out of bounds.

getAttribute

public Object getAttribute(String name)
Description copied from interface: SimpleFeature
Gets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 return p.getValue();
 

Specified by:
getAttribute in interface SimpleFeature
Parameters:
name - The name of the attribute whose value to retrieve.
Returns:
The attribute value, or null if no such attribute exists with the specified name.

getAttribute

public Object getAttribute(Name name)
Description copied from interface: SimpleFeature
Gets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 return p.getValue();
 

Since attribute names in simple features do not have a namespace uri this method is equivalent to calling getAttribute(name.getLocalPart()).

Specified by:
getAttribute in interface SimpleFeature
Parameters:
name - The name of the attribute whose value to retrieve.
Returns:
The attribute value, or null if no such attribute exists with the specified name.

getAttributeCount

public int getAttributeCount()
Description copied from interface: SimpleFeature
The number of attributes the feature is composed of.

This is a convenience for:

   return getAttributes().size();
 

Specified by:
getAttributeCount in interface SimpleFeature
Returns:
Number of attributes of the feature.

getAttributes

public List<Object> getAttributes()
Description copied from interface: SimpleFeature
Returns a list of the values of the attributes contained by the feature.

This method is a convenience for:

 List values = new ArrayList();
 for ( Property p : getProperties(); ) {
   values.add( p.getValue() );
 }

 return values;
 

Specified by:
getAttributes in interface SimpleFeature
Returns:
List of attribute values for the feature.

getDefaultGeometry

public Object getDefaultGeometry()
Description copied from interface: SimpleFeature
Returns the value of the default geometry of the feature.

This method is convenience for:

 return getDefaultGeometry().getValue();
 

Specified by:
getDefaultGeometry in interface SimpleFeature
Returns:
The default geometry, or null if no default geometry attribute exists.

getFeatureType

public SimpleFeatureType getFeatureType()
Description copied from interface: SimpleFeature
The type of the feature.

This method is a synonym for SimpleFeature.getType().

Specified by:
getFeatureType in interface SimpleFeature
See Also:
SimpleFeature.getType()

getType

public SimpleFeatureType getType()
Description copied from interface: SimpleFeature
Override and type narrow to SimpleFeatureType.

Specified by:
getType in interface Attribute
Specified by:
getType in interface ComplexAttribute
Specified by:
getType in interface Feature
Specified by:
getType in interface Property
Specified by:
getType in interface SimpleFeature
Returns:
The feature type
See Also:
Attribute.getType()

setAttribute

public void setAttribute(int index,
                         Object value)
                  throws IndexOutOfBoundsException
Description copied from interface: SimpleFeature
Sets an attribute value by index.

This method is a convenience for:

 Property p = ((List)getProperties()).get( i ) ;
 p.setValue(value);
 

Specified by:
setAttribute in interface SimpleFeature
Parameters:
index - The index of the attribute whose value to set.
value - The new value of the attribute.
Throws:
IndexOutOfBoundsException - If the specified index is out of bounds.

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: SimpleFeature
Sets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 p.setValue(value);
 

Specified by:
setAttribute in interface SimpleFeature
Parameters:
name - The name of the attribute whose value to set.
value - The new value of the attribute.

setAttribute

public void setAttribute(Name name,
                         Object value)
Description copied from interface: SimpleFeature
Sets an attribute value by name.

This method is a convenience for:

 Property p = getProperty( name );
 p.setValue(value);
 

Since attribute names in simple features do not have a namespace uri this method is equivalent to calling setAttribute(name.getLocalPart(), value).

Specified by:
setAttribute in interface SimpleFeature
Parameters:
name - The name of the attribute whose value to set.
value - The new value of the attribute.

setAttributes

public void setAttributes(List<Object> values)
Description copied from interface: SimpleFeature
Sets the values of the attributes contained by the feature.

The values must be in the order of the attributes defined by the feature type.

This method is a convenience for:

 int i = 0;
 for ( Property p : getProperties() ) {
   p.setValue( values.get( i++ ) );
 }
 

Specified by:
setAttributes in interface SimpleFeature
Parameters:
values - The attribute values to set.

setAttributes

public void setAttributes(Object[] values)
Description copied from interface: SimpleFeature
Sets the values of the attributes contained by the feature.

The values must be in the order of the attributes defined by the feature type.

This method is a convenience for:

 for ( Property p : getProperties() ) {
   p.setValue( values[i] );
 }
 

Specified by:
setAttributes in interface SimpleFeature
Parameters:
values - The attribute values to set.

setDefaultGeometry

public void setDefaultGeometry(Object geometry)
Description copied from interface: SimpleFeature
Sets the value of the default geometry for the feature.

This method is convenience for:

 getDefaultGeometry().setValue(geometry);
 

Specified by:
setDefaultGeometry in interface SimpleFeature
Parameters:
geometry - The new default geometry value.

getBounds

public BoundingBox getBounds()
Description copied from interface: Feature
The bounds of this Feature, if available.

This value is derived from any geometric attributes that the feature is composed of.

In the case that the feature has no geometric attributes this method should return an empty bounds, ie, bounds.isEmpty() == true. This method should never return null.

The coordinate reference system of the returned bounds is derived from the geometric attributes which were used to compute the bounds. In the event that the feature contains multiple geometric attributes which have different crs's, the one defined by #getGeometryDescriptor() should take precedence and the others should be reprojected accordingly.

Specified by:
getBounds in interface Feature
Returns:
the feature bounds, possibly empty.

getDefaultGeometryProperty

public GeometryAttribute getDefaultGeometryProperty()
Description copied from interface: Feature
The default geometric attribute of the feature.

This method returns null in the case where no such attribute exists.

Specified by:
getDefaultGeometryProperty in interface Feature
Returns:
The default geometry attribute, or null.

setDefaultGeometryProperty

public void setDefaultGeometryProperty(GeometryAttribute geometryAttribute)
Description copied from interface: Feature
Sets the default geometric attribute of the feature.

This value must be an attribute which is already defined for the feature. In other words, this method can not be used to add a new attribute to the feature.

Specified by:
setDefaultGeometryProperty in interface Feature
Parameters:
geometryAttribute - The new geomtric attribute.

getProperties

public Collection<Property> getProperties()
Description copied from interface: ComplexAttribute
Complete collection of properties.

This method is a convenience method for calling (Collection) getValue().

Specified by:
getProperties in interface ComplexAttribute
Returns:
The complete collection of properties.

getProperties

public Collection<Property> getProperties(Name name)
Description copied from interface: ComplexAttribute
Returns a subset of the properties of the complex attribute which match the specified name.

The name parameter is matched against each contained Property.getName(), those that are equal are returned.

Specified by:
getProperties in interface ComplexAttribute
Parameters:
name - The name of the properties to return.
Returns:
The collection of properties which match the specified name, or an empty collection if no such properties match.

getProperties

public Collection<Property> getProperties(String name)
Description copied from interface: ComplexAttribute
Returns a subset of the properties of the complex attribute which match the specified name.

This method is a convenience for ComplexAttribute.getProperties(Name) in which Name.getNamespaceURI() is null.

Note: Special care should be taken when using this method in the case that two properties with the same local name but different namespace uri exist. For this reason using ComplexAttribute.getProperties(Name) is safer.

Specified by:
getProperties in interface ComplexAttribute
Parameters:
name - The local name of the properties to return.
Returns:
The collection of properties which match the specified name, or an empty collection if no such properties match.
See Also:
ComplexAttribute.getProperties(Name)

getProperty

public Property getProperty(Name name)
Description copied from interface: ComplexAttribute
Returns single property of the complex attribute which matches the specified name.

Note: This method is a convenience and care should be taken when calling it if more then a single property matches name. In such a case the first encountered property in which Property.getName() is equal to name is returned, and no order is guaranteed.

This method is a safe convenience for: getProperties(name).iterator().next(). In the event that no property matches the specified name null is returned.

Specified by:
getProperty in interface ComplexAttribute
Parameters:
name - The name of the property to return.
Returns:
The property matching the specified name, or null.

getProperty

public Property getProperty(String name)
Description copied from interface: ComplexAttribute
Returns single property of the complex attribute which matches the specified name.

This method is a convenience for ComplexAttribute.getProperty(Name) in which Name.getNamespaceURI() is null.

Note: This method is a convenience and care should be taken when calling it if more then a single property matches name. In such a case the first encountered property in which Property.getName() is matches name is returned, and no order is guaranteed.

Note: Special care should be taken when using this method in the case that two properties with the same local name but different namespace uri exist. For this reason using ComplexAttribute.getProperties(Name) is safer.

Specified by:
getProperty in interface ComplexAttribute
Parameters:
name - The local name of the property to return.
Returns:
The property matching the specified name, or null.

getValue

public Collection<? extends Property> getValue()
Description copied from interface: ComplexAttribute
Override of Property.getValue() which returns the collection of Property which make up the value of the complex attribute.

Specified by:
getValue in interface ComplexAttribute
Specified by:
getValue in interface Property
Returns:
The value of the property.

setValue

public void setValue(Collection<Property> values)
Description copied from interface: ComplexAttribute
Sets the contained properties of the complex attribute.

The values should match the structure defined by getDescriptor().

Specified by:
setValue in interface ComplexAttribute

setValue

public void setValue(Object newValue)
Description copied from interface: Property
Sets the value or content of the property.

The class of newValue should be the same as or a subclass of getType().getBinding().

newValue may be null if getDescriptor().isNillable() is true.

Specified by:
setValue in interface Property
Parameters:
newValue - The new value of the property.

getDescriptor

public AttributeDescriptor getDescriptor()
Description copied from interface: Attribute
Override of Property.getDescriptor() which type narrows to AttributeDescriptor.

Specified by:
getDescriptor in interface Attribute
Specified by:
getDescriptor in interface Property
Returns:
The attribute descriptor, may be null if this is a top level type
See Also:
Attribute.getDescriptor()

getName

public Name getName()
Description copied from interface: Property
The name of the property with respect to its descriptor.

This method is convenience for getDescriptor().getName().

Specified by:
getName in interface Property
Returns:
same name than this feature's SimpleFeatureType
See Also:
Property.getName()

isNillable

public boolean isNillable()
Description copied from interface: Property
Flag indicating if null is an acceptable value for the property.

This method is convenience for getDescriptor().isNillable().

Specified by:
isNillable in interface Property
Returns:
true if the value of the property is allowed to be null, otherwise false.

getUserData

public Map<Object,Object> getUserData()
Description copied from interface: Property
A map of "user data" which enables applications to store "application-specific" information against a property.

An example of information that may wish to be stored along with an attribute could be its srs information (in the case of a geometric attribute ).

 
  GeometryAttribute attribute = ...;

  //set the crs
  CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
  attribute.setCRS( crs );

  //set the srs
  attribute.getUserData().put( "srs", "EPSG:4326" );
 
 

Specified by:
getUserData in interface Property
Returns:
A map of user data.

hashCode

public int hashCode()
returns a unique code for this feature

Overrides:
hashCode in class Object
Returns:
A unique int

equals

public boolean equals(Object obj)
override of equals. Returns if the passed in object is equal to this.

Overrides:
equals in class Object
Parameters:
obj - the Object to test for equality.
Returns:
true if the object is equal, false otherwise.

validate

public void validate()
Description copied from interface: ComplexAttribute
Check the properties against the constraints provided by their AttributeDescriptors.

Please note this method checks minOccurs and maxOccurs information; and calls each Attribute.validate on each entry in turn (in order to check isNillable, binding and restrictions).

Specified by:
validate in interface Attribute
Specified by:
validate in interface ComplexAttribute

toString

public String toString()
Overrides:
toString in class Object


Copyright © 1996-2014 Geotools. All Rights Reserved.