Class AuthorityCodes

  • All Implemented Interfaces:
    Serializable, Iterable<String>, Collection<String>, Set<String>

    public final class AuthorityCodes
    extends AbstractSet<String>
    implements Serializable
    A set of EPSG authority codes. This set requires a living connection to the EPSG database. All iterator() method call creates a new ResultSet holding the codes. However, call to contains(java.lang.Object) map directly to a SQL call.

    Serialization of this class store a copy of all authority codes. The serialization do not preserve any connection to the database.

    Since:
    2.2
    Author:
    Martin Desruisseaux (IRD)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      Class<?> type
      The type for this code set.
    • Constructor Summary

      Constructors 
      Constructor Description
      AuthorityCodes​(TableInfo table, Class<?> type, DirectEpsgFactory factory)
      Creates a new set of authority codes for the specified type.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(Object code)
      Returns true if this collection contains the specified element.
      protected void finalize()
      Closes the underlying statements.
      boolean isEmpty()
      Returns true if this collection contains no elements.
      Iterator<String> iterator()
      Returns an iterator over the codes.
      int size()
      Count the number of elements in the underlying result set.
      protected PreparedStatement validateStatement​(PreparedStatement stmt, String sql)  
      protected Object writeReplace()
      Returns a serializable copy of this set.
      • Methods inherited from class AbstractSet

        equals, hashCode, removeAll
      • Methods inherited from class AbstractCollection

        add, addAll, clear, containsAll, remove, retainAll, toArray, toArray, toString
      • Methods inherited from class Object

        clone, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface Iterable

        forEach
      • Methods inherited from interface Set

        add, addAll, clear, containsAll, remove, retainAll, spliterator, toArray, toArray
    • Field Detail

      • type

        public final Class<?> type
        The type for this code set. This is translated to the most appropriate interface type even if the user supplied an implementation type.
    • Constructor Detail

      • AuthorityCodes

        public AuthorityCodes​(TableInfo table,
                              Class<?> type,
                              DirectEpsgFactory factory)
        Creates a new set of authority codes for the specified type.
        Parameters:
        table - The table to query.
        type - The type to query.
        factory - The factory originator.
    • Method Detail

      • validateStatement

        protected PreparedStatement validateStatement​(PreparedStatement stmt,
                                                      String sql)
                                               throws SQLException
        Throws:
        SQLException
      • isEmpty

        public boolean isEmpty()
        Returns true if this collection contains no elements. This method fetch at most one row instead of counting all rows.
        Specified by:
        isEmpty in interface Collection<String>
        Specified by:
        isEmpty in interface Set<String>
        Overrides:
        isEmpty in class AbstractCollection<String>
      • size

        public int size()
        Count the number of elements in the underlying result set.
        Specified by:
        size in interface Collection<String>
        Specified by:
        size in interface Set<String>
        Specified by:
        size in class AbstractCollection<String>
      • contains

        public boolean contains​(Object code)
        Returns true if this collection contains the specified element.
        Specified by:
        contains in interface Collection<String>
        Specified by:
        contains in interface Set<String>
        Overrides:
        contains in class AbstractCollection<String>
      • iterator

        public Iterator<String> iterator()
        Returns an iterator over the codes. The iterator is backed by a living ResultSet, which will be closed as soon as the iterator reach the last element.
        Specified by:
        iterator in interface Collection<String>
        Specified by:
        iterator in interface Iterable<String>
        Specified by:
        iterator in interface Set<String>
        Specified by:
        iterator in class AbstractCollection<String>
      • writeReplace

        protected Object writeReplace()
                               throws ObjectStreamException
        Returns a serializable copy of this set. This method is invoked automatically during serialization. The serialised set of authority code is disconnected from the underlying database.
        Throws:
        ObjectStreamException
      • finalize

        protected void finalize()
                         throws SQLException
        Closes the underlying statements. Note: this method is also invoked directly by DirectEpsgFactory.dispose(), which is okay in this particular case since the implementation of this method can be executed an arbitrary amount of times.
        Overrides:
        finalize in class Object
        Throws:
        SQLException