V - the class of attribute values.public final class AttributeTypeBuilder<V> extends PropertyTypeBuilder
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:
String, Float or Geometry.
Must be specified at construction time.FeatureTypeBuilder.addAttribute(Class),
DefaultAttributeTypeDefined in the sis-feature module
| Modifier and Type | Method and Description |
|---|---|
<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 pre-defined operations managed by
AttributeTypeBuilder. |
DefaultAttributeType<V> |
build()
Builds the attribute type from the information specified to this builder.
|
List<CharacteristicTypeBuilder<?>> |
characteristics()
Returns a view of all characteristics added to the
AttributeType to build. |
CharacteristicTypeBuilder<?> |
getCharacteristic(String name)
Returns the builder for the characteristic of the given name.
|
CoordinateReferenceSystem |
getCRS()
Returns the coordinate reference system associated to attribute values.
|
V |
getDefaultValue()
Returns the default value for the attribute, or
null if none. |
Integer |
getMaximalLength()
Returns the maximal length that characterizes the
CharSequence values of this attribute. |
V[] |
getValidValues()
Returns an enumeration of valid values for the attribute, or an empty array if none.
|
Class<V> |
getValueClass()
Returns the class of attribute values.
|
void |
remove()
Removes this property from the
FeatureTypeBuilder. |
Set<AttributeRole> |
roles()
Returns the roles that the attribute play in the pre-defined operations managed by
AttributeTypeBuilder. |
AttributeTypeBuilder<V> |
setCRS(CoordinateReferenceSystem crs)
Sets the coordinate reference system that characterizes the values of this attribute.
|
AttributeTypeBuilder<V> |
setDefaultValue(V value)
Sets the default value for the attribute.
|
AttributeTypeBuilder<V> |
setDefinition(CharSequence definition)
Sets a concise definition of the element.
|
AttributeTypeBuilder<V> |
setDeprecated(boolean deprecated)
Sets whether the type is deprecated.
|
AttributeTypeBuilder<V> |
setDescription(CharSequence description)
Sets optional information beyond that required for concise definition of the element.
|
AttributeTypeBuilder<V> |
setDesignation(CharSequence designation)
Sets a natural language designator for the element.
|
AttributeTypeBuilder<V> |
setMaximalLength(Integer length)
Sets the maximal length that characterizes the
CharSequence values of this attribute. |
AttributeTypeBuilder<V> |
setMaximumOccurs(int occurs)
Sets the maximum number of attribute values.
|
AttributeTypeBuilder<V> |
setMinimumOccurs(int occurs)
Sets the minimum number of attribute values.
|
AttributeTypeBuilder<V> |
setName(CharSequence... components)
Sets the
AttributeType name as a string in the given scope. |
AttributeTypeBuilder<V> |
setName(CharSequence localPart)
Sets the
AttributeType name as a simple string (local name). |
AttributeTypeBuilder<V> |
setName(GenericName name)
Sets the
AttributeType name as a generic name. |
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.
|
getMaximumOccurs, getMinimumOccursgetDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toStringpublic AttributeTypeBuilder<V> setName(GenericName name)
AttributeType name as a generic name.
If another name was defined before this method call, that previous value will be discarded.setName in class TypeBuildername - the generic name (can not be null).this for allowing method calls chaining.TypeBuilder.getName(),
TypeBuilder.setName(CharSequence),
AbstractIdentifiedType.NAME_KEYpublic AttributeTypeBuilder<V> setName(CharSequence localPart)
AttributeType name as a simple string (local name).
The namespace will be the value specified by the last call to FeatureTypeBuilder.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 given CharSequence, then delegates to setName(GenericName).
setName in class TypeBuilderlocalPart - the local part of the generic name as a String or InternationalString.this for allowing method calls chaining.TypeBuilder.getName(),
TypeBuilder.setName(CharSequence...),
FeatureTypeBuilder.getNameSpace()public AttributeTypeBuilder<V> setName(CharSequence... components)
AttributeType name as a string in the given scope.
The components array must contain at least one element.
The last component (the tip) will be sufficient
in many cases for calls to the AbstractFeature.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.
setName("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 to feature.getProperty("C")
if there is no ambiguity, or otherwise by a call to feature.getProperty("B:C") (if non-ambiguous) or
feature.getProperty("A:B:C").components array, the name may also contain
a namespace specified by the last call to FeatureTypeBuilder.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 or ScopedName
instance depending on whether the names array contains exactly 1 element or more than 1 element, then
delegates to setName(GenericName).
setName in class TypeBuildercomponents - the name components as an array of String or InternationalString instances.this for allowing method calls chaining.TypeBuilder.getName(),
TypeBuilder.setName(CharSequence),
FeatureTypeBuilder.getNameSpace()public AttributeTypeBuilder<V> setMinimumOccurs(int occurs)
setMinimumOccurs in class PropertyTypeBuilderoccurs - the new minimum number of attribute values.this for allowing method calls chaining.PropertyTypeBuilder.getMinimumOccurs()public AttributeTypeBuilder<V> setMaximumOccurs(int occurs)
setMaximumOccurs in class PropertyTypeBuilderoccurs - the new maximum number of attribute values.this for allowing method calls chaining.PropertyTypeBuilder.getMaximumOccurs()public Class<V> getValueClass()
setValueClass(Class)public <N> AttributeTypeBuilder<N> setValueClass(Class<N> type) throws UnconvertibleObjectException
this builder after this method call, since the returned builder may be a new instance.N - the compile-time value of the type argument.type - the new class of attribute values.UnconvertibleObjectException - if the default value
can not be converted to the given <N> class.getValueClass()public V getDefaultValue()
null if none.null if none.setDefaultValue(Object)public AttributeTypeBuilder<V> setDefaultValue(V value)
value - default attribute value, or null if none.this for allowing method calls chaining.getDefaultValue()public V[] getValidValues()
setValidValues(Object...).@SafeVarargs public final AttributeTypeBuilder<V> setValidValues(V... values)
This is a convenience method for addCharacteristic(Class) with a value
of type Set and a conventional name.
values - valid values.this for allowing method calls chaining.characteristics(),
AttributeConvention.VALID_VALUES_CHARACTERISTICpublic Integer getMaximalLength()
CharSequence values of this attribute.
This convenience method returns the value of the characteristic set by setMaximalLength(Integer).CharSequence attribute values, or null.public AttributeTypeBuilder<V> setMaximalLength(Integer length)
CharSequence 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 type Integer and a conventional name.
length - maximal length of CharSequence attribute values, or null.this for allowing method calls chaining.characteristics(),
AttributeConvention.MAXIMAL_LENGTH_CHARACTERISTICpublic CoordinateReferenceSystem getCRS()
setCRS(CoordinateReferenceSystem).null.public AttributeTypeBuilder<V> setCRS(CoordinateReferenceSystem crs)
This is a convenience method for addCharacteristic(Class) with a value
of type CoordinateReferenceSystem and a conventional name.
crs - coordinate reference system associated to attribute values, or null.this for allowing method calls chaining.characteristics(),
AttributeConvention.CRS_CHARACTERISTICpublic CharacteristicTypeBuilder<?> getCharacteristic(String name)
ScopedName; 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.name - name of the characteristic to search.null if none.IllegalArgumentException - if the given name is ambiguous.characteristics()public <C> CharacteristicTypeBuilder<C> addCharacteristic(Class<C> type)
DefaultAttributeType Javadoc for more information.
Usage example:
attribute.addCharacteristic(Unit.class).setName("Unit of measurement").setDefaultValue(Units.CELSIUS);
The default characteristic name is the name of the given type, but callers should invoke one
of the CharacteristicTypeBuilder.setName(…) methods on the returned instance with a better name.C - the compile-time type of type argument.type - the class of characteristic values.characteristics()public <C> CharacteristicTypeBuilder<C> addCharacteristic(DefaultAttributeType<C> template)
DefaultAttributeType Javadoc for more information.
template argument type will be changed to AttributeType if and when such interface
will be defined in GeoAPI.C - the compile-time type of values in the template argument.template - an existing attribute type to use as a template.characteristics()public List<CharacteristicTypeBuilder<?>> characteristics()
AttributeType 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 the set/addCharacteristic(…) methods.getCharacteristic(String),
addCharacteristic(Class),
addCharacteristic(DefaultAttributeType),
setValidValues(Object...),
setCRS(CoordinateReferenceSystem)public Set<AttributeRole> roles()
AttributeTypeBuilder.
The set returned by this method is live: additions or removal on that set are reflected back on
this builder, and conversely.AttributeTypeBuilder.public boolean addRole(AttributeRole role)
AttributeTypeBuilder.
Invoking this method is equivalent to invoking roles().add(role).role - the role to add to the attribute (shall not be null).true if the given role has been added to the attribute.public AttributeTypeBuilder<V> setDefinition(CharSequence definition)
setDefinition in class TypeBuilderdefinition - a concise definition of the element, or null if none.this for allowing method calls chaining.TypeBuilder.getDefinition(),
AbstractIdentifiedType.DEFINITION_KEYpublic AttributeTypeBuilder<V> setDesignation(CharSequence designation)
setDesignation in class TypeBuilderdesignation - a natural language designator for the element, or null if none.this for allowing method calls chaining.TypeBuilder.getDesignation(),
AbstractIdentifiedType.DESIGNATION_KEYpublic AttributeTypeBuilder<V> setDescription(CharSequence description)
setDescription in class TypeBuilderdescription - information beyond that required for concise definition of the element, or null if none.this for allowing method calls chaining.TypeBuilder.getDescription(),
AbstractIdentifiedType.DESCRIPTION_KEYpublic AttributeTypeBuilder<V> setDeprecated(boolean deprecated)
setDeprecated in class TypeBuilderdeprecated - whether this type is deprecated.this for allowing method calls chaining.TypeBuilder.isDeprecated(),
AbstractIdentifiedType.DEPRECATED_KEYpublic void remove()
FeatureTypeBuilder.
After this method has been invoked, this PropertyTypeBuilder instance
is no longer in the list returned by FeatureTypeBuilder.properties()
and attempts to invoke any setter method on this will cause an
IllegalStateException to be thrown.remove in class PropertyTypeBuilderpublic DefaultAttributeType<V> build()
AttributeType instance is returned.
AttributeType<String> instance. If no setter method is invoked on the builder of the "name"
attribute after those lines, then the name variable below will reference the same instance
than the "name" attribute in the city 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.";
Note that city.getProperty("name") returns AttributeType<?>,
i.e. the value class is lost at compile-time.
By comparison, this build() method has a more accurate return type.
org.opengis.feature.AttributeType interface. This change is pending GeoAPI revision.build in class PropertyTypeBuilderCopyright © 2010–2017 The Apache Software Foundation. All rights reserved.