Class ConcurrentAuthorityFactory.Finder
java.lang.Object
org.apache.sis.referencing.factory.IdentifiedObjectFinder
org.apache.sis.referencing.factory.ConcurrentAuthorityFactory.Finder
- Enclosing class:
ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFactory>
An implementation of
IdentifiedObjectFinder
which delegates
the work to the underlying Data Access Object and caches the result.
Synchronization note
Our public API claims thatIdentifiedObjectFinder
s are not thread-safe.
Nevertheless we synchronize this particular implementation for safety, because the consequence of misuse
are more dangerous than other implementations. Furthermore, this is also a way to assert that no code path
go to the ConcurrentAuthorityFactory.create(AuthorityFactoryProxy, String)
method from a non-overridden public method.- Since:
- 0.7
- Version:
- 1.2
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sis.referencing.factory.IdentifiedObjectFinder
IdentifiedObjectFinder.Domain
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Number of time thatacquire()
has been invoked.private static final int
Number of values in theIdentifiedObjectFinder.Domain
enumeration.private IdentifiedObjectFinder
The finder on which to delegate the work.Fields inherited from class org.apache.sis.referencing.factory.IdentifiedObjectFinder
COMPARISON_MODE, factory
-
Constructor Summary
ConstructorsConstructorDescriptionFinder
(ConcurrentAuthorityFactory<?> factory) Creates a finder for the given type of objects. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
acquire()
Acquires a new finder.(package private) final Set
<org.opengis.referencing.IdentifiedObject> cache
(org.opengis.referencing.IdentifiedObject object, Set<org.opengis.referencing.IdentifiedObject> result) Stores the given result in the cache.private static Set<org.opengis.referencing.IdentifiedObject>[]
createCacheEntry
(org.opengis.referencing.IdentifiedObject object) Creates an initially empty cache entry for the given object.Set
<org.opengis.referencing.IdentifiedObject> find
(org.opengis.referencing.IdentifiedObject object) Looks up an object from this authority factory which is approximately equal to the specified object.getCodeCandidates
(org.opengis.referencing.IdentifiedObject object) Returns a set of authority codes that may identify the same object than the specified one.(package private) final Set
<org.opengis.referencing.IdentifiedObject> getFromCache
(org.opengis.referencing.IdentifiedObject object) Returns the cached value for the given object, ornull
if none.private static int
index
(IdentifiedObjectFinder finder) Returns the index in the cachedSet<IdentifiedObject>[]
array for a result using the given finder.private void
release()
Releases the finder.Methods inherited from class org.apache.sis.referencing.factory.IdentifiedObjectFinder
createFromCodes, findSingleton, getSearchDomain, isIgnoringAxes, setIgnoringAxes, setSearchDomain, setWrapper
-
Field Details
-
DOMAIN_COUNT
private static final int DOMAIN_COUNTNumber of values in theIdentifiedObjectFinder.Domain
enumeration. Hard-coded for efficiency. Value is verified using reflection by the testConcurrentAuthorityFactoryTest.verifyDomainCount()
.- See Also:
-
finder
-
acquireCount
private transient int acquireCount
-
-
Constructor Details
-
Finder
Finder(ConcurrentAuthorityFactory<?> factory) Creates a finder for the given type of objects.
-
-
Method Details
-
acquire
private void acquire() throws org.opengis.util.FactoryExceptionAcquires a new finder. Therelease()
method must be invoked in afinally
block after the call toacquire
. The pattern must be as below (note that the call toacquire()
is inside thetry
block):- Throws:
org.opengis.util.FactoryException
-
release
private void release()Releases the finder. -
getCodeCandidates
protected Set<String> getCodeCandidates(org.opengis.referencing.IdentifiedObject object) throws org.opengis.util.FactoryException Returns a set of authority codes that may identify the same object than the specified one. This method delegates to the data access object.- Overrides:
getCodeCandidates
in classIdentifiedObjectFinder
- Parameters:
object
- the object looked up.- Returns:
- a set of code candidates.
- Throws:
org.opengis.util.FactoryException
- if an error occurred while fetching the set of code candidates.
-
getFromCache
final Set<org.opengis.referencing.IdentifiedObject> getFromCache(org.opengis.referencing.IdentifiedObject object) Returns the cached value for the given object, ornull
if none. The returned set (if non-null) is unmodifiable.- Overrides:
getFromCache
in classIdentifiedObjectFinder
-
cache
final Set<org.opengis.referencing.IdentifiedObject> cache(org.opengis.referencing.IdentifiedObject object, Set<org.opengis.referencing.IdentifiedObject> result) Stores the given result in the cache. This method wraps or copies the given set in an unmodifiable set and returns the result.- Overrides:
cache
in classIdentifiedObjectFinder
- Parameters:
result
- the search result as a modifiable set.- Returns:
- a set with the same content than
result
.
-
createCacheEntry
private static Set<org.opengis.referencing.IdentifiedObject>[] createCacheEntry(org.opengis.referencing.IdentifiedObject object) Creates an initially empty cache entry for the given object. -
index
Returns the index in the cachedSet<IdentifiedObject>[]
array for a result using the given finder. -
find
public Set<org.opengis.referencing.IdentifiedObject> find(org.opengis.referencing.IdentifiedObject object) throws org.opengis.util.FactoryException Looks up an object from this authority factory which is approximately equal to the specified object. The default implementation performs the same lookup than the Data Access Object and caches the result.- Overrides:
find
in classIdentifiedObjectFinder
- Parameters:
object
- the object looked up.- Returns:
- the identified objects, or an empty set if not found.
- Throws:
org.opengis.util.FactoryException
- if an error occurred while creating an object.
-