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 overmethodselements.private final Iterable<? extends org.opengis.referencing.operation.OperationMethod>TheDefaultMathTransformFactory.methodsused 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 TypeMethodDescriptionbooleanReturnstrueif this set contains the given object.(package private) final booleanhasNext(int index) Returnstrueifnext(int)can return an operation method at the given index.booleanisEmpty()Returnstrueif this set is empty.protected booleanReturnstrueif 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.OperationMethodnext(int index) Returns the operation method at the given index.(package private) final voidreset()Invoked on construction time, or when the service loader has been reloaded.intsize()Returns the number of elements in this set.private booleantransfer()Transfers the next element frommethodIteratortocachedMethods.Methods inherited from class org.apache.sis.internal.util.SetOfUnknownSize
equals, removeAll, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSet
hashCodeMethods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, remove, retainAll, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Field Details
-
type
The operation type we are looking for. -
methods
TheDefaultMathTransformFactory.methodsused 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 onmethodswhen invoking this constructor.- Parameters:
type- the type of coordinate operation for which to retain methods.methods- theDefaultMathTransformFactory.methodsused 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 onmethodswhen invoking this method. -
transfer
private boolean transfer()Transfers the next element frommethodIteratortocachedMethods.- Returns:
trueif the transfer has been done, orfalseif 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()Returnstrueif this set is empty.- Specified by:
isEmptyin interfaceCollection<org.opengis.referencing.operation.OperationMethod>- Specified by:
isEmptyin interfaceSet<org.opengis.referencing.operation.OperationMethod>- Overrides:
isEmptyin classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>- Returns:
trueif this set is empty.
-
size
public int size()Returns the number of elements in this set.- Specified by:
sizein interfaceCollection<org.opengis.referencing.operation.OperationMethod>- Specified by:
sizein interfaceSet<org.opengis.referencing.operation.OperationMethod>- Overrides:
sizein classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>- Returns:
- the number of elements in this set.
-
isSizeKnown
protected boolean isSizeKnown()Returnstrueif thesize()method is cheap.- Overrides:
isSizeKnownin classSetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>- Returns:
trueif theSetOfUnknownSize.size()method is cheap.
-
hasNext
final boolean hasNext(int index) Returnstrueifnext(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 aNoSuchElementExceptioninstead of anIndexOutOfBoundsExceptionbecause this method is designed for being invoked byIterator.next(). -
iterator
Returns an iterator over the elements contained in this set.- Specified by:
iteratorin interfaceCollection<org.opengis.referencing.operation.OperationMethod>- Specified by:
iteratorin interfaceIterable<org.opengis.referencing.operation.OperationMethod>- Specified by:
iteratorin interfaceSet<org.opengis.referencing.operation.OperationMethod>- Specified by:
iteratorin classAbstractCollection<org.opengis.referencing.operation.OperationMethod>
-
contains
Returnstrueif this set contains the given object. This implementation overrides the default one with a quick check allowing us to filterOperationMethodinstances of the wrong type before to iterate over the elements.- Specified by:
containsin interfaceCollection<org.opengis.referencing.operation.OperationMethod>- Specified by:
containsin interfaceSet<org.opengis.referencing.operation.OperationMethod>- Overrides:
containsin classAbstractCollection<org.opengis.referencing.operation.OperationMethod>
-