Class DefaultFeatureType
- All Implemented Interfaces:
Serializable
,FeatureType
,Deprecable
FeatureType
instance describes the class of all
feature instances of that type.
FeatureType
is equivalent to Class
while
Feature
instances are equivalent to Object
instances of that class.FeatureType
interface in a future version.
When such interface will be available, most references to DefaultFeatureType
in the API
will be replaced by references to the FeatureType
interface.Naming
The feature type name is mandatory and should be unique. Those names are the main criterion used for deciding if a feature type is assignable from another type. Names can be scoped for avoiding name collision.Properties and inheritance
Each feature type can provide descriptions for the following properties: In addition, a feature type can inherit the properties of one or more other feature types. Properties defined in the sub-type can override properties of the same name defined in the super-types, provided that values of the sub-type property are assignable to the super-type property.String[]
can be casted to CharSequence[]
, which
is safe for read operations but not for write operations — the latter may throw ArrayStoreException
).Instantiation
DefaultFeatureType
can be instantiated directly by a call to its constructor.
But a more convenient approach may be to use the FeatureTypeBuilder
instead,
which provides shortcuts for frequently-used operations like creating various GenericName
instances sharing the same namespace.
Immutability and thread safety
Instances of this class are immutable if all properties (GenericName
and InternationalString
instances) and all arguments (AttributeType
instances) given to the constructor are also immutable.
Such immutable instances can be shared by many objects and passed between threads without synchronization.- Since:
- 0.5
- Version:
- 0.8
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Collection<AbstractIdentifiedType>
All properties, including the ones declared in the super-types.private Set<org.opengis.util.GenericName>
The names of all parents of this feature type, including parents of parents.private Map<String,
AbstractIdentifiedType> A lookup table for fetching properties by name, including the properties from super-types.Indices of properties in an array of properties similar toproperties
, but excluding operations.private final boolean
Iftrue
, the feature type acts as an abstract super-type.private boolean
true
if we determined that this feature type does not have, directly or indirectly, any unresolved name (i.e.private boolean
true
if this feature type contains only attributes with [1 … 1] multiplicity, or operations.private boolean
true
if the feature instances are expected to have lot of unset properties, orfalse
if we expect most properties to be specified.(package private) static final Integer
Value inindices
map for parameterless operations.private final List<AbstractIdentifiedType>
Any feature operation, any feature attribute type and any feature association role that carries characteristics of a feature type.private static final long
For cross-version compatibility.private final Set<DefaultFeatureType>
The direct parents of this feature type, or an empty set if none.Fields inherited from class org.apache.sis.feature.AbstractIdentifiedType
DEFINITION_KEY, deprecated, DEPRECATED_KEY, DESCRIPTION_KEY, DESIGNATION_KEY, NAME_KEY
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultFeatureType
(Map<String, ?> identification, boolean isAbstract, DefaultFeatureType[] superTypes, AbstractIdentifiedType... properties) Constructs a feature type from the given properties. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
computeTransientFields
(List<AbstractIdentifiedType> properties) (package private) org.opengis.util.GenericName
createName
(org.opengis.util.NameFactory factory, String value) Creates a name from the given string.boolean
Compares this feature type with the given object for equality.getProperties
(boolean includeSuperTypes) Returns any feature operation, any feature attribute type and any feature association role that carries characteristics of a feature type.getProperty
(String name) Returns the attribute, operation or association role for the given name.final Set<DefaultFeatureType>
Returns the direct parents of this feature type.int
hashCode()
Returns a hash code value for this feature type.indices()
Returns the map from names to indices in an array of properties.final boolean
Returnstrue
if the feature type acts as an abstract super-type.boolean
Returnstrue
if this type is same or a super-type of the given type.private static boolean
Returnstrue
if instances of theother
type are assignable to the givenbase
type.(package private) static boolean
Returnstrue
if the given property type stands for a parameterless operation which return a result.boolean
isSimple()
Returnstrue
if this feature type contains only attributes with [1 … 1] multiplicity, or operations (no feature association).(package private) final boolean
isSparse()
Returnstrue
if the feature instances are expected to have lot of unset properties, orfalse
if we expect most properties to be specified.(package private) static boolean
maybeAssignableFrom
(DefaultFeatureType base, DefaultFeatureType type) Returnstrue
if the given base type may be the same or a super-type of the given type, using only the name as a criterion.Creates a new feature instance of this type.private static org.opengis.util.GenericName
ownerOf
(DefaultFeatureType type, Collection<? extends AbstractIdentifiedType> properties, AbstractIdentifiedType toSearch) Returns the name of the feature which defines the given property, ornull
if not found.private void
Invoked on deserialization for restoring thebyName
and other transient fields.private boolean
resolve
(DefaultFeatureType feature, Collection<? extends AbstractIdentifiedType> toUpdate, Map<FeatureType, Boolean> previous, boolean resolved) Implementation ofresolve(FeatureType, Map)
, also to be invoked from the constructor.private boolean
resolve
(DefaultFeatureType feature, Map<FeatureType, Boolean> previous) If an associated feature type is a placeholder for aFeatureType
to be defined later, replaces the placeholder by the actual instance if available.private void
scanPropertiesFrom
(DefaultFeatureType source, Collection<? extends AbstractIdentifiedType> sourceProperties) Fills thebyName
map using the non-transient information in the givensource
.toString()
Formats this feature in a tabular format.Methods inherited from class org.apache.sis.feature.AbstractIdentifiedType
getDefinition, getDescription, getDesignation, getName, getRemarks, isDeprecated, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.sis.feature.FeatureType
getName
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
isAbstract
private final boolean isAbstractIftrue
, the feature type acts as an abstract super-type.- See Also:
-
isSimple
private transient boolean isSimpletrue
if this feature type contains only attributes with [1 … 1] multiplicity, or operations. The feature type shall not contains associations.- See Also:
-
isSparse
private transient boolean isSparsetrue
if the feature instances are expected to have lot of unset properties, orfalse
if we expect most properties to be specified. -
isResolved
private transient boolean isResolvedtrue
if we determined that this feature type does not have, directly or indirectly, any unresolved name (i.e. aDefaultAssociationRole.valueType
specified only be the feature type name instead of its actual instance). A value oftrue
means that all names have been resolved. However, a value offalse
only means that we are not sure, and thatresolve(FeatureType, Map)
should check again.Note: Strictly speaking, this field should be declaredvolatile
since the names could be resolved late after construction, after theDefaultFeatureType
instance became used by different threads. However, this is not the intended usage of deferred associations. Furthermore, a wrong value (false
when it should betrue
) should only cause more computation than needed, without changing the result. -
superTypes
The direct parents of this feature type, or an empty set if none.- See Also:
-
assignableTo
The names of all parents of this feature type, including parents of parents. This is used for a more efficient implementation ofisAssignableFrom(DefaultFeatureType)
.- See Also:
-
properties
Any feature operation, any feature attribute type and any feature association role that carries characteristics of a feature type. This list does not include the properties inherited from the super-types.- See Also:
-
allProperties
All properties, including the ones declared in the super-types. This is an unmodifiable view of thebyName
values.- See Also:
-
byName
A lookup table for fetching properties by name, including the properties from super-types. This map shall not be modified after construction.- See Also:
-
indices
Indices of properties in an array of properties similar toproperties
, but excluding operations. This map includes the properties from the super-types. Parameterless operations (to be handled in a special way) are identified by index -1. The size of this map may be smaller than thebyName
size. This map shall not be modified after construction. -
OPERATION_INDEX
Value inindices
map for parameterless operations. Those operations are not stored in feature instances, but can be handled as virtual attributes computed on-the-fly.
-
-
Constructor Details
-
DefaultFeatureType
public DefaultFeatureType(Map<String, ?> identification, boolean isAbstract, DefaultFeatureType[] superTypes, AbstractIdentifiedType... properties) Constructs a feature type from the given properties. The identification map is given unchanged to the super-class constructor. The following table is a reminder of main (not all) recognized map entries:Recognized map entries (non exhaustive list) Map key Value type Returned by "name" GenericName
orString
AbstractIdentifiedType.getName()
"definition" InternationalString
orString
AbstractIdentifiedType.getDefinition()
"designation" InternationalString
orString
AbstractIdentifiedType.getDesignation()
"description" InternationalString
orString
AbstractIdentifiedType.getDescription()
"deprecated" Boolean
AbstractIdentifiedType.isDeprecated()
Warning: In a future SIS version, the type of array elements may be changed toorg.opengis.feature.FeatureType
andorg.opengis.feature.PropertyType
. This change is pending GeoAPI revision. In the meantime, make sure that theproperties
array contains only attribute types, association roles or operations, not other feature types since the later are not properties in the ISO sense.- Parameters:
identification
- the name and other information to be given to this feature type.isAbstract
- iftrue
, the feature type acts as an abstract super-type.superTypes
- the parents of this feature type, ornull
or empty if none.properties
- any feature operation, any feature attribute type and any feature association role that carries characteristics of a feature type.- See Also:
-
-
Method Details
-
createName
Creates a name from the given string. This method is invoked at construction time, so it should not use any field in thisAbtractIdentifiedObject
instance.- Overrides:
createName
in classAbstractIdentifiedType
-
readObject
Invoked on deserialization for restoring thebyName
and other transient fields.- Parameters:
in
- the input stream from which to deserialize a feature type.- Throws:
IOException
- if an I/O error occurred while reading or if the stream contains invalid data.ClassNotFoundException
- if the class serialized on the stream is not on the classpath.
-
computeTransientFields
Computes transient fields (assignableTo
,byName
,indices
,isSimple
).As a side effect, this method checks for missing or duplicated names.
- Parameters:
properties
- same content asproperties
(may be the reference to the same list), but optionally in a temporarily modifiable list if we want to allow removal of duplicated values. SeescanPropertiesFrom(FeatureType, Collection)
javadoc for more explanation.- Throws:
IllegalArgumentException
- if two properties have the same name.
-
scanPropertiesFrom
private void scanPropertiesFrom(DefaultFeatureType source, Collection<? extends AbstractIdentifiedType> sourceProperties) Fills thebyName
map using the non-transient information in the givensource
. This method invokes itself recursively in order to use the information provided in super-types. This method also performs an opportunist verification of argument validity.this
shall be the instance in process of being created, not any other instance (i.e. recursive method invocations are performed on the samethis
instance).This method requires that the caller gives
source.getProperties(false)
himself for two reasons:- Avoid a call to the user-overrideable
getProperties(boolean)
method while thisDefaultFeatureType
instance is still under constructor. - Allow the
DefaultFeatureType(Map, boolean, FeatureType[], PropertyType[])
constructor to pass a temporary modifiable list that allow element removal.
- Parameters:
source
- the feature from which to get properties.sourceProperties
-source.getProperties(false)
(see above method javadoc).- Throws:
IllegalArgumentException
- if two properties have the same name.
- Avoid a call to the user-overrideable
-
ownerOf
private static org.opengis.util.GenericName ownerOf(DefaultFeatureType type, Collection<? extends AbstractIdentifiedType> properties, AbstractIdentifiedType toSearch) Returns the name of the feature which defines the given property, ornull
if not found. This method is for information purpose when producing an error message - its implementation does not need to be efficient.API note: a non-static method would be more elegant in this "SIS for GeoAPI 3.0" branch. However this method needs to be static in other SIS branches, because they work with interfaces rather than SIS implementation. We keep the method static in this branch too for easier merges.
-
resolve
If an associated feature type is a placeholder for aFeatureType
to be defined later, replaces the placeholder by the actual instance if available. Otherwise do nothing.This method is needed only in case of cyclic graph, e.g. feature A has an association to feature B which has an association back to A. It may also be A having an association to itself, etc.
this
shall be the instance in process of being created, not other instance (i.e. recursive method invocations are performed on the samethis
instance).- Parameters:
feature
- the feature type for which to resolve the properties.previous
- previous results, for avoiding never ending loop.- Returns:
true
if all names have been resolved.
-
resolve
private boolean resolve(DefaultFeatureType feature, Collection<? extends AbstractIdentifiedType> toUpdate, Map<FeatureType, Boolean> previous, boolean resolved) Implementation ofresolve(FeatureType, Map)
, also to be invoked from the constructor.this
shall be the instance in process of being created, not other instance (i.e. recursive method invocations are performed on the samethis
instance).- Parameters:
feature
- the feature type for which to resolve the properties.toUpdate
-feature.getProperties(false)
, which may contain the associations to update.previous
- previous results, for avoiding never ending loop. Initiallynull
.resolved
-true
if we already know that all names are resolved.- Returns:
true
if all names have been resolved.
-
isParameterlessOperation
Returnstrue
if the given property type stands for a parameterless operation which return a result.- See Also:
-
isAbstract
public final boolean isAbstract()Returnstrue
if the feature type acts as an abstract super-type. Abstract types cannot be instantiated.- Returns:
true
if the feature type acts as an abstract super-type.
-
isSparse
final boolean isSparse()Returnstrue
if the feature instances are expected to have lot of unset properties, orfalse
if we expect most properties to be specified. -
isSimple
public boolean isSimple()Returnstrue
if this feature type contains only attributes with [1 … 1] multiplicity, or operations (no feature association). Such feature types can be handled as a records.- Returns:
true
if this feature type contains only simple attributes or operations.
-
maybeAssignableFrom
Returnstrue
if the given base type may be the same or a super-type of the given type, using only the name as a criterion. This is a faster check thanisAssignableFrom(DefaultFeatureType)
.Performance note: callers should verify that
base != type
before to invoke this method.API note: a non-static method would be more elegant in this "SIS for GeoAPI 3.0" branch. However this method needs to be static in other SIS branches, because they work with interfaces rather than SIS implementation. We keep the method static in this branch too for easier merges.
-
isAssignableFrom
Returnstrue
if this type is same or a super-type of the given type. The check is based mainly on the feature type name, which should be unique. However, as a safety, this method also checks that all properties in this feature type is assignable from a property of the same name in the given type.Constraints
- If A is assignable from B and B is assignable from C, then A is assignable from C.
Analogy: if we compareFeatureType
toClass
in the Java language, then this method is equivalent toClass.isAssignableFrom(Class)
.- Specified by:
isAssignableFrom
in interfaceFeatureType
- Parameters:
type
- the type to be checked.- Returns:
true
if instances of the given type can be assigned to association of this type.
-
isAssignableIgnoreName
private static boolean isAssignableIgnoreName(AbstractIdentifiedType base, AbstractIdentifiedType other) Returnstrue
if instances of theother
type are assignable to the givenbase
type. This method does not compare the names — this verification is presumed already done by the caller. -
getSuperTypes
Returns the direct parents of this feature type.Analogy: if we compareFeatureType
toClass
in the Java language, then this method is equivalent toClass.getSuperclass()
except that feature types allow multi-inheritance.Warning: The type of list elements will be changed toFeatureType
if and when such interface will be defined in GeoAPI.Note for subclasses: this method is final because it is invoked (indirectly) by constructors, and invoking a user-overrideable method at construction time is not recommended. Furthermore, many Apache SIS methods need guarantees about the stability of this collection.- Returns:
- the parents of this feature type, or an empty set if none.
-
getProperties
Returns any feature operation, any feature attribute type and any feature association role that carries characteristics of a feature type. The returned collection will include the properties inherited from the super-types only ifincludeSuperTypes
istrue
.Warning: The type of list elements will be changed toPropertyType
if and when such interface will be defined in GeoAPI.- Specified by:
getProperties
in interfaceFeatureType
- Parameters:
includeSuperTypes
-true
for including the properties inherited from the super-types, orfalse
for returning only the properties defined explicitly in this type.- Returns:
- feature operation, attribute type and association role that carries characteristics of this feature type (not including parent types).
-
getProperty
Returns the attribute, operation or association role for the given name.Warning: The type of returned element will be changed toPropertyType
if and when such interface will be defined in GeoAPI.- Parameters:
name
- the name of the property to search.- Returns:
- the property for the given name, or
null
if none. - Throws:
IllegalArgumentException
- if the given argument is not a property name of this feature.- See Also:
-
indices
Returns the map from names to indices in an array of properties. This is used forDenseFeature
implementation. -
newInstance
Creates a new feature instance of this type.Analogy: if we compareFeatureType
toClass
andFeature
toObject
in the Java language, then this method is equivalent toClass.newInstance()
.- Returns:
- a new feature instance.
- Throws:
IllegalStateException
- if this feature type is abstract.
-
hashCode
public int hashCode()Returns a hash code value for this feature type.- Overrides:
hashCode
in classAbstractIdentifiedType
- Returns:
- the hash code for this type.
-
equals
Compares this feature type with the given object for equality.- Overrides:
equals
in classAbstractIdentifiedType
- Parameters:
obj
- the object to compare with this type.- Returns:
true
if the given object is equal to this type.
-
toString
Formats this feature in a tabular format.
-