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 Classes
    Modifier and Type
    Class
    Description
    static class 
    A function for simplifying an IdentifiedObject name before comparison with isHeuristicMatchForName(Identifier, Collection, CharSequence, Simplifier).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    NameToIdentifier(org.opengis.util.GenericName name)
    Infers the attributes from the given name.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object object)
    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.
    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.
    Returns null since names are not versioned.
    int
    Returns a hash code value for this object.
    static boolean
    isHeuristicMatchForIdentifier(Iterable<? extends org.opengis.referencing.ReferenceIdentifier> identifiers, String toSearch)
    Returns true 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)
    Returns true 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)
    Returns true 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.
    Returns the string representation of this identifier.
    static String
    toString(org.opengis.util.GenericName name, Locale locale)
    Returns a string representation of the given name in the given locale, with paranoiac checks against null value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      private final org.opengis.util.GenericName name
      The 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, or null.
      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 interface org.opengis.metadata.Identifier
      Returns:
      the authority, or null if none.
    • getCodeSpace

      public static String getCodeSpace(org.opengis.util.GenericName name, Locale locale)
      Takes the element before the tip as the code space.
      Parameters:
      name - the name from which to get the code space, or null.
      locale - the locale, or null for a call to name.toString().
      Returns:
      the code space, or null if none.
    • getCodeSpace

      public String getCodeSpace()
      Takes everything except the tip as the code space.
      Specified by:
      getCodeSpace in interface org.opengis.referencing.ReferenceIdentifier
    • getCode

      public String getCode()
      Takes the last element as the code.
      Specified by:
      getCode in interface org.opengis.metadata.Identifier
    • getVersion

      public String getVersion()
      Returns null since names are not versioned.
      Specified by:
      getVersion in interface org.opengis.referencing.ReferenceIdentifier
    • hashCode

      public int hashCode()
      Returns a hash code value for this object.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Compares this object with the given one for equality.
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this identifier.
      Returns:
      true if both objects are equal.
    • toString

      public String toString()
      Returns the string representation of this identifier.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this identifier.
    • toString

      public static String toString(org.opengis.util.GenericName name, Locale locale)
      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, or null.
      locale - the locale, or null for a call to name.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)
      Returns true if the given identifier to search matches one of the object identifiers.
      Parameters:
      identifiers - the identifiers to compare against toSearch.
      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)
      Returns true 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 the IdentifiedObject to check.
      aliases - the list of aliases in the IdentifiedObject (may be null). 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 given name.
    • isHeuristicMatchForName

      public static boolean isHeuristicMatchForName(org.opengis.referencing.IdentifiedObject object, String name)
      Returns true 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 specified name.