Class AttributeTypeBuilder<V>
- 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,FloatorGeometry. 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:
Defined in the sis-feature module
-
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.booleanaddRole(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 theAttributeTypeto 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, ornullif none.Returns the maximal length that characterizes theCharSequencevalues 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.voidremove()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 theCharSequencevalues 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 theAttributeTypename as a simple string (local name).setName(CharSequence... components) Sets theAttributeTypename as a string in the given scope.setName(GenericName name) Sets theAttributeTypename 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, getMinimumOccursMethods inherited from class TypeBuilder
getDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toString
-
Method Details
-
setName
Sets theAttributeTypename as a generic name. If another name was defined before this method call, that previous value will be discarded.- Overrides:
setNamein classPropertyTypeBuilder- Parameters:
name- the generic name (cannot benull).- Returns:
thisfor allowing method calls chaining.- See Also:
-
setName
Sets theAttributeTypename 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
LocalNameinstance from the givenCharSequence, then delegates tosetName(GenericName).- Overrides:
setNamein classPropertyTypeBuilder- Parameters:
localPart- the local part of the generic name as aStringorInternationalString.- Returns:
thisfor allowing method calls chaining.- See Also:
-
setName
Sets theAttributeTypename as a string in the given scope. Thecomponentsarray 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").componentsarray, 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
LocalNameorScopedNameinstance depending on whether thenamesarray contains exactly 1 element or more than 1 element, then delegates tosetName(GenericName).- Overrides:
setNamein classPropertyTypeBuilder- Parameters:
components- the name components as an array ofStringorInternationalStringinstances.- Returns:
thisfor 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:
setMinimumOccursin classPropertyTypeBuilder- Parameters:
occurs- the new minimum number of attribute values.- Returns:
thisfor 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_VALUEmeans that there is no maximum.- Overrides:
setMaximumOccursin classPropertyTypeBuilder- Parameters:
occurs- the new maximum number of attribute values.- Returns:
thisfor 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 ofthisbuilder after this method call, since the returned builder may be a new instance.- Type Parameters:
N- the compile-time value of thetypeargument.- 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, ornullif none.- Returns:
- the default attribute value, or
nullif none. - See Also:
-
setDefaultValue
Sets the default value for the attribute.- Parameters:
value- default attribute value, ornullif none.- Returns:
thisfor 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 typeSetand a conventional name.- Parameters:
values- valid values.- Returns:
thisfor allowing method calls chaining.- See Also:
-
getMaximalLength
Returns the maximal length that characterizes theCharSequencevalues of this attribute. This convenience method returns the value of the characteristic set bysetMaximalLength(Integer).- Returns:
- the maximal length of
CharSequenceattribute values, ornull.
-
setMaximalLength
Sets the maximal length that characterizes theCharSequencevalues 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 typeIntegerand a conventional name.- Parameters:
length- maximal length ofCharSequenceattribute values, ornull.- Returns:
thisfor 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 typeUnitand a conventional name.- Parameters:
unit- unit of measurement associated to attribute values, ornull.- Returns:
thisfor 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 typeCoordinateReferenceSystemand a conventional name.- Parameters:
crs- coordinate reference system associated to attribute values, ornull.- Returns:
thisfor 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
nullif none. - Throws:
IllegalArgumentException- if the given name is ambiguous.- See Also:
-
addCharacteristic
Adds another attribute type that describes this attribute type. See "Attribute characterization" inDefaultAttributeTypeJavadoc for more information.Usage example:
The default characteristic name is the name of the given type, but callers should invoke one of theattribute.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 oftypeargument.- 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" inDefaultAttributeTypeJavadoc for more information.Warning: Thetemplateargument type will be changed toAttributeTypeif and when such interface will be defined in GeoAPI.- Type Parameters:
C- the compile-time type of values in thetemplateargument.- 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 theAttributeTypeto 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:
trueif the given role has been added to the attribute.
-
setDefinition
Sets a concise definition of the element.- Overrides:
setDefinitionin classPropertyTypeBuilder- Parameters:
definition- a concise definition of the element, ornullif none.- Returns:
thisfor 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:
setDesignationin classPropertyTypeBuilder- Parameters:
designation- a natural language designator for the element, ornullif none.- Returns:
thisfor 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:
setDescriptionin classPropertyTypeBuilder- Parameters:
description- information beyond that required for concise definition of the element, ornullif none.- Returns:
thisfor 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:
setDeprecatedin classPropertyTypeBuilder- Parameters:
deprecated- whether this type is deprecated.- Returns:
thisfor allowing method calls chaining.- See Also:
-
remove
public void remove()Removes this property from theFeatureTypeBuilder. After this method has been invoked, thisPropertyTypeBuilderinstance is no longer in the list returned byFeatureTypeBuilder.properties()and attempts to invoke any setter method onthiswill cause anIllegalStateExceptionto be thrown.- Overrides:
removein 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 createdAttributeTypeinstance 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 thenamevariable below will reference the same instance than the "name" attribute in thecitytype.
Note thatFeatureTypeBuilder 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.AttributeTypeinterface. This change is pending GeoAPI revision.- Specified by:
buildin classPropertyTypeBuilder- Returns:
- the attribute type.
-