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
putandremovemethods) 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 classThe 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 IdentifierMapAn immutable empty instance.final Collection<org.opengis.metadata.Identifier>The identifiers to wrap in a map view.private static final longFor 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 TypeMethodDescriptionvoidclear()Removes every entries in the underlying collection.final booleancontainsKey(Object authority) Returnstrueif at least one identifier declares the given authority.final booleancontainsValue(Object code) Returnstrueif at least one identifier declares the given code.entrySet()Returns a view over the collection of identifiers.final StringReturns the code of the first identifier associated with the given authority, ornullif no identifier was found.private URIgetHRef()Extracts thexlink:hrefvalue from theXLinkif presents.(package private) final org.opengis.metadata.IdentifiergetIdentifier(org.opengis.metadata.citation.Citation authority) Returns the identifier for the given key, ornullif none.final Collection<org.opengis.metadata.Identifier>getIdentifiers(Class<?> type) Returns the identifiers as a collection of the specified type.final <T> TgetSpecialized(IdentifierSpace<T> authority) Returns the identifier associated with the given authority, ornullif no specialized identifier was found.final booleanisEmpty()Returnstrueif the collection of identifiers contains at least one element.(package private) booleanWhether this map supportputandremoveoperations.Sets the code of the identifier having the given authority to the given value.<T> TputSpecialized(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 intsize()Counts the number of entries, ignoring null elements and duplicated authorities.(package private) static intspecialCase(Object authority) If the given authority is a special case, returns itsNonMarshalledAuthorityinteger enum.toString()Overrides the string representation in order to use only the authority title as keys.private static StringReturns the string representation of the given value, ornullif none.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 ifidentifiersis 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.classorSet.class.- Returns:
- the identifiers as a collection of the specified type.
-
specialCase
If the given authority is a special case, returns itsNonMarshalledAuthorityinteger enum. Otherwise returns -1. See javadoc for more information about special cases.- Parameters:
authority- aCitationconstant. The type is relaxed toObjectbecause the signature of someMapmethods are that way.
-
getHRef
Extracts thexlink:hrefvalue from theXLinkif presents. This method does not test if an explicitxlink:hrefidentifier 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, ornullif none.- Parameters:
value- the value returned be one of the abovegetFoo()methods.
-
isModifiable
boolean isModifiable()Whether this map supportputandremoveoperations. -
isEmpty
public final boolean isEmpty()Returnstrueif 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
nullelements are ignored, this method may return 0 even ifisEmpty()returnsfalse. However, this inconsistency should not happen in practice becauseModifiableMetadatainternal collection implementations do not allow null values. -
containsValue
Returnstrueif at least one identifier declares the given code.- Specified by:
containsValuein interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
containsValuein classAbstractMap<org.opengis.metadata.citation.Citation,String> - Parameters:
code- the code to search, which should be an instance ofString.- Returns:
trueif at least one identifier uses the given code.
-
containsKey
Returnstrueif at least one identifier declares the given authority.- Specified by:
containsKeyin interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
containsKeyin classAbstractMap<org.opengis.metadata.citation.Citation,String> - Parameters:
authority- the authority to search, which should be an instance ofCitation.- Returns:
trueif 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, ornullif none. -
getSpecialized
Returns the identifier associated with the given authority, ornullif no specialized identifier was found.- Specified by:
getSpecializedin 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
nullif this map contains no mapping for the namespace.
-
get
Returns the code of the first identifier associated with the given authority, ornullif no identifier was found.- Specified by:
getin interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
getin 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
nullif none.
-
remove
Removes all identifiers associated with the given authority.- Specified by:
removein interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
removein 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
nullif none. - Throws:
UnsupportedOperationException- if the collection of identifiers is unmodifiable.
-
clear
Removes every entries in the underlying collection.- Specified by:
clearin interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
clearin 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 thegetmethod.- Specified by:
putin interfaceMap<org.opengis.metadata.citation.Citation,String> - Overrides:
putin 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, ornullfor removing the entry.- Returns:
- the previous code for the given authority, or
nullif 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:
putSpecializedin 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, ornullif 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 ofDefaultCitationobjects are very big.String examples:
- {gml:id=“myID”}
- {gco:uuid=“42924124-032a-4dfe-b06e-113e3cb81cf0”}
- {xlink:href=“http://www.mydomain.org/myHREF”}
- Overrides:
toStringin classAbstractMap<org.opengis.metadata.citation.Citation,String> - See Also:
-