Class NameIterator

java.lang.Object
org.apache.sis.referencing.NameIterator
All Implemented Interfaces:
Iterator<org.opengis.referencing.ReferenceIdentifier>

final class NameIterator extends Object implements Iterator<org.opengis.referencing.ReferenceIdentifier>
An iterator over the name of an identified object followed by aliases which are instance of ReferenceIdentifier. This iterator is used for AbstractIdentifiedObject XML marshalling because GML merges the name and aliases in a single <gml:name> property. However, this iterator is useful only if the aliases are instances of NamedIdentifier, or any other implementation which is both a name and an identifier.

This class also opportunistically provide helper methods for AbstractIdentifiedObject marshalling.

Since:
0.4
Version:
0.7
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Iterator<org.opengis.util.GenericName>
    An iterator over the aliases.
    private org.opengis.referencing.ReferenceIdentifier
    The next element to return, or null if we reached the end of iteration.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NameIterator(org.opengis.referencing.IdentifiedObject object)
    Creates a new iterator over the name and aliases of the given object.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    count(org.opengis.referencing.IdentifiedObject object)
    Returns the number of name and aliases in the given object.
    (package private) static String
    getID(Context context, org.opengis.referencing.IdentifiedObject object, org.opengis.referencing.ReferenceIdentifier name, Collection<? extends org.opengis.util.GenericName> alias, Collection<? extends org.opengis.referencing.ReferenceIdentifier> identifiers)
    Implementation of AbstractIdentifiedObject.getID(), provided here for reducing the amount of code to load in the common case where XML support is not needed.
    boolean
    Returns true if there is another name or alias to return.
    (package private) static boolean
    isUnnamed(org.opengis.referencing.ReferenceIdentifier name)
    Returns true if the given identifier is null or the NilReferencingObject.UNNAMED instance.
    org.opengis.referencing.ReferenceIdentifier
    Returns the next name or alias in the iteration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining, remove
  • Field Details

    • next

      private org.opengis.referencing.ReferenceIdentifier next
      The next element to return, or null if we reached the end of iteration.
    • alias

      private final Iterator<org.opengis.util.GenericName> alias
      An iterator over the aliases.
  • Constructor Details

    • NameIterator

      NameIterator(org.opengis.referencing.IdentifiedObject object)
      Creates a new iterator over the name and aliases of the given object.
  • Method Details

    • isUnnamed

      static boolean isUnnamed(org.opengis.referencing.ReferenceIdentifier name)
      Returns true if the given identifier is null or the NilReferencingObject.UNNAMED instance.
    • hasNext

      public boolean hasNext()
      Returns true if there is another name or alias to return.
      Specified by:
      hasNext in interface Iterator<org.opengis.referencing.ReferenceIdentifier>
    • next

      public org.opengis.referencing.ReferenceIdentifier next()
      Returns the next name or alias in the iteration. Note: we do not bother checking for NoSuchElementException because this iterator will be used only by JAXB, which is presumed checking for hasNext() correctly.
      Specified by:
      next in interface Iterator<org.opengis.referencing.ReferenceIdentifier>
    • count

      public static int count(org.opengis.referencing.IdentifiedObject object)
      Returns the number of name and aliases in the given object.
    • getID

      static String getID(Context context, org.opengis.referencing.IdentifiedObject object, org.opengis.referencing.ReferenceIdentifier name, Collection<? extends org.opengis.util.GenericName> alias, Collection<? extends org.opengis.referencing.ReferenceIdentifier> identifiers)
      Implementation of AbstractIdentifiedObject.getID(), provided here for reducing the amount of code to load in the common case where XML support is not needed.

      The current implementation searches for the first identifier, regardless its authority. If no identifier is found, then the name and aliases are used. Then, this method returns the concatenation of the following elements separated by hyphens:

      • The code space in lower case, retaining only characters that are valid for Unicode identifiers.
      • The object type as defined in OGC's URN (see DefinitionURI)
      • The object code, retaining only characters that are valid for Unicode identifiers.
      Example: "epsg-crs-4326".

      The returned ID needs to be unique only in the XML document being marshalled. Consecutive invocations of this method do not need to return the same value, since it may depends on the marshalling context.

      Parameters:
      context - the (un)marshalling context.
      object - the object for which to get a gml:id.
      name - the identified object name, or null if none.
      alias - the identified object aliases, or null if none.
      identifiers - the identifiers, or null if none.
      Returns:
      proposed value for gml:id attribute, or null if none.