Class AbstractIdentifiedObject
- All Implemented Interfaces:
Serializable
,IdentifiedObject
- Direct Known Subclasses:
AbstractCoordinateOperation
,AbstractCS
,AbstractDatum
,AbstractParameterDescriptor
,AbstractReferenceSystem
,DefaultCoordinateSystemAxis
,DefaultEllipsoid
,DefaultOperationMethod
,DefaultPrimeMeridian
AuthorityFactory
is used to create an object, the
authority and authority code
values are set to the authority name of the factory object, and the authority code supplied by the client,
respectively. When ObjectFactory
creates an object, the name is set to the value supplied by the client and all of the other metadata items are left empty.
This class is conceptually abstract, even if it is technically possible to instantiate it. Typical
applications should create instances of the most specific subclass with Default
prefix instead. An exception
to this rule may occurs when it is not possible to identify the exact type. For example it is not possible to infer
the exact coordinate system from Well Known
Text is some cases (e.g. in a LOCAL_CS
element). In such exceptional situation, a plain
AbstractCS
object may be instantiated.
- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GenericName[]
An empty array of alias.static final ReferenceIdentifier[]
An empty array of identifiers.static final Comparator<IdentifiedObject>
A comparator for sorting identified objects by identifiers.static final Comparator<IdentifiedObject>
A comparator for sorting identified objects by name.static final Comparator<IdentifiedObject>
A comparator for sorting identified objects by remarks.Fields inherited from class Formattable
SINGLE_LINE
Fields inherited from interface IdentifiedObject
ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractIdentifiedObject
(Map<String, ?> properties) Constructs an object from a set of properties.protected
AbstractIdentifiedObject
(Map<String, ?> properties, Map<String, Object> subProperties, String... localizables) Constructs an object from a set of properties and copy unrecognized properties in the specified map.Constructs a new identified object with the same values than the specified one. -
Method Summary
Modifier and TypeMethodDescriptionprotected static <E> Set<E>
asSet
(E... array) Returns the specified array as an immutable set, ornull
if the array is empty or null.protected static void
ensureAngularUnit
(Unit<?> unit) Makes sure that the specified unit is an angular one.protected static void
ensureLinearUnit
(Unit<?> unit) Makes sure that the specified unit is a linear one.protected static void
ensureNonNull
(String name, Object object) Makes sure that an argument is non-null.protected static void
ensureNonNull
(String name, Object[] array, int index) Makes sure an array element is non-null.protected static void
ensureTimeUnit
(Unit<?> unit) Makes sure that the specified unit is a temporal one.final boolean
Compares the specified object with this object for equality.protected static boolean
equals
(Collection<? extends IdentifiedObject> collection1, Collection<? extends IdentifiedObject> collection2, boolean compareMetadata) Compares two collectionss of OpenGIS'sIdentifiedObject
objects for equality.protected static boolean
equals
(IdentifiedObject[] array1, IdentifiedObject[] array2, boolean compareMetadata) Compares two arrays of OpenGIS'sIdentifiedObject
objects for equality.protected static boolean
equals
(IdentifiedObject object1, IdentifiedObject object2, boolean compareMetadata) Compares two OpenGIS'sIdentifiedObject
objects for equality.boolean
equals
(AbstractIdentifiedObject object, boolean compareMetadata) Compares this object with the specified object for equality.getAlias()
An alternative name by which this object is identified.getIdentifier
(Citation authority) Returns an identifier according the given authority.static ReferenceIdentifier
getIdentifier
(IdentifiedObject info, Citation authority) Returns an identifier according the given authority.An identifier which references elsewhere the object's defining information.getName()
The primary name by which this object is identified.Returns this object's name according the given authority.static String
getName
(IdentifiedObject info, Citation authority) Returns an object's name according the given authority.Returns the informations provided in the specified indentified object as a map of properties.getProperties
(IdentifiedObject info, Citation authority) Returns the properties to be given to an identified object derived from the specified one.Comments on or information about this object, including data source information.int
hashCode()
Returns a hash value for this identified object.boolean
nameMatches
(String name) static boolean
nameMatches
(IdentifiedObject object, String name) static boolean
Returnstrue
if the primary name of an object matches the primary name of one alias of the other object.Methods inherited from class Formattable
cleanupThreadLocals, formatWKT, toString, toWKT, toWKT, toWKT, toWKT
Methods inherited from interface IdentifiedObject
toWKT
-
Field Details
-
EMPTY_IDENTIFIER_ARRAY
An empty array of identifiers. This is usefull for fetching identifiers as an array, using the following idiom:getIdentifiers().toArray(EMPTY_IDENTIFIER_ARRAY);
-
EMPTY_ALIAS_ARRAY
An empty array of alias. This is usefull for fetching alias as an array, using the following idiom:getAlias().toArray(EMPTY_ALIAS_ARRAY);
-
NAME_COMPARATOR
A comparator for sorting identified objects by name. -
IDENTIFIER_COMPARATOR
A comparator for sorting identified objects by identifiers. -
REMARKS_COMPARATOR
A comparator for sorting identified objects by remarks.
-
-
Constructor Details
-
AbstractIdentifiedObject
Constructs a new identified object with the same values than the specified one. This copy constructor provides a way to wrap an arbitrary implementation into a Geotools one or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API. This constructor performs a shallow copy, i.e. the properties are not cloned.- Parameters:
object
- The object to copy.
-
AbstractIdentifiedObject
Constructs an object from a set of properties. Keys are strings from the table below. Key are case-insensitive, and leading and trailing spaces are ignored. The map given in argument shall contains at least a"name"
property. Other properties listed in the table below are optional.Property name Value type Value given to "name" String
orReferenceIdentifier
getName()
"alias" String
,String[]
,GenericName
orGenericName[]
getAlias()
"authority" String
orCitation
Identifier.getAuthority()
on the name"codespace" String
ReferenceIdentifier.getCodeSpace()
on the name"version" String
ReferenceIdentifier.getVersion()
on the name"identifiers" ReferenceIdentifier
orReferenceIdentifier[]
getIdentifiers()
"remarks" String
orInternationalString
getRemarks()
Additionally, all localizable attributes like
"remarks"
may have a language and country code suffix. For example the"remarks_fr"
property stands for remarks in French and the"remarks_fr_CA"
property stands for remarks in French Canadian.Note that the
"authority"
and"version"
properties are ignored if the"name"
property is already aCitation
object instead of aString
.- Parameters:
properties
- The properties to be given to this identified object.- Throws:
InvalidParameterValueException
- if a property has an invalid value.IllegalArgumentException
- if a property is invalid for some other reason.
-
AbstractIdentifiedObject
protected AbstractIdentifiedObject(Map<String, ?> properties, Map<String, throws IllegalArgumentExceptionObject> subProperties, String... localizables) Constructs an object from a set of properties and copy unrecognized properties in the specified map. Theproperties
argument is treated as in the one argument constructor. All properties unknow to thisAbstractIdentifiedObject
constructor are copied in thesubProperties
map, after their key has been normalized (usually lower case, leading and trailing space removed).If
localizables
is non-null, then all keys listed in this argument are treated as localizable one (i.e. may have a suffix like "_fr", "_de", etc.). Localizable properties are stored in thesubProperties
map asInternationalString
objects.- Parameters:
properties
- Set of properties. Should contains at least"name"
.subProperties
- The map in which to copy unrecognized properties.localizables
- Optional list of localized properties.- Throws:
InvalidParameterValueException
- if a property has an invalid value.IllegalArgumentException
- if a property is invalid for some other reason.
-
-
Method Details
-
getName
The primary name by which this object is identified.- Specified by:
getName
in interfaceIdentifiedObject
- Returns:
- The primary name.
- See Also:
-
getAlias
An alternative name by which this object is identified.- Specified by:
getAlias
in interfaceIdentifiedObject
- Returns:
- The aliases, or an empty array if there is none.
- See Also:
-
getIdentifiers
An identifier which references elsewhere the object's defining information. Alternatively an identifier by which this object can be referenced.- Specified by:
getIdentifiers
in interfaceIdentifiedObject
- Returns:
- This object identifiers, or an empty array if there is none.
- See Also:
-
getRemarks
Comments on or information about this object, including data source information.- Specified by:
getRemarks
in interfaceIdentifiedObject
- Returns:
- The remarks, or
null
if none.
-
getProperties
Returns the informations provided in the specified indentified object as a map of properties. The returned map contains key such asNAME_KEY
, and values from methods such asgetName()
.- Parameters:
info
- The identified object to view as a properties map.- Returns:
- An view of the identified object as an immutable map.
-
getProperties
Returns the properties to be given to an identified object derived from the specified one. This method is typically used for creating a new CRS identical to an existing one except for axis units. This method returns the same properties than the supplied argument (as ofgetProperties(info)
), except for the following:- The name's authority is replaced by the specified one.
- All identifiers are removed, because the new object to be created is probably not endorsed by the original authority.
This method returns a mutable map. Consequently, callers can add their own identifiers directly to this map if they wish.
- Parameters:
info
- The identified object to view as a properties map.authority
- The new authority for the object to be created, ornull
if it is not going to have any declared authority.- Returns:
- An view of the identified object as a mutable map.
-
getIdentifier
Returns an identifier according the given authority. This method first checks all identifiers in their iteration order. It returns the first identifier with an authority citation matching the specified authority.- Parameters:
authority
- The authority for the identifier to return, ornull
for the first identifier regarless its authority.- Returns:
- The object's identifier, or
null
if no identifier matching the specified authority was found. - Since:
- 2.2
-
getIdentifier
Returns an identifier according the given authority. This method performs the same search thangetIdentifier(Citation)
on arbitrary implementations of GeoAPI interface.- Parameters:
info
- The object to get the identifier from.authority
- The authority for the identifier to return, ornull
for the first identifier regarless its authority.- Returns:
- The object's identifier, or
null
if no identifier matching the specified authority was found. - Since:
- 2.2
-
getName
Returns this object's name according the given authority. This method checks first the primary name, then all alias in their iteration order.-
If the name or alias implements the
ReferenceIdentifier
interface, then this method compares the identifier authority against the specified citation using theidentifierMatches
method. If a matching is found, then this method returns the identifier code of this object. -
Otherwise, if the alias implements the
GenericName
interface, then this method compares the name scope against the specified citation using the identifierMatches method. If a matching is found, then this method returns the local name of this object.
ReferenceIdentifier
andGenericName
interfaces (for exampleNamedIdentifier
). In such cases, the identifier view has precedence.- Parameters:
authority
- The authority for the name to return.- Returns:
- The object's name (either a code or a
local name), or
null
if no name matching the specified authority was found. - Since:
- 2.2
- See Also:
-
-
getName
Returns an object's name according the given authority. This method performs the same search thangetName(Citation)
on arbitrary implementations of GeoAPI interface.- Parameters:
info
- The object to get the name from.authority
- The authority for the name to return.- Returns:
- The object's name (either a code or a
local name), or
null
if no name matching the specified authority was found. - Since:
- 2.2
-
nameMatches
Returnstrue
if either the primary name or at least one alias matches the specified string. This method performs the search in the following order, regardless of any authority:- The primary name of this object
- The fully qualified name of an alias
- The local name of an alias
- Parameters:
name
- The name to compare.- Returns:
true
if the primary name of at least one alias matches the specifiedname
.
-
nameMatches
Returnstrue
if either the primary name or at least one alias matches the specified string. This method performs the same check than the non-static method on arbitrary object implementing the GeoAPI interface.- Parameters:
object
- The object to check.name
- The name.- Returns:
true
if the primary name of at least one alias matches the specifiedname
.
-
nameMatches
Returnstrue
if the primary name of an object matches the primary name of one alias of the other object.- Parameters:
o1
- The first object to compare by name.o2
- The second object to compare by name.- Returns:
true
if both objects have a common name.- Since:
- 2.4
-
equals
Compares the specified object with this object for equality. -
equals
Compares this object with the specified object for equality.If
compareMetadata
istrue
, then all available properties are compared including name, remarks, identifiers code, etc.If
compareMetadata
isfalse
, then this method compare only the properties needed for computing transformations. In other words,sourceCS.equals(targetCS, false)
returnstrue
only if the transformation fromsourceCS
totargetCS
is the identity transform, no matter whatgetName()
saids.Some subclasses (especially
AbstractDatum
andAbstractParameterDescriptor
) will test for the name, since objects with different name have completely different meaning. For example nothing differentiate the"semi_major"
and"semi_minor"
parameters except the name. The name comparison may be loose however, i.e. we may accept a name matching an alias.- Parameters:
object
- The object to compare tothis
.compareMetadata
-true
for performing a strict comparison, orfalse
for comparing only properties relevant to transformations.- Returns:
true
if both objects are equal.
-
equals
protected static boolean equals(IdentifiedObject object1, IdentifiedObject object2, boolean compareMetadata) Compares two OpenGIS'sIdentifiedObject
objects for equality. This convenience method is provided for implementation ofequals
in subclasses.- Parameters:
object1
- The first object to compare (may benull
).object2
- The second object to compare (may benull
).compareMetadata
-true
for performing a strict comparaison, orfalse
for comparing only properties relevant to transformations.- Returns:
true
if both objects are equal.
-
equals
protected static boolean equals(IdentifiedObject[] array1, IdentifiedObject[] array2, boolean compareMetadata) Compares two arrays of OpenGIS'sIdentifiedObject
objects for equality. This convenience method is provided for implementation ofequals
method in subclasses.- Parameters:
array1
- The first array to compare (may benull
).array2
- The second array to compare (may benull
).compareMetadata
-true
for performing a strict comparaison, orfalse
for comparing only properties relevant to transformations.- Returns:
true
if both arrays are equal.
-
equals
protected static boolean equals(Collection<? extends IdentifiedObject> collection1, Collection<? extends IdentifiedObject> collection2, boolean compareMetadata) Compares two collectionss of OpenGIS'sIdentifiedObject
objects for equality. The comparaison take order in account, which make it more appropriate forList
orLinkedHashSet
comparaisons. This convenience method is provided for implementation ofequals
method in subclasses.- Parameters:
collection1
- The first collection to compare (may benull
).collection2
- The second collection to compare (may benull
).compareMetadata
-true
for performing a strict comparaison, orfalse
for comparing only properties relevant to transformations.- Returns:
true
if both collections are equal.
-
hashCode
public int hashCode()Returns a hash value for this identified object. Name, identifiers and remarks are not taken in account. In other words, two identified objects will return the same hash value if they are equal in the sense ofequals(AbstractIdentifiedObject, false)
. -
asSet
Returns the specified array as an immutable set, ornull
if the array is empty or null. This is a convenience method for sub-classes constructors.- Type Parameters:
E
- The type of array elements.- Parameters:
array
- The array to copy in a set. May benull
.- Returns:
- A set containing the array elements, or
null
if none or empty.
-
ensureNonNull
protected static void ensureNonNull(String name, Object object) throws InvalidParameterValueException Makes sure that an argument is non-null. This is a convenience method for subclass constructors.- Parameters:
name
- Argument name.object
- User argument.- Throws:
InvalidParameterValueException
- ifobject
is null.
-
ensureNonNull
protected static void ensureNonNull(String name, Object[] array, int index) throws InvalidParameterValueException Makes sure an array element is non-null. This is a convenience method for subclass constructors.- Parameters:
name
- Argument name.array
- User argument.index
- Index of the element to check.- Throws:
InvalidParameterValueException
- ifarray[i]
is null.
-
ensureTimeUnit
Makes sure that the specified unit is a temporal one. This is a convenience method for subclass constructors.- Parameters:
unit
- Unit to check.- Throws:
IllegalArgumentException
- ifunit
is not a temporal unit.
-
ensureLinearUnit
Makes sure that the specified unit is a linear one. This is a convenience method for subclass constructors.- Parameters:
unit
- Unit to check.- Throws:
IllegalArgumentException
- ifunit
is not a linear unit.
-
ensureAngularUnit
Makes sure that the specified unit is an angular one. This is a convenience method for subclass constructors.- Parameters:
unit
- Unit to check.- Throws:
IllegalArgumentException
- ifunit
is not an angular unit.
-