Class OperationMethodSet
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.apache.sis.internal.util.SetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
org.apache.sis.referencing.operation.transform.OperationMethodSet
- All Implemented Interfaces:
Iterable<org.opengis.referencing.operation.OperationMethod>
,Collection<org.opengis.referencing.operation.OperationMethod>
,Set<org.opengis.referencing.operation.OperationMethod>
final class OperationMethodSet
extends SetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
An immutable and thread-safe set containing the operation methods given by an
Iterable
.
Initial iteration is synchronized on the given Iterable
and the result is cached.
Rational
We use this class instead of copying theOperationMethod
instances in a HashSet
in order to allow deferred OperationMethod
instantiation, for example in the usual case where the
iterable is a ServiceLoader
: we do not invoke Iterator.next()
before needed.
Limitations
The usualSet
methods like contains(Object)
are inefficient as they may require a traversal
of all elements in this set.- Since:
- 0.6
- Version:
- 0.7
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<org.opengis.referencing.operation.OperationMethod>
The methods returned by the first iteration.private Iterator<? extends org.opengis.referencing.operation.OperationMethod>
Iterator overmethods
elements.private final Iterable<? extends org.opengis.referencing.operation.OperationMethod>
TheDefaultMathTransformFactory.methods
used for fetching the initial methods.private final Class<? extends org.opengis.referencing.operation.SingleOperation>
The operation type we are looking for. -
Constructor Summary
ConstructorsConstructorDescriptionOperationMethodSet
(Class<? extends org.opengis.referencing.operation.SingleOperation> type, Iterable<? extends org.opengis.referencing.operation.OperationMethod> methods) Constructs a set wrapping the given iterable. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if this set contains the given object.(package private) final boolean
hasNext
(int index) Returnstrue
ifnext(int)
can return an operation method at the given index.boolean
isEmpty()
Returnstrue
if this set is empty.protected boolean
Returnstrue
if thesize()
method is cheap.Iterator<org.opengis.referencing.operation.OperationMethod>
iterator()
Returns an iterator over the elements contained in this set.(package private) final org.opengis.referencing.operation.OperationMethod
next
(int index) Returns the operation method at the given index.(package private) final void
reset()
Invoked on construction time, or when the service loader has been reloaded.int
size()
Returns the number of elements in this set.private boolean
transfer()
Transfers the next element frommethodIterator
tocachedMethods
.Methods inherited from class org.apache.sis.internal.util.SetOfUnknownSize
equals, removeAll, spliterator, toArray, toArray
Methods inherited from class java.util.AbstractSet
hashCode
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, remove, retainAll, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
type
The operation type we are looking for. -
methods
TheDefaultMathTransformFactory.methods
used for fetching the initial methods. We need this reference for locking purpose. -
methodIterator
-
cachedMethods
The methods returned by the first iteration.
-
-
Constructor Details
-
OperationMethodSet
OperationMethodSet(Class<? extends org.opengis.referencing.operation.SingleOperation> type, Iterable<? extends org.opengis.referencing.operation.OperationMethod> methods) Constructs a set wrapping the given iterable. The caller musts holds the lock onmethods
when invoking this constructor.- Parameters:
type
- the type of coordinate operation for which to retain methods.methods
- theDefaultMathTransformFactory.methods
used for fetching the initial methods.
-
-
Method Details
-
reset
final void reset()Invoked on construction time, or when the service loader has been reloaded. The caller musts holds the lock onmethods
when invoking this method. -
transfer
private boolean transfer()Transfers the next element frommethodIterator
tocachedMethods
.- Returns:
true
if the transfer has been done, orfalse
if the next method has been skipped because its operation type is not the expected one or because the element has already been added in a previous transfer.
-
isEmpty
public boolean isEmpty()Returnstrue
if this set is empty.- Specified by:
isEmpty
in interfaceCollection<org.opengis.referencing.operation.OperationMethod>
- Specified by:
isEmpty
in interfaceSet<org.opengis.referencing.operation.OperationMethod>
- Overrides:
isEmpty
in classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
- Returns:
true
if this set is empty.
-
size
public int size()Returns the number of elements in this set.- Specified by:
size
in interfaceCollection<org.opengis.referencing.operation.OperationMethod>
- Specified by:
size
in interfaceSet<org.opengis.referencing.operation.OperationMethod>
- Overrides:
size
in classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
- Returns:
- the number of elements in this set.
-
isSizeKnown
protected boolean isSizeKnown()Returnstrue
if thesize()
method is cheap.- Overrides:
isSizeKnown
in classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
- Returns:
true
if theSetOfUnknownSize.size()
method is cheap.
-
hasNext
final boolean hasNext(int index) Returnstrue
ifnext(int)
can return an operation method at the given index. -
next
final org.opengis.referencing.operation.OperationMethod next(int index) Returns the operation method at the given index. In case of index out of bounds, this method throws aNoSuchElementException
instead of anIndexOutOfBoundsException
because this method is designed for being invoked byIterator.next()
. -
iterator
Returns an iterator over the elements contained in this set.- Specified by:
iterator
in interfaceCollection<org.opengis.referencing.operation.OperationMethod>
- Specified by:
iterator
in interfaceIterable<org.opengis.referencing.operation.OperationMethod>
- Specified by:
iterator
in interfaceSet<org.opengis.referencing.operation.OperationMethod>
- Specified by:
iterator
in classAbstractCollection<org.opengis.referencing.operation.OperationMethod>
-
contains
Returnstrue
if this set contains the given object. This implementation overrides the default one with a quick check allowing us to filterOperationMethod
instances of the wrong type before to iterate over the elements.- Specified by:
contains
in interfaceCollection<org.opengis.referencing.operation.OperationMethod>
- Specified by:
contains
in interfaceSet<org.opengis.referencing.operation.OperationMethod>
- Overrides:
contains
in classAbstractCollection<org.opengis.referencing.operation.OperationMethod>
-