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 classA function for simplifying anIdentifiedObjectname before comparison withisHeuristicMatchForName(Identifier, Collection, CharSequence, Simplifier). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.util.GenericNameThe name from which to infer the identifier attributes.Fields inherited from interface org.opengis.metadata.Identifier
AUTHORITY_KEY, CODE_KEYFields 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 TypeMethodDescriptionbooleanCompares this object with the given one for equality.org.opengis.metadata.citation.CitationInfers 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 StringgetCodeSpace(org.opengis.util.GenericName name, Locale locale) Takes the element before the tip as the code space.Returnsnullsince names are not versioned.inthashCode()Returns a hash code value for this object.static booleanisHeuristicMatchForIdentifier(Iterable<? extends org.opengis.referencing.ReferenceIdentifier> identifiers, String toSearch) Returnstrueif the given identifier to search matches one of the object identifiers.static booleanisHeuristicMatchForName(org.opengis.metadata.Identifier name, Collection<org.opengis.util.GenericName> aliases, CharSequence toSearch, NameToIdentifier.Simplifier simplifier) Returnstrueif the given primary name or one of the given aliases matches the given name.static booleanisHeuristicMatchForName(org.opengis.referencing.IdentifiedObject object, String name) Returnstrueif the primary name or an aliases of the given object matches the given name.private static org.opengis.util.GenericNamescope(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 StringReturns 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
nullif 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:
getAuthorityin interfaceorg.opengis.metadata.Identifier- Returns:
- the authority, or
nullif 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, ornullfor a call toname.toString().- Returns:
- the code space, or
nullif none.
-
getCodeSpace
Takes everything except the tip as the code space.- Specified by:
getCodeSpacein interfaceorg.opengis.referencing.ReferenceIdentifier
-
getCode
Takes the last element as the code.- Specified by:
getCodein interfaceorg.opengis.metadata.Identifier
-
getVersion
Returnsnullsince names are not versioned.- Specified by:
getVersionin 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, ornullfor a call toname.toString().- Returns:
- the localized string representation, or
nullif the given name was null.
-
isHeuristicMatchForIdentifier
public static boolean isHeuristicMatchForIdentifier(Iterable<? extends org.opengis.referencing.ReferenceIdentifier> identifiers, String toSearch) Returnstrueif 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:
trueif 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) Returnstrueif 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 theIdentifiedObjectto 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:
trueif the primary name or at least one alias matches the givenname.
-
isHeuristicMatchForName
public static boolean isHeuristicMatchForName(org.opengis.referencing.IdentifiedObject object, String name) Returnstrueif 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:
trueif the primary name of at least one alias matches the specifiedname.
-