Package org.geotools.referencing.factory
Class IdentifiedObjectSet
- Object
-
- AbstractCollection<E>
-
- AbstractSet
-
- IdentifiedObjectSet
-
- All Implemented Interfaces:
Serializable,Iterable,Collection,Set
public class IdentifiedObjectSet extends AbstractSet implements Serializable
A lazy set of identified objects. This set createsIdentifiedObjects from authority codes only when first needed. This class is typically used as the set returned by implementations of thecreateFromCoordinateReferenceSystemCodesmethod. 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 defaultAuthorityBackedFactoryimplementation).Exception handling
If the underlying factory failed to creates an object because of an unsupported operation method (NoSuchIdentifierException), the exception is logged with theFINElevel (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 uncheckedBackingStoreException. This default behavior can be changed if a subclass overrides theisRecoverableFailuremethod.Serialization
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.- Since:
- 2.2
- Author:
- Martin Desruisseaux (IRD)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected AuthorityFactoryfactoryThe factory to use for creating identified objects when first needed.
-
Constructor Summary
Constructors Constructor Description IdentifiedObjectSet(AuthorityFactory factory)Creates an initially empty set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Object object)Ensures that this collection contains the specified object.booleanaddAuthorityCode(String code)Ensures that this collection contains an object for the specified authority code.voidclear()Removes all of the elements from this collection.booleancontains(Object object)Returnstrueif this collection contains the specified object.protected IdentifiedObjectcreateObject(String code)Creates an object for the specified authority code.protected StringgetAuthorityCode(IdentifiedObject object)Returns the code to uses as a key for the specified object.String[]getAuthorityCodes()Returns the authority code of all objects in this set.protected booleanisRecoverableFailure(FactoryException exception)Returnstrueif the specified exception should be handled as a recoverable failure.Iteratoriterator()Returns an iterator over the objects in this set.booleanremove(Object object)Removes a single instance of the specified element from this collection, if it is present.booleanremoveAll(Collection collection)Removes from this collection all of its elements that are contained in the specified collection.voidresolve(int n)Ensures that the n first objects in this set are created.voidsetAuthorityCodes(String... codes)Set the content of this set as an array of authority codes.intsize()Returns the number of objects available in this set.protected ObjectwriteReplace()Returns a serializable copy of this set.-
Methods inherited from class AbstractSet
equals, hashCode
-
Methods inherited from class AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
-
Methods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface Set
addAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
factory
protected final AuthorityFactory factory
The factory to use for creating identified objects when first needed.
-
-
Constructor Detail
-
IdentifiedObjectSet
public IdentifiedObjectSet(AuthorityFactory factory)
Creates an initially empty set. The IdentifiedObjects will be created when first needed using the specified factory.- Parameters:
factory- The factory to use for deferredIdentifiedObjects creations.
-
-
Method Detail
-
clear
public void clear()
Removes all of the elements from this collection.- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet- Overrides:
clearin classAbstractCollection
-
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:
sizein interfaceCollection- Specified by:
sizein interfaceSet- Specified by:
sizein classAbstractCollection
-
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 returnstrueif 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:
addin interfaceCollection- Specified by:
addin interfaceSet- Overrides:
addin classAbstractCollection
-
contains
public boolean contains(Object object)
Returnstrueif this collection contains the specified object.- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceSet- Overrides:
containsin classAbstractCollection
-
remove
public boolean remove(Object object)
Removes a single instance of the specified element from this collection, if it is present.- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet- Overrides:
removein classAbstractCollection
-
removeAll
public boolean removeAll(Collection collection)
Removes from this collection all of its elements that are contained in the specified collection.- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceSet- Overrides:
removeAllin classAbstractSet
-
iterator
public Iterator iterator()
Returns an iterator over the objects in this set. If the iteration encounter any kind ofFactoryExceptionother thanNoSuchIdentifierException, then the exception will be rethrown as an uncheckedBackingStoreException.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceSet- Specified by:
iteratorin classAbstractCollection
-
resolve
public void resolve(int n) throws FactoryExceptionEnsures that the n first objects in this set are created. This method is typically invoked after some calls toaddAuthorityCode(java.lang.String)in order to make sure that the underlying factory is really capable to create at least one object.FactoryException(except the ones accepted as recoverable failures) are thrown as if they were never wrapped intoBackingStoreException.- Parameters:
n- The number of object to resolve. If this number is equals or greater than the set's size, then the creation of all objects is garantee successful.- Throws:
FactoryException- if an object creation failed.
-
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 thisIdentifiedObjectSetimplementation.This method is typically used together with
getAuthorityCodes()for altering the iteration order on the basis of authority codes. If the specifiedcodesarray contains the same elements thangetAuthorityCodes()in a different order, then this method just set the new ordering.- See Also:
addAuthorityCode(java.lang.String)
-
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 invokesfactory.. Subclasses may override this method if they want to invoke a more specific method.createObject(code)- Throws:
FactoryException
-
isRecoverableFailure
protected boolean isRecoverableFailure(FactoryException exception)
Returnstrueif 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 returnstruefor the given exception, then the exception will be logged in the Geotools factory logger with theFINElevel. If this method returnsfalse, then the exception will be retrown as aBackingStoreException. The default implementation returnstrueonly forNoSuchIdentifierException(not to be confused withNoSuchAuthorityCodeException).
-
writeReplace
protected Object writeReplace() throws ObjectStreamException
Returns a serializable copy of this set. This method is invoked automatically during serialization. The serialised set of identified objects is disconnected from the underlying factory.- Throws:
ObjectStreamException
-
-