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 the OperationMethod 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 usual Set 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 Details

    • type

      private final Class<? extends org.opengis.referencing.operation.SingleOperation> type
      The operation type we are looking for.
    • methods

      private final Iterable<? extends org.opengis.referencing.operation.OperationMethod> methods
      The DefaultMathTransformFactory.methods used for fetching the initial methods. We need this reference for locking purpose.
    • methodIterator

      private Iterator<? extends org.opengis.referencing.operation.OperationMethod> methodIterator
      Iterator over methods elements. All usage of this iterator must be synchronized on methods. Will be set to null when the iteration is over.
    • cachedMethods

      private final List<org.opengis.referencing.operation.OperationMethod> 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 on methods when invoking this constructor.
      Parameters:
      type - the type of coordinate operation for which to retain methods.
      methods - the DefaultMathTransformFactory.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 on methods when invoking this method.
    • transfer

      private boolean transfer()
      Transfers the next element from methodIterator to cachedMethods.
      Returns:
      true if the transfer has been done, or false 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()
      Returns true if this set is empty.
      Specified by:
      isEmpty in interface Collection<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      isEmpty in interface Set<org.opengis.referencing.operation.OperationMethod>
      Overrides:
      isEmpty in class SetOfUnknownSize<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 interface Collection<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      size in interface Set<org.opengis.referencing.operation.OperationMethod>
      Overrides:
      size in class SetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
      Returns:
      the number of elements in this set.
    • isSizeKnown

      protected boolean isSizeKnown()
      Returns true if the size() method is cheap.
      Overrides:
      isSizeKnown in class SetOfUnknownSize<org.opengis.referencing.operation.OperationMethod>
      Returns:
      true if the SetOfUnknownSize.size() method is cheap.
    • hasNext

      final boolean hasNext(int index)
      Returns true if next(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 a NoSuchElementException instead of an IndexOutOfBoundsException because this method is designed for being invoked by Iterator.next().
    • iterator

      public Iterator<org.opengis.referencing.operation.OperationMethod> iterator()
      Returns an iterator over the elements contained in this set.
      Specified by:
      iterator in interface Collection<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      iterator in interface Iterable<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      iterator in interface Set<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      iterator in class AbstractCollection<org.opengis.referencing.operation.OperationMethod>
    • contains

      public boolean contains(Object object)
      Returns true if this set contains the given object. This implementation overrides the default one with a quick check allowing us to filter OperationMethod instances of the wrong type before to iterate over the elements.
      Specified by:
      contains in interface Collection<org.opengis.referencing.operation.OperationMethod>
      Specified by:
      contains in interface Set<org.opengis.referencing.operation.OperationMethod>
      Overrides:
      contains in class AbstractCollection<org.opengis.referencing.operation.OperationMethod>