Class IdentifiedObjectSet

  • All Implemented Interfaces:
    Serializable, Iterable, Collection, Set

    public class IdentifiedObjectSet
    extends AbstractSet
    implements Serializable
    A lazy set of identified objects. This set creates IdentifiedObjects from authority codes only when first needed. This class is typically used as the set returned by implementations of the createFromCoordinateReferenceSystemCodes method. Deferred creation in this case may have great performance impact since a set may contains about 40 entries (e.g. transformations from "ED50" (EPSG:4230) to "WGS 84" (EPSG:4326)) while some users only want to look for the first entry (e.g. the default AuthorityBackedFactory implementation).

    Exception handling

    If the underlying factory failed to creates an object because of an unsupported operation method (NoSuchIdentifierException), the exception is logged with the FINE level (because this is a recoverable failure) and the iteration continue. If the operation creation failed for any other kind of reason (FactoryException), then the exception is rethrown as an unchecked BackingStoreException. This default behavior can be changed if a subclass overrides the isRecoverableFailure method.


    Serialization of this class forces the immediate creation of all identified objects not yet created. The serialized set is disconnected from the underlying factory.

    Thread safety

    This class is not thread-safe.
    Martin Desruisseaux (IRD)
    See Also:
    Serialized Form
    • Constructor Detail

      • IdentifiedObjectSet

        public IdentifiedObjectSet​(AuthorityFactory factory)
        Creates an initially empty set. The IdentifiedObjects will be created when first needed using the specified factory.
        factory - The factory to use for deferred IdentifiedObjects creations.
    • Method Detail

      • size

        public int size()
        Returns the number of objects available in this set. Note that this number may decrease during the iteration process if the creation of some identified objects failed.
        Specified by:
        size in interface Collection
        Specified by:
        size in interface Set
        Specified by:
        size in class AbstractCollection
      • addAuthorityCode

        public boolean addAuthorityCode​(String code)
        Ensures that this collection contains an object for the specified authority code. The identified object will be created from the specified code only when first needed. This method returns true if this set changed as a result of this call.
      • add

        public boolean add​(Object object)
        Ensures that this collection contains the specified object. This set do not allows multiple objects for the same authority code. If this set already contains an object using the same authority code than the specified one, then the old object is replaced by the new one even if the objects are not otherwise identical.
        Specified by:
        add in interface Collection
        Specified by:
        add in interface Set
        add in class AbstractCollection
      • remove

        public boolean remove​(Object object)
        Removes a single instance of the specified element from this collection, if it is present.
        Specified by:
        remove in interface Collection
        Specified by:
        remove in interface Set
        remove in class AbstractCollection
      • getAuthorityCodes

        public String[] getAuthorityCodes()
        Returns the authority code of all objects in this set. The returned array contains the codes in iteration order. This method do not trig the creation of any new object.

        This method is typically used together with setAuthorityCodes(java.lang.String...) for altering the iteration order on the basis of authority codes.

      • setAuthorityCodes

        public void setAuthorityCodes​(String... codes)
        Set the content of this set as an array of authority codes. For any code in the given list, this method will preserve the corresponding identified object if it was already created. Other objects will be created only when first needed, as usual in this IdentifiedObjectSet implementation.

        This method is typically used together with getAuthorityCodes() for altering the iteration order on the basis of authority codes. If the specified codes array contains the same elements than getAuthorityCodes() in a different order, then this method just set the new ordering.

        See Also:
      • getAuthorityCode

        protected String getAuthorityCode​(IdentifiedObject object)
        Returns the code to uses as a key for the specified object. The default implementation returns the code of the first identifier, if any, or the code of theprimary name otherwise. Subclasses may overrides this method if they want to use a different key for this set.
      • createObject

        protected IdentifiedObject createObject​(String code)
                                         throws FactoryException
        Creates an object for the specified authority code. This method is invoked during the iteration process if an object was not already created. The default implementation invokes factory.createObject(code). Subclasses may override this method if they want to invoke a more specific method.
      • isRecoverableFailure

        protected boolean isRecoverableFailure​(FactoryException exception)
        Returns true if the specified exception should be handled as a recoverable failure. This method is invoked during the iteration process if the factory failed to create some object. If this method returns true for the given exception, then the exception will be logged in the Geotools factory logger with the FINE level. If this method returns false, then the exception will be retrown as a BackingStoreException. The default implementation returns true only for NoSuchIdentifierException (not to be confused with NoSuchAuthorityCodeException).