Package org.apache.sis.internal.metadata
Class NameToIdentifier
java.lang.Object
org.apache.sis.internal.metadata.NameToIdentifier
- All Implemented Interfaces:
org.opengis.metadata.Identifier
,org.opengis.referencing.ReferenceIdentifier
public final class NameToIdentifier
extends Object
implements org.opengis.referencing.ReferenceIdentifier
Does the unobvious mapping between
Identifier
properties and GenericName
ones.
This class also implements the isHeuristicMatchForName(Identifier, Collection, CharSequence, Simplifier)
method since that method involves a mix of names and identifiers.
Limitations
Current version does not yet work with URN or HTTP syntax.- Since:
- 0.4
- Version:
- 0.8
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A function for simplifying anIdentifiedObject
name before comparison withisHeuristicMatchForName(Identifier, Collection, CharSequence, Simplifier)
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.util.GenericName
The name from which to infer the identifier attributes.Fields inherited from interface org.opengis.metadata.Identifier
AUTHORITY_KEY, CODE_KEY
Fields inherited from interface org.opengis.referencing.ReferenceIdentifier
CODESPACE_KEY, VERSION_KEY
-
Constructor Summary
ConstructorsConstructorDescriptionNameToIdentifier
(org.opengis.util.GenericName name) Infers the attributes from the given name. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares this object with the given one for equality.org.opengis.metadata.citation.Citation
Infers the authority from the scope if any, or from the code space otherwise.getCode()
Takes the last element as the code.Takes everything except the tip as the code space.static String
getCodeSpace
(org.opengis.util.GenericName name, Locale locale) Takes the element before the tip as the code space.Returnsnull
since names are not versioned.int
hashCode()
Returns a hash code value for this object.static boolean
isHeuristicMatchForIdentifier
(Iterable<? extends org.opengis.referencing.ReferenceIdentifier> identifiers, String toSearch) Returnstrue
if the given identifier to search matches one of the object identifiers.static boolean
isHeuristicMatchForName
(org.opengis.metadata.Identifier name, Collection<org.opengis.util.GenericName> aliases, CharSequence toSearch, NameToIdentifier.Simplifier simplifier) Returnstrue
if the given primary name or one of the given aliases matches the given name.static boolean
isHeuristicMatchForName
(org.opengis.referencing.IdentifiedObject object, String name) Returnstrue
if the primary name or an aliases of the given object matches the given name.private static org.opengis.util.GenericName
scope
(org.opengis.util.GenericName name) Returns the scope of the given name if it is not global.toString()
Returns the string representation of this identifier.static String
Returns a string representation of the given name in the given locale, with paranoiac checks against null value.
-
Field Details
-
name
private final org.opengis.util.GenericName nameThe name from which to infer the identifier attributes.
-
-
Constructor Details
-
NameToIdentifier
public NameToIdentifier(org.opengis.util.GenericName name) Infers the attributes from the given name.- Parameters:
name
- the name from which to infer the identifier properties.
-
-
Method Details
-
scope
private static org.opengis.util.GenericName scope(org.opengis.util.GenericName name) Returns the scope of the given name if it is not global. This method is null-safe, including paranoiac checks against null scope.- Parameters:
name
- the name from which to get the scope, ornull
.- Returns:
- the scope of the given name, or
null
if the given name was null or has a global scope.
-
getAuthority
public org.opengis.metadata.citation.Citation getAuthority()Infers the authority from the scope if any, or from the code space otherwise.- Specified by:
getAuthority
in interfaceorg.opengis.metadata.Identifier
- Returns:
- the authority, or
null
if none.
-
getCodeSpace
Takes the element before the tip as the code space.- Parameters:
name
- the name from which to get the code space, ornull
.locale
- the locale, ornull
for a call toname.toString()
.- Returns:
- the code space, or
null
if none.
-
getCodeSpace
Takes everything except the tip as the code space.- Specified by:
getCodeSpace
in interfaceorg.opengis.referencing.ReferenceIdentifier
-
getCode
Takes the last element as the code.- Specified by:
getCode
in interfaceorg.opengis.metadata.Identifier
-
getVersion
Returnsnull
since names are not versioned.- Specified by:
getVersion
in interfaceorg.opengis.referencing.ReferenceIdentifier
-
hashCode
public int hashCode()Returns a hash code value for this object. -
equals
Compares this object with the given one for equality. -
toString
Returns the string representation of this identifier. -
toString
Returns a string representation of the given name in the given locale, with paranoiac checks against null value. Such null values should never happen since the properties used here are mandatory, but we try to make this class robust to broken implementations.- Parameters:
name
- the name from which to get the localized string, ornull
.locale
- the locale, ornull
for a call toname.toString()
.- Returns:
- the localized string representation, or
null
if the given name was null.
-
isHeuristicMatchForIdentifier
public static boolean isHeuristicMatchForIdentifier(Iterable<? extends org.opengis.referencing.ReferenceIdentifier> identifiers, String toSearch) Returnstrue
if the given identifier to search matches one of the object identifiers.- Parameters:
identifiers
- the identifiers to compare againsttoSearch
.toSearch
- the identifier to check for equality.- Returns:
true
if the identifier to search is found in the given set of identifiers.- Since:
- 0.8
-
isHeuristicMatchForName
public static boolean isHeuristicMatchForName(org.opengis.metadata.Identifier name, Collection<org.opengis.util.GenericName> aliases, CharSequence toSearch, NameToIdentifier.Simplifier simplifier) Returnstrue
if the given primary name or one of the given aliases matches the given name. The comparison ignores case, some Latin diacritical signs and any characters that are not letters or digits.- Parameters:
name
- the name of theIdentifiedObject
to check.aliases
- the list of aliases in theIdentifiedObject
(may benull
). This method will never modify that list, so the given list can be a direct reference to an internal list.toSearch
- the name for which to check for equality.simplifier
- a function for simplifying the names before comparison.- Returns:
true
if the primary name or at least one alias matches the givenname
.
-
isHeuristicMatchForName
public static boolean isHeuristicMatchForName(org.opengis.referencing.IdentifiedObject object, String name) Returnstrue
if the primary name or an aliases of the given object matches the given name. The comparison ignores case, some Latin diacritical signs and any characters that are not letters or digits.- Parameters:
object
- the object for which to check the name or alias.name
- the name to compare with the object name or aliases.- Returns:
true
if the primary name of at least one alias matches the specifiedname
.
-