- Type Parameters:
V
- the class of attribute values.
- All Implemented Interfaces:
Localized
AttributeType
which will be part of the feature type to be built by
a FeatureTypeBuilder
. An attribute can be for example a city name, a temperature
(together with its units of measurement and uncertainty if desired) or a geometric shape.
Attribute types contain the following information:
- the name — a unique name which can be defined within a scope (or namespace).
- the definition — a concise definition of the element.
- the designation — a natural language designator for the element for user interfaces.
- the description — information beyond that required for concise definition of the element.
- the value class — often
String
,Float
orGeometry
. Must be specified at construction time. - a default value — to be used when an attribute instance does not provide an explicit value.
- characteristics — for example the units of measurement for all attributes of the same type.
- multiplicity — the minimum and maximum occurrences of attribute values.
- Since:
- 0.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<C> CharacteristicTypeBuilder
<C> addCharacteristic
(Class<C> type) Adds another attribute type that describes this attribute type.<C> CharacteristicTypeBuilder
<C> addCharacteristic
(DefaultAttributeType<C> template) Adds another attribute type that describes this attribute type, using an existing one as a template.boolean
addRole
(AttributeRole role) Flags this attribute as an input of one of the predefined operations managed byAttributeTypeBuilder
.build()
Builds the attribute type from the information specified to this builder.Returns a view of all characteristics added to theAttributeType
to build.getCharacteristic
(String name) Returns the builder for the characteristic of the given name.getCRS()
Returns the coordinate reference system associated to attribute values.Returns the default value for the attribute, ornull
if none.Returns the maximal length that characterizes theCharSequence
values of this attribute.Unit
<?> getUnit()
Returns the unit of measurement associated to attribute values.V[]
Returns an enumeration of valid values for the attribute, or an empty array if none.Returns the class of attribute values.void
remove()
Removes this property from theFeatureTypeBuilder
.roles()
Returns the roles that the attribute play in the predefined operations managed byAttributeTypeBuilder
.Sets the coordinate reference system that characterizes the values of this attribute.setDefaultValue
(V value) Sets the default value for the attribute.setDefinition
(CharSequence definition) Sets a concise definition of the element.setDeprecated
(boolean deprecated) Sets whether the type is deprecated.setDescription
(CharSequence description) Sets optional information beyond that required for concise definition of the element.setDesignation
(CharSequence designation) Sets a natural language designator for the element.setMaximalLength
(Integer length) Sets the maximal length that characterizes theCharSequence
values of this attribute.setMaximumOccurs
(int occurs) Sets the maximum number of attribute values.setMinimumOccurs
(int occurs) Sets the minimum number of attribute values.setName
(CharSequence localPart) Sets theAttributeType
name as a simple string (local name).setName
(CharSequence... components) Sets theAttributeType
name as a string in the given scope.setName
(GenericName name) Sets theAttributeType
name as a generic name.Sets the unit of measurement that characterizes the values of this attribute.final AttributeTypeBuilder
<V> setValidValues
(V... values) Sets an enumeration of valid values for the attribute.<N> AttributeTypeBuilder
<N> setValueClass
(Class<N> type) Sets the class of attribute values.Methods inherited from class PropertyTypeBuilder
getMaximumOccurs, getMinimumOccurs
Methods inherited from class TypeBuilder
getDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toString
-
Method Details
-
setName
Sets theAttributeType
name as a generic name. If another name was defined before this method call, that previous value will be discarded.- Overrides:
setName
in classPropertyTypeBuilder
- Parameters:
name
- the attribute name (cannot benull
).- Returns:
this
for allowing method calls chaining.- See Also:
-
setName
Sets theAttributeType
name as a simple string (local name). The namespace will be the value specified by the last call toFeatureTypeBuilder.setNameSpace(CharSequence)
, but that namespace will not be visible in the string representation unless the fully qualified name is requested.This convenience method creates a
LocalName
instance from the givenCharSequence
, then delegates tosetName(GenericName)
.- Overrides:
setName
in classPropertyTypeBuilder
- Parameters:
localPart
- the local part of the generic name as aString
orInternationalString
.- Returns:
this
for allowing method calls chaining.- See Also:
-
setName
Sets theAttributeType
name as a string in the given scope. Thecomponents
array must contain at least one element. The last component (the tip) will be sufficient in many cases for calls to theAbstractFeature.getProperty(String)
method. The other elements before the last one are optional and can be used for resolving ambiguity. They will be visible as the name path.Example: a call toIn addition to the path specified by thesetName("A", "B", "C")
will create a "A:B:C" name. An attribute built with this name can be obtained from a feature by a call tofeature.getProperty("C")
if there is no ambiguity, or otherwise by a call tofeature.getProperty("B:C")
(if non-ambiguous) orfeature.getProperty("A:B:C")
.components
array, the name may also contain a namespace specified by the last call toFeatureTypeBuilder.setNameSpace(CharSequence)
. But contrarily to the specified components, the namespace will not be visible in the name string representation unless the fully qualified name is requested.This convenience method creates a
LocalName
orScopedName
instance depending on whether thenames
array contains exactly 1 element or more than 1 element, then delegates tosetName(GenericName)
.- Overrides:
setName
in classPropertyTypeBuilder
- Parameters:
components
- the name components as an array ofString
orInternationalString
instances.- Returns:
this
for allowing method calls chaining.- See Also:
-
setMinimumOccurs
Sets the minimum number of attribute values. If the given number is greater than the maximal number of attribute values, than the maximum is also set to that value.- Overrides:
setMinimumOccurs
in classPropertyTypeBuilder
- Parameters:
occurs
- the new minimum number of attribute values.- Returns:
this
for allowing method calls chaining.- See Also:
-
setMaximumOccurs
Sets the maximum number of attribute values. If the given number is less than the minimal number of attribute values, than the minimum is also set to that value.Integer.MAX_VALUE
means that there is no maximum.- Overrides:
setMaximumOccurs
in classPropertyTypeBuilder
- Parameters:
occurs
- the new maximum number of attribute values.- Returns:
this
for allowing method calls chaining.- See Also:
-
getValueClass
Returns the class of attribute values.- Returns:
- the class of attribute values.
- See Also:
-
setValueClass
Sets the class of attribute values. Callers must use the builder returned by this method instead ofthis
builder after this method call, since the returned builder may be a new instance.- Type Parameters:
N
- the compile-time value of thetype
argument.- Parameters:
type
- the new class of attribute values.- Returns:
- the attribute builder — not necessarily this instance.
- Throws:
UnconvertibleObjectException
- if the default value cannot be converted to the given<N>
class.- See Also:
-
getDefaultValue
Returns the default value for the attribute, ornull
if none.- Returns:
- the default attribute value, or
null
if none. - See Also:
-
setDefaultValue
Sets the default value for the attribute.- Parameters:
value
- default attribute value, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
getValidValues
Returns an enumeration of valid values for the attribute, or an empty array if none. This convenience method returns the value of the characteristic set bysetValidValues(Object...)
.- Returns:
- valid values for the attribute, or an empty array if none.
-
setValidValues
Sets an enumeration of valid values for the attribute.This is a convenience method for
addCharacteristic(Class)
with a value of typeSet
and a conventional name.- Parameters:
values
- valid values.- Returns:
this
for allowing method calls chaining.- See Also:
-
getMaximalLength
Returns the maximal length that characterizes theCharSequence
values of this attribute. This convenience method returns the value of the characteristic set bysetMaximalLength(Integer)
.- Returns:
- the maximal length of
CharSequence
attribute values, ornull
.
-
setMaximalLength
Sets the maximal length that characterizes theCharSequence
values of this attribute. While this characteristic can be applied to any kind of attribute, it is meaningful only with character sequences.This is a convenience method for
addCharacteristic(Class)
with a value of typeInteger
and a conventional name.- Parameters:
length
- maximal length ofCharSequence
attribute values, ornull
.- Returns:
this
for allowing method calls chaining.- See Also:
-
getUnit
Returns the unit of measurement associated to attribute values. This convenience method returns the value of the characteristic set bysetUnit(Unit)
.- Returns:
- the unit of measurement associated to attribute values, or
null
.
-
setUnit
Sets the unit of measurement that characterizes the values of this attribute. While this characteristic can be applied to any kind of attribute, it is meaningful only with numeric values.This is a convenience method for
addCharacteristic(Class)
with a value of typeUnit
and a conventional name.- Parameters:
unit
- unit of measurement associated to attribute values, ornull
.- Returns:
this
for allowing method calls chaining.- See Also:
-
getCRS
Returns the coordinate reference system associated to attribute values. This convenience method returns the value of the characteristic set bysetCRS(CoordinateReferenceSystem)
.- Returns:
- the coordinate reference system associated to attribute values, or
null
.
-
setCRS
Sets the coordinate reference system that characterizes the values of this attribute. While this characteristic can be applied to any kind of attribute, it is meaningful only with georeferenced values like geometries or coverages.This is a convenience method for
addCharacteristic(Class)
with a value of typeCoordinateReferenceSystem
and a conventional name.- Parameters:
crs
- coordinate reference system associated to attribute values, ornull
.- Returns:
this
for allowing method calls chaining.- See Also:
-
getCharacteristic
Returns the builder for the characteristic of the given name. The given name does not need to contains all elements of aScopedName
; it is okay to specify only the tip (for example"myName"
instead of"myScope:myName"
) provided that ignoring the name head does not create ambiguity.- Parameters:
name
- name of the characteristic to search.- Returns:
- characteristic of the given name, or
null
if none. - Throws:
IllegalArgumentException
- if the given name is ambiguous.- See Also:
-
addCharacteristic
Adds another attribute type that describes this attribute type. See "Attribute characterization" inDefaultAttributeType
Javadoc for more information.Usage example
attribute.addCharacteristic(Unit.class).setName("Unit of measurement").setDefaultValue(Units.CELSIUS);
CharacteristicTypeBuilder.setName(…)
methods on the returned instance with a better name.- Type Parameters:
C
- the compile-time type oftype
argument.- Parameters:
type
- the class of characteristic values.- Returns:
- a builder for a characteristic of this attribute.
- See Also:
-
addCharacteristic
Adds another attribute type that describes this attribute type, using an existing one as a template. See "Attribute characterization" inDefaultAttributeType
Javadoc for more information.Warning: Thetemplate
argument type will be changed toAttributeType
if and when such interface will be defined in GeoAPI.- Type Parameters:
C
- the compile-time type of values in thetemplate
argument.- Parameters:
template
- an existing attribute type to use as a template.- Returns:
- a builder for a characteristic of this attribute, initialized with the values of the given template.
- See Also:
-
characteristics
Returns a view of all characteristics added to theAttributeType
to build. The returned list is live: changes in this builder are reflected in that list and conversely. However, the returned list allows only remove operations; new characteristics can be added only by calls to one of theset/addCharacteristic(…)
methods.- Returns:
- a live list over the characteristics declared to this builder.
- See Also:
-
roles
Returns the roles that the attribute play in the predefined operations managed byAttributeTypeBuilder
. The set returned by this method is live: additions or removal on that set are reflected back on this builder, and conversely.- Returns:
- the roles that the attribute play in the predefined operations managed by
AttributeTypeBuilder
.
-
addRole
Flags this attribute as an input of one of the predefined operations managed byAttributeTypeBuilder
. Invoking this method is equivalent to invokingroles().add(role)
.- Parameters:
role
- the role to add to the attribute (shall not be null).- Returns:
true
if the given role has been added to the attribute.
-
setDefinition
Sets a concise definition of the element.- Overrides:
setDefinition
in classPropertyTypeBuilder
- Parameters:
definition
- a concise definition of the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDesignation
Sets a natural language designator for the element. This can be used as an alternative to the name in user interfaces.- Overrides:
setDesignation
in classPropertyTypeBuilder
- Parameters:
designation
- a natural language designator for the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDescription
Sets optional information beyond that required for concise definition of the element. The description may assist in understanding the feature scope and application. If the type is deprecated, then the description should give indication about the replacement (e.g. "superceded by …").- Overrides:
setDescription
in classPropertyTypeBuilder
- Parameters:
description
- information beyond that required for concise definition of the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDeprecated
Sets whether the type is deprecated. If the type is deprecated, then the description should be set to an indication about the replacement (e.g. "superceded by …").- Overrides:
setDeprecated
in classPropertyTypeBuilder
- Parameters:
deprecated
- whether this type is deprecated.- Returns:
this
for allowing method calls chaining.- See Also:
-
remove
public void remove()Removes this property from theFeatureTypeBuilder
. After this method has been invoked, thisPropertyTypeBuilder
instance is no longer in the list returned byFeatureTypeBuilder.properties()
and attempts to invoke any setter method onthis
will cause anIllegalStateException
to be thrown.- Overrides:
remove
in classPropertyTypeBuilder
-
build
Builds the attribute type from the information specified to this builder. If a type has already been built and this builder state has not changed since the type creation, then the previously createdAttributeType
instance is returned.Example
The following lines of code add a "name" attribute to a "City" feature, then get the correspondingAttributeType<String>
instance. If no setter method is invoked on the builder of the "name" attribute after those lines, then thename
variable below will reference the same instance than the "name" attribute in thecity
type.FeatureTypeBuilder builder = new FeatureTypeBuilder().setName("City"); AttributeType<String> name = builder.addAttribute(String.class).setName("name").build(); FeatureType city = builder.build(); assert city.getProperty("name") == name : "AttributeType instance should be the same.";
city.getProperty("name")
returnsAttributeType<?>
, i.e. the value class is lost at compile-time. By comparison, thisbuild()
method has a more accurate return type.Warning: In a future SIS version, the return type may be changed to theorg.opengis.feature.AttributeType
interface. This change is pending GeoAPI revision.- Specified by:
build
in classPropertyTypeBuilder
- Returns:
- the attribute type.
-