Class IdentifierMapAdapter
- All Implemented Interfaces:
Serializable
,Map<org.opengis.metadata.citation.Citation,
,String> IdentifierMap
- Direct Known Subclasses:
ModifiableIdentifierMap
IdentifiedObject
instances.
This base class implements an unmodifiable map, but the ModifiableIdentifierMap
subclass add write
capabilities.
This class works as a wrapper around a collection of identifiers. Because all operations are performed by an iteration over the collection elements, this implementation is suitable only for small maps (less than 10 elements). Given that objects typically have only one or two identifiers, this is considered acceptable.
Special cases
The identifiers for the following authorities are handled in a special way:IdentifierSpace.HREF
: handled as a shortcut toXLink.getHRef()
.
Handling of duplicated authorities
The collection shall not contain more than one identifier for the same authority. However, duplications may happen if the user has direct access to the list, for example throughCitation.getIdentifiers()
. If such
duplication is found, then this map implementation applies the following rules:
- All getter methods (including the iterators and the values returned by the
put
andremove
methods) return only the identifier code associated to the first occurrence of each authority. Any subsequent occurrences of the same authorities are silently ignored. - All setter methods may affect all identifiers previously associated to the given authority, not just the first occurrence. The only guarantee is that the list is update in such a way that the effect of setter methods are visible to subsequent calls to getter methods.
Handling of null identifiers
The collection of identifiers shall not contain any null element. This is normally ensured by theModifiableMetadata
internal collection implementations.
This class performs opportunist null checks as an additional safety, but consistency is not
guaranteed. See size()
for more information.
Thread safety
This class is thread safe if the underlying identifier collection is thread safe.- Since:
- 0.3
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The iterator over the (citation, code) entries.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IdentifierMap
An immutable empty instance.final Collection<org.opengis.metadata.Identifier>
The identifiers to wrap in a map view.private static final long
For cross-version compatibility. -
Constructor Summary
ConstructorsConstructorDescriptionIdentifierMapAdapter
(Collection<org.opengis.metadata.Identifier> identifiers) Creates a new map which will be a view over the given identifiers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes every entries in the underlying collection.final boolean
containsKey
(Object authority) Returnstrue
if at least one identifier declares the given authority.final boolean
containsValue
(Object code) Returnstrue
if at least one identifier declares the given code.entrySet()
Returns a view over the collection of identifiers.final String
Returns the code of the first identifier associated with the given authority, ornull
if no identifier was found.private URI
getHRef()
Extracts thexlink:href
value from theXLink
if presents.(package private) final org.opengis.metadata.Identifier
getIdentifier
(org.opengis.metadata.citation.Citation authority) Returns the identifier for the given key, ornull
if none.final Collection<org.opengis.metadata.Identifier>
getIdentifiers
(Class<?> type) Returns the identifiers as a collection of the specified type.final <T> T
getSpecialized
(IdentifierSpace<T> authority) Returns the identifier associated with the given authority, ornull
if no specialized identifier was found.final boolean
isEmpty()
Returnstrue
if the collection of identifiers contains at least one element.(package private) boolean
Whether this map supportput
andremove
operations.Sets the code of the identifier having the given authority to the given value.<T> T
putSpecialized
(IdentifierSpace<T> authority, T value) Sets the identifier associated with the given authority, and returns the previous value.Removes all identifiers associated with the given authority.final int
size()
Counts the number of entries, ignoring null elements and duplicated authorities.(package private) static int
specialCase
(Object authority) If the given authority is a special case, returns itsNonMarshalledAuthority
integer enum.toString()
Overrides the string representation in order to use only the authority title as keys.private static String
Returns the string representation of the given value, ornull
if none.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, values
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
EMPTY
An immutable empty instance. -
identifiers
The identifiers to wrap in a map view.- See Also:
-
-
Constructor Details
-
IdentifierMapAdapter
Creates a new map which will be a view over the given identifiers.- Parameters:
identifiers
- the identifiers to wrap in a map view.
-
-
Method Details
-
getIdentifiers
Returns the identifiers as a collection of the specified type. The given type is the return type of thegetIdentifiers()
method which is delegating to this method. The returned collection is modifiable only ifidentifiers
is already of the desired type. This is the case forISOMetadata.getIdentifiers()
, which is the API for which we want modifiable collections.- Parameters:
type
-Collection.class
,List.class
orSet.class
.- Returns:
- the identifiers as a collection of the specified type.
-
specialCase
If the given authority is a special case, returns itsNonMarshalledAuthority
integer enum. Otherwise returns -1. See javadoc for more information about special cases.- Parameters:
authority
- aCitation
constant. The type is relaxed toObject
because the signature of someMap
methods are that way.
-
getHRef
Extracts thexlink:href
value from theXLink
if presents. This method does not test if an explicitxlink:href
identifier exists; this check must be done by the caller before to invoke this method.- See Also:
-
toString
Returns the string representation of the given value, ornull
if none.- Parameters:
value
- the value returned be one of the abovegetFoo()
methods.
-
isModifiable
boolean isModifiable()Whether this map supportput
andremove
operations. -
isEmpty
public final boolean isEmpty()Returnstrue
if the collection of identifiers contains at least one element. This method does not verify if the collection contains null element (it should not). -
size
public final int size()Counts the number of entries, ignoring null elements and duplicated authorities.Because
null
elements are ignored, this method may return 0 even ifisEmpty()
returnsfalse
. However, this inconsistency should not happen in practice becauseModifiableMetadata
internal collection implementations do not allow null values. -
containsValue
Returnstrue
if at least one identifier declares the given code.- Specified by:
containsValue
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
containsValue
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Parameters:
code
- the code to search, which should be an instance ofString
.- Returns:
true
if at least one identifier uses the given code.
-
containsKey
Returnstrue
if at least one identifier declares the given authority.- Specified by:
containsKey
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
containsKey
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Parameters:
authority
- the authority to search, which should be an instance ofCitation
.- Returns:
true
if at least one identifier uses the given authority.
-
getIdentifier
final org.opengis.metadata.Identifier getIdentifier(org.opengis.metadata.citation.Citation authority) Returns the identifier for the given key, ornull
if none. -
getSpecialized
Returns the identifier associated with the given authority, ornull
if no specialized identifier was found.- Specified by:
getSpecialized
in interfaceIdentifierMap
- Type Parameters:
T
- the identifier type.- Parameters:
authority
- the namespace whose associated identifier is to be returned.- Returns:
- the identifier to which the given namespace is mapped, or
null
if this map contains no mapping for the namespace.
-
get
Returns the code of the first identifier associated with the given authority, ornull
if no identifier was found.- Specified by:
get
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
get
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Parameters:
authority
- the authority to search, which should be an instance ofCitation
.- Returns:
- the code of the identifier for the given authority, or
null
if none.
-
remove
Removes all identifiers associated with the given authority.- Specified by:
remove
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
remove
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Parameters:
authority
- the authority to search, which should be an instance ofCitation
.- Returns:
- the code of the identifier for the given authority, or
null
if none. - Throws:
UnsupportedOperationException
- if the collection of identifiers is unmodifiable.
-
clear
Removes every entries in the underlying collection.- Specified by:
clear
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
clear
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Throws:
UnsupportedOperationException
- if the collection of identifiers is unmodifiable.
-
put
public String put(org.opengis.metadata.citation.Citation authority, String code) throws UnsupportedOperationException Sets the code of the identifier having the given authority to the given value. If no identifier is found for the given authority, a new one is created. If more than one identifier is found for the given authority, then all previous identifiers may be removed in order to ensure that the new entry will be the first entry, so it can be find by theget
method.- Specified by:
put
in interfaceMap<org.opengis.metadata.citation.Citation,
String> - Overrides:
put
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - Parameters:
authority
- the authority for which to set the code.code
- the new code for the given authority, ornull
for removing the entry.- Returns:
- the previous code for the given authority, or
null
if none. - Throws:
UnsupportedOperationException
- if the collection of identifiers is unmodifiable.
-
putSpecialized
public <T> T putSpecialized(IdentifierSpace<T> authority, T value) throws UnsupportedOperationException Sets the identifier associated with the given authority, and returns the previous value.- Specified by:
putSpecialized
in interfaceIdentifierMap
- Type Parameters:
T
- the identifier type.- Parameters:
authority
- the namespace with which the given identifier is to be associated.value
- the identifier to be associated with the given namespace.- Returns:
- the previous identifier associated with
authority
, ornull
if there was no mapping of the specialized type forauthority
. - Throws:
UnsupportedOperationException
- if the identifier map is unmodifiable.
-
entrySet
Returns a view over the collection of identifiers. This view supports removal operation if the underlying collection of identifiers supports theIterator.remove()
method.If the backing identifier collection contains null entries, those entries will be ignored. If the backing collection contains many entries for the same authority, then only the first occurrence is included.
-
toString
Overrides the string representation in order to use only the authority title as keys. We do that because the string representations ofDefaultCitation
objects are very big.String examples:
- {gml:id=“myID”}
- {gco:uuid=“42924124-032a-4dfe-b06e-113e3cb81cf0”}
- {xlink:href=“http://www.mydomain.org/myHREF”}
- Overrides:
toString
in classAbstractMap<org.opengis.metadata.citation.Citation,
String> - See Also:
-