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 booleanIftrue, the feature type acts as an abstract super-type.private booleantrueif we determined that this feature type does not have, directly or indirectly, any unresolved name (i.e.private booleantrueif this feature type contains only attributes with [1 … 1] multiplicity, or operations.private booleantrueif the feature instances are expected to have lot of unset properties, orfalseif we expect most properties to be specified.(package private) static final IntegerValue inindicesmap 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 longFor 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 voidcomputeTransientFields(List<AbstractIdentifiedType> properties) (package private) org.opengis.util.GenericNamecreateName(org.opengis.util.NameFactory factory, String value) Creates a name from the given string.booleanCompares 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.inthashCode()Returns a hash code value for this feature type.indices()Returns the map from names to indices in an array of properties.final booleanReturnstrueif the feature type acts as an abstract super-type.booleanReturnstrueif this type is same or a super-type of the given type.private static booleanReturnstrueif instances of theothertype are assignable to the givenbasetype.(package private) static booleanReturnstrueif the given property type stands for a parameterless operation which return a result.booleanisSimple()Returnstrueif this feature type contains only attributes with [1 … 1] multiplicity, or operations (no feature association).(package private) final booleanisSparse()Returnstrueif the feature instances are expected to have lot of unset properties, orfalseif we expect most properties to be specified.(package private) static booleanmaybeAssignableFrom(DefaultFeatureType base, DefaultFeatureType type) Returnstrueif 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.GenericNameownerOf(DefaultFeatureType type, Collection<? extends AbstractIdentifiedType> properties, AbstractIdentifiedType toSearch) Returns the name of the feature which defines the given property, ornullif not found.private voidInvoked on deserialization for restoring thebyNameand other transient fields.private booleanresolve(DefaultFeatureType feature, Collection<? extends AbstractIdentifiedType> toUpdate, Map<FeatureType, Boolean> previous, boolean resolved) Implementation ofresolve(FeatureType, Map), also to be invoked from the constructor.private booleanresolve(DefaultFeatureType feature, Map<FeatureType, Boolean> previous) If an associated feature type is a placeholder for aFeatureTypeto be defined later, replaces the placeholder by the actual instance if available.private voidscanPropertiesFrom(DefaultFeatureType source, Collection<? extends AbstractIdentifiedType> sourceProperties) Fills thebyNamemap 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, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 isSimpletrueif 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 isSparsetrueif the feature instances are expected to have lot of unset properties, orfalseif we expect most properties to be specified. -
isResolved
private transient boolean isResolvedtrueif we determined that this feature type does not have, directly or indirectly, any unresolved name (i.e. aDefaultAssociationRole.valueTypespecified only be the feature type name instead of its actual instance). A value oftruemeans that all names have been resolved. However, a value offalseonly means that we are not sure, and thatresolve(FeatureType, Map)should check again.Note: Strictly speaking, this field should be declaredvolatilesince the names could be resolved late after construction, after theDefaultFeatureTypeinstance became used by different threads. However, this is not the intended usage of deferred associations. Furthermore, a wrong value (falsewhen 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 thebyNamevalues.- 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 thebyNamesize. This map shall not be modified after construction. -
OPERATION_INDEX
Value inindicesmap 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" GenericNameorStringAbstractIdentifiedType.getName()"definition" InternationalStringorStringAbstractIdentifiedType.getDefinition()"designation" InternationalStringorStringAbstractIdentifiedType.getDesignation()"description" InternationalStringorStringAbstractIdentifiedType.getDescription()"deprecated" BooleanAbstractIdentifiedType.isDeprecated()Warning: In a future SIS version, the type of array elements may be changed toorg.opengis.feature.FeatureTypeandorg.opengis.feature.PropertyType. This change is pending GeoAPI revision. In the meantime, make sure that thepropertiesarray 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, ornullor 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 thisAbtractIdentifiedObjectinstance.- Overrides:
createNamein classAbstractIdentifiedType
-
readObject
Invoked on deserialization for restoring thebyNameand 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 thebyNamemap 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.thisshall be the instance in process of being created, not any other instance (i.e. recursive method invocations are performed on the samethisinstance).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 thisDefaultFeatureTypeinstance 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, ornullif 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 aFeatureTypeto 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.
thisshall be the instance in process of being created, not other instance (i.e. recursive method invocations are performed on the samethisinstance).- Parameters:
feature- the feature type for which to resolve the properties.previous- previous results, for avoiding never ending loop.- Returns:
trueif 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.thisshall be the instance in process of being created, not other instance (i.e. recursive method invocations are performed on the samethisinstance).- 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-trueif we already know that all names are resolved.- Returns:
trueif all names have been resolved.
-
isParameterlessOperation
Returnstrueif the given property type stands for a parameterless operation which return a result.- See Also:
-
isAbstract
public final boolean isAbstract()Returnstrueif the feature type acts as an abstract super-type. Abstract types cannot be instantiated.- Returns:
trueif the feature type acts as an abstract super-type.
-
isSparse
final boolean isSparse()Returnstrueif the feature instances are expected to have lot of unset properties, orfalseif we expect most properties to be specified. -
isSimple
public boolean isSimple()Returnstrueif 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:
trueif this feature type contains only simple attributes or operations.
-
maybeAssignableFrom
Returnstrueif 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 != typebefore 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
Returnstrueif 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 compareFeatureTypetoClassin the Java language, then this method is equivalent toClass.isAssignableFrom(Class).- Specified by:
isAssignableFromin interfaceFeatureType- Parameters:
type- the type to be checked.- Returns:
trueif instances of the given type can be assigned to association of this type.
-
isAssignableIgnoreName
private static boolean isAssignableIgnoreName(AbstractIdentifiedType base, AbstractIdentifiedType other) Returnstrueif instances of theothertype are assignable to the givenbasetype. 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 compareFeatureTypetoClassin 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 toFeatureTypeif 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 ifincludeSuperTypesistrue.Warning: The type of list elements will be changed toPropertyTypeif and when such interface will be defined in GeoAPI.- Specified by:
getPropertiesin interfaceFeatureType- Parameters:
includeSuperTypes-truefor including the properties inherited from the super-types, orfalsefor 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 toPropertyTypeif 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
nullif 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 forDenseFeatureimplementation. -
newInstance
Creates a new feature instance of this type.Analogy: if we compareFeatureTypetoClassandFeaturetoObjectin 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:
hashCodein classAbstractIdentifiedType- Returns:
- the hash code for this type.
-
equals
Compares this feature type with the given object for equality.- Overrides:
equalsin classAbstractIdentifiedType- Parameters:
obj- the object to compare with this type.- Returns:
trueif the given object is equal to this type.
-
toString
Formats this feature in a tabular format.
-