public class IdentifiedObjectSet extends AbstractSet implements Serializable
IdentifiedObject
s 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).
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.
Modifier and Type | Field and Description |
---|---|
protected AuthorityFactory |
factory
The factory to use for creating identified objects when first
needed.
|
Constructor and Description |
---|
IdentifiedObjectSet(AuthorityFactory factory)
Creates an initially empty set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object object)
Ensures that this collection contains the specified object.
|
boolean |
addAuthorityCode(String code)
Ensures that this collection contains an object for the specified authority code.
|
void |
clear()
Removes all of the elements from this collection.
|
boolean |
contains(Object object)
Returns
true if this collection contains the specified object. |
protected IdentifiedObject |
createObject(String code)
Creates an object for the specified authority code.
|
protected String |
getAuthorityCode(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 boolean |
isRecoverableFailure(FactoryException exception)
Returns
true if the specified exception should be handled as a recoverable failure. |
Iterator |
iterator()
Returns an iterator over the objects in this set.
|
boolean |
remove(Object object)
Removes a single instance of the specified element from this collection, if it is present.
|
boolean |
removeAll(Collection collection)
Removes from this collection all of its elements that are contained in the specified
collection.
|
void |
resolve(int n)
Ensures that the n first objects in this set are created.
|
void |
setAuthorityCodes(String[] codes)
Set the content of this set as an array of authority codes.
|
int |
size()
Returns the number of objects available in this set.
|
protected Object |
writeReplace()
Returns a serializable copy of this set.
|
equals, hashCode
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
addAll, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
protected final AuthorityFactory factory
public IdentifiedObjectSet(AuthorityFactory factory)
factory
- The factory to use for deferred IdentifiedObject
s creations.public void clear()
clear
in interface Collection
clear
in interface Set
clear
in class AbstractCollection
public int size()
size
in interface Collection
size
in interface Set
size
in class AbstractCollection
public boolean addAuthorityCode(String code)
true
if this set changed as a result of this
call.public boolean add(Object object)
add
in interface Collection
add
in interface Set
add
in class AbstractCollection
public boolean contains(Object object)
true
if this collection contains the specified object.contains
in interface Collection
contains
in interface Set
contains
in class AbstractCollection
public boolean remove(Object object)
remove
in interface Collection
remove
in interface Set
remove
in class AbstractCollection
public boolean removeAll(Collection collection)
removeAll
in interface Collection
removeAll
in interface Set
removeAll
in class AbstractSet
public Iterator iterator()
FactoryException
other than NoSuchIdentifierException
, then the exception
will be rethrown as an unchecked BackingStoreException
.iterator
in interface Iterable
iterator
in interface Collection
iterator
in interface Set
iterator
in class AbstractCollection
public void resolve(int n) throws FactoryException
addAuthorityCode(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 into BackingStoreException
.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.FactoryException
- if an object creation failed.public String[] getAuthorityCodes()
This method is typically used together with setAuthorityCodes(java.lang.String[])
for altering the
iteration order on the basis of authority codes.
public void setAuthorityCodes(String[] codes)
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.
addAuthorityCode(java.lang.String)
protected String getAuthorityCode(IdentifiedObject object)
protected IdentifiedObject createObject(String code) throws FactoryException
factory.createObject
(code)
.
Subclasses may override this method if they want to invoke a more specific method.FactoryException
protected boolean isRecoverableFailure(FactoryException exception)
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
).protected Object writeReplace() throws ObjectStreamException
ObjectStreamException
Copyright © 1996–2019 Geotools. All rights reserved.