Object
FormattableObject
ImmutableIdentifier
NamedIdentifier
- All Implemented Interfaces:
Serializable
,Comparable<GenericName>
,Identifier
,ReferenceIdentifier
,GenericName
An identification of a CRS object which is both a
Identifier
and a GenericName
.
This class implements both interfaces in order to allow usage of the same instance either as an object
name or alias.
This flexibility make easier to uses object's names in two different models:
- In the ISO 19111 model, objects have a single name of type
RS_Identifier
and an arbitrary amount of aliases of typeGenericName
. - In the GML model, objects have an arbitrary number of names of type
gml:CodeType
, but do not have any alias.
NamedIdentifier
class, users can declare supplemental object's names as
aliases and have those names used in contexts
where Identifier
instances are required, like GML marshalling time.
Name ↔ Identifier mapping
TheGenericName
attributes will be inferred from Identifier
attributes as below:
- Tip: derived from the identifier code.
- Head: derived from the identifier code space if non-null. If there is no code space, then the scope is derived from the shortest authority's alternate titles, or the main title if there are no alternate titles. This policy exploits the ISO 19115 comment saying that citation alternate titles often contain abbreviation (for example "DCW" as an alternative title for "Digital Chart of the World").
Example
If the identifier attributes areauthority
= new DefaultCitation("IOGP")
,
codeSpace
= "EPSG"
and code
= "4326"
, then the name attributes will be
head
= "EPSG"
, tip
= "4326"
and toString()
= "EPSG:4326"
.
Note that the scope does not appear in the string representation of names.
Immutability and thread safety
This class is immutable and thus inherently thread-safe if theCitation
and InternationalString
arguments given to the constructor are also immutable. It is caller's responsibility to ensure that those
conditions hold, for example by invoking DefaultCitation.transitionTo(DefaultCitation.State.FINAL)
before passing the arguments to the constructor.
Subclasses shall make sure that any overridden methods remain safe to call from multiple threads and do not change
any public NamedIdentifier
state.- Since:
- 0.4
- See Also:
-
Field Summary
Fields inherited from class ImmutableIdentifier
DESCRIPTION_KEY
Fields inherited from interface Identifier
AUTHORITY_KEY, CODE_KEY
Fields inherited from interface ReferenceIdentifier
CODESPACE_KEY, VERSION_KEY
-
Constructor Summary
ConstructorDescriptionNamedIdentifier
(Map<String, ?> properties) Constructs an identifier from the given properties.NamedIdentifier
(Citation authority, CharSequence code) Constructs an identifier from an authority and code.NamedIdentifier
(Citation authority, String codeSpace, CharSequence code, String version, InternationalString description) Constructs an identifier from an authority and localizable code, with an optional version number and description.NamedIdentifier
(ReferenceIdentifier identifier) Creates a new identifier from the specified one.NamedIdentifier
(GenericName name) Creates a new identifier from the specified name. -
Method Summary
Modifier and TypeMethodDescriptionstatic NamedIdentifier
castOrCopy
(ReferenceIdentifier object) Returns a SIS identifier implementation with the values of the given arbitrary implementation.static NamedIdentifier
castOrCopy
(GenericName object) Returns a SIS name implementation with the values of the given arbitrary implementation.int
compareTo
(GenericName object) Compares this name with the specified object for order.int
depth()
Returns the depth of this name within the namespace hierarchy.boolean
Compares this identifier with the specified object for equality.List
<? extends LocalName> Returns the sequence of local names making this generic name.int
Returns a hash code value for this object.head()
Returns the first element in the sequence of parsed names.push
(GenericName scope) Returns this name expanded with the specified scope.scope()
Returns the scope (name space) in which this name is local.tip()
The last element in the sequence of parsed names.Returns a view of this name as a fully-qualified name.Returns a local-dependent string representation of this generic name.Returns a string representation of this generic name.Methods inherited from class ImmutableIdentifier
formatTo, getAuthority, getCode, getCodeSpace, getDescription, getVersion
Methods inherited from class FormattableObject
print, toString, toWKT
-
Constructor Details
-
NamedIdentifier
Creates a new identifier from the specified one. This is a copy constructor which get the code, codespace, authority, version and the description (if available) from the given identifier.If the given identifier implements the
GenericName
interface, then calls totip()
,head()
,scope()
and similar methods will delegate to that name.- Parameters:
identifier
- the identifier to copy.- See Also:
-
NamedIdentifier
Creates a new identifier from the specified name. This constructor infers the identifier attributes (code, codespace and authority) from the given name. Calls to name-related methods liketip()
,head()
andscope()
will delegate to the given name.- Parameters:
name
- the name to wrap.- See Also:
-
NamedIdentifier
Constructs an identifier from the given properties. The content of the properties map is used as described in the super-class constructor, with the addition of an optional"name"
property.Recognized properties Property name Value type Returned by "name"
GenericName
(none) Defined in parent class (reminder) "code" String
ImmutableIdentifier.getCode()
"codespace" String
ImmutableIdentifier.getCodeSpace()
"authority" String
orCitation
ImmutableIdentifier.getAuthority()
"version" String
ImmutableIdentifier.getVersion()
"description" String
orInternationalString
ImmutableIdentifier.getDescription()
"locale" Locale
(none) "name"
property is provided, then calls to name-related methods liketip()
,head()
andscope()
will delegate to the given name.- Parameters:
properties
- the properties to be given to this identifier.- Throws:
InvalidParameterValueException
- if a property has an invalid value.IllegalArgumentException
- if a property is invalid for some other reason.
-
NamedIdentifier
Constructs an identifier from an authority and code. This is a convenience constructor for commonly-used parameters.If the given code is an
InternationalString
, then thecode.toString(Locale.ROOT)
return value will be used for thecode
property, and the complete international string will be used for thename
property.- Parameters:
authority
- organization or party responsible for definition and maintenance of the code space or code, ornull
if not available.code
- identifier code or name, optionally from a controlled list or pattern defined by the authority. The code cannot be null.
-
NamedIdentifier
public NamedIdentifier(Citation authority, String codeSpace, CharSequence code, String version, InternationalString description) Constructs an identifier from an authority and localizable code, with an optional version number and description.If the given code is an
InternationalString
, then thecode.toString(Locale.ROOT)
return value will be used for thecode
property, and the complete international string will be used for thename
property.- Parameters:
authority
- organization or party responsible for definition and maintenance of the code space or code, ornull
if not available.codeSpace
- name or identifier of the person or organization responsible for namespace, ornull
if not available. This is often an abbreviation of the authority name.code
- identifier code or name, optionally from a controlled list or pattern defined by a code space. The code cannot be null.version
- the version of the associated code space or code as specified by the code authority, ornull
if none.description
- natural language description of the meaning of the code value, ornull
if none.
-
-
Method Details
-
castOrCopy
Returns a SIS identifier implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:- If the given object is
null
, then this method returnsnull
. - Otherwise if the given object is already an instance of
NamedIdentifier
, then it is returned unchanged. - Otherwise a new
NamedIdentifier
instance is created using the copy constructor and returned. Note that this is a shallow copy operation, because the other metadata contained in the given object are not recursively copied.
- Parameters:
object
- the object to get as a SIS implementation, ornull
if none.- Returns:
- a SIS implementation containing the values of the given object (may be the
given object itself), or
null
if the argument was null. - Since:
- 1.0
- If the given object is
-
castOrCopy
Returns a SIS name implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:- If the given object is
null
, then this method returnsnull
. - Otherwise if the given object is already an instance of
NamedIdentifier
, then it is returned unchanged. - Otherwise a new
NamedIdentifier
instance is created using the copy constructor and returned. Note that this is a shallow copy operation, because the other metadata contained in the given object are not recursively copied.
- Parameters:
object
- the object to get as a SIS implementation, ornull
if none.- Returns:
- a SIS implementation containing the values of the given object (may be the
given object itself), or
null
if the argument was null. - Since:
- 1.0
- If the given object is
-
tip
The last element in the sequence of parsed names. By default, this is the same value than the code provided as a local name.- Specified by:
tip
in interfaceGenericName
- Returns:
- the last element in the list of parsed names.
- See Also:
-
head
Returns the first element in the sequence of parsed names. By default, this is the same value than the code space provided as a local name.- Specified by:
head
in interfaceGenericName
- Returns:
- the first element in the list of parsed names.
- See Also:
-
scope
Returns the scope (name space) in which this name is local. By default, this is the same value than theauthority
provided as a name space.- Specified by:
scope
in interfaceGenericName
- Returns:
- the scope of this name.
- See Also:
-
depth
public int depth()Returns the depth of this name within the namespace hierarchy.- Specified by:
depth
in interfaceGenericName
- Returns:
- the depth of this name.
-
getParsedNames
Returns the sequence of local names making this generic name. The length of this sequence is the depth. It does not include the scope.- Specified by:
getParsedNames
in interfaceGenericName
- Returns:
- the local names making this generic name, without the scope.
Shall never be
null
neither empty.
-
push
Returns this name expanded with the specified scope. One may represent this operation as a concatenation of the specifiedname
withthis
.- Specified by:
push
in interfaceGenericName
- Parameters:
scope
- The name to use as prefix.- Returns:
- a concatenation of the given scope with this name.
-
toFullyQualifiedName
Returns a view of this name as a fully-qualified name.- Specified by:
toFullyQualifiedName
in interfaceGenericName
- Returns:
- the fully-qualified name (never
null
).
-
toInternationalString
Returns a local-dependent string representation of this generic name. This string is similar to the one returned bytoString()
except that each element has been localized in the specified locale. If no international string is available, then this method returns an implementation mapping totoString()
for all locales.- Specified by:
toInternationalString
in interfaceGenericName
- Returns:
- a localizable string representation of this name.
-
toString
Returns a string representation of this generic name. This string representation is local-independent. It contains all elements listed bygetParsedNames()
separated by a namespace-dependent character (usually:
or/
).- Specified by:
toString
in interfaceGenericName
- Overrides:
toString
in classFormattableObject
- Returns:
- a local-independent string representation of this generic name.
- See Also:
-
compareTo
Compares this name with the specified object for order. Returns a negative integer, zero, or a positive integer as this name lexicographically precedes, is equal to, or follows the specified object.- Specified by:
compareTo
in interfaceComparable<GenericName>
- Parameters:
object
- the object to compare with.- Returns:
- -1 if this identifier precedes the given object, +1 if it follows it.
-
equals
Compares this identifier with the specified object for equality.- Overrides:
equals
in classImmutableIdentifier
- Parameters:
object
- the object to compare with this name.- Returns:
true
if the given object is equal to this name.
-
hashCode
public int hashCode()Returns a hash code value for this object.- Overrides:
hashCode
in classImmutableIdentifier
-