uk.ac.starlink.table

## Class ProgressRowSplittable

- java.lang.Object
- - uk.ac.starlink.table.ProgressRowSplittable

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, RowData, RowSequence, RowSplittable, Sequence, Splittable<RowSplittable>

      public class ProgressRowSplittable
      extends java.lang.Object
      implements RowSplittable

  RowSplittable wrapper that can manage progress reporting, as well as force termination of iteration.

  Note that it is important to close instances of this splittable for correct progress reporting.

  Since:
    12 Oct 2020

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `ProgressRowSplittable.Target` Callback interface for objects that will be informed about iteration progress, and also given the opportunity to terminate iteration.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProgressRowSplittable(RowSplittable base, ProgressRowSplittable.Target target)` Public constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Indicates that this sequence will not be required any more.
    `java.lang.Object` | `getCell(int icol)` Returns the contents of a cell in the current row.
    `java.lang.Object[]` | `getRow()` Returns the contents of the current table row, as an array with the same number of elements as there are columns in this table.
    `boolean` | `next()` Attempts to advance the current row to the next one.
    `java.util.function.LongSupplier` | `rowIndex()` Returns a supplier for the index of the row currently being processed, if possible.
    `ProgressRowSplittable` | `split()` Attempts to partition this object into two halves, ideally of similar size.
    `long` | `splittableSize()` Provides an estimate of the number of processable items in this object.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ProgressRowSplittable

          public ProgressRowSplittable(RowSplittable base,
                                       ProgressRowSplittable.Target target)

      Public constructor.
      Parameters:
        `base` - splittable which this one is to monitor
        `target` - object to which progress events are reported

  - ### Method Detail

    - #### next

          public boolean next()
                       throws java.io.IOException

      Description copied from interface: `RowSequence`
      Attempts to advance the current row to the next one. If `true` is returned the attempt has been successful, and if `false` is returned there are no more rows in this sequence. Since the initial position of a RowSequence is before the first row, this method must be called before current row data can be accessed using the `RowSequence.getCell(int)` or `RowSequence.getRow()` methods.
      Specified by:
        `next` in interface `RowSequence`
      Specified by:
        `next` in interface `Sequence`
      Returns:
        `true` iff this sequence has been advanced to the next row
      Throws:
        `java.io.IOException` - if there is some error

    - #### split

          public ProgressRowSplittable split()

      Description copied from interface: `Splittable`
      Attempts to partition this object into two halves, ideally of similar size. If a non-null value is returned, then the content previously contained by this object is now split between this object and the returned object. If for any reason a split is not carried out, null is returned.

      Following a successful call, the two parts may be processed in different threads.

      Specified by:
        `split` in interface `Splittable<RowSplittable>`
      Returns:
        other half of this splittable, or null
      See Also:
        `Spliterator.trySplit()`

    - #### getCell

          public java.lang.Object getCell(int icol)
                                   throws java.io.IOException

      Description copied from interface: `RowSequence`
      Returns the contents of a cell in the current row. The class of the returned object should be the same as, or a subclass of, the class returned by `getColumnInfo(icol).getContentClass()`. An unchecked exception will be thrown if there is no current row (`next` has not yet been called).
      Specified by:
        `getCell` in interface `RowData`
      Specified by:
        `getCell` in interface `RowSequence`
      Parameters:
        `icol` - column index
      Returns:
        the contents of cell `icol` in the current row
      Throws:
        `java.io.IOException` - if there is an error reading the data

    - #### getRow

          public java.lang.Object[] getRow()
                                    throws java.io.IOException

      Description copied from interface: `RowSequence`
      Returns the contents of the current table row, as an array with the same number of elements as there are columns in this table. An unchecked exception will be thrown if there is no current row (`next` has not yet been called).
      Specified by:
        `getRow` in interface `RowData`
      Specified by:
        `getRow` in interface `RowSequence`
      Returns:
        an array of the objects in each cell in row `irow`
      Throws:
        `java.io.IOException` - if there is an error reading the data

    - #### rowIndex

          public java.util.function.LongSupplier rowIndex()

      Description copied from interface: `RowSplittable`
      Returns a supplier for the index of the row currently being processed, if possible. The row index is a global value; when accessing the first row of a top-level RowSplittable, the value returned by this supplier should be the first index in the table. But for objects resulting from splitting a top-level instance into sub-instances, the return value should reflect the index in the original sequence of rows; each index should be returned from only one of the splittables resulting from splitting a top-level instance.

      Typically, the row index will start at 0 and increment for each row, but the numbering may be different depending on the requirements of the implementation or usage.

      Before the `RowSequence.next()` method has been called, the return value will be one less than the first row index. After `RowSequence.next` has returned false, the value is undefined.

      Depending on the implementation, it may not be possible to determine the row index (for instance if the sequence is split into sub-splittables of unknown size). In such cases, this method returns null. The null-ness of the return value must be the same for all instances of the splittable hierarchy for a given sequence, so don't return a non-null value for the first splittable and then null values for some or all of its children.

      Specified by:
        `rowIndex` in interface `RowSplittable`
      Returns:
        supplier for the globally-referenced row index value of the current row of this sequence, or null

    - #### splittableSize

          public long splittableSize()

      Description copied from interface: `Splittable`
      Provides an estimate of the number of processable items in this object. A processable item is not a well-defined quantity, but it should generally be something that can be processed fast. For instance, if this object represents a collection of collections, the value that should be returned is the total number of elements rather than the number of collections.

      If no estimate for the size is available, a negative value should be returned.

      Specified by:
        `splittableSize` in interface `Splittable<RowSplittable>`
      Returns:
        approximate size, or negative value if not known

    - #### close

          public void close()
                     throws java.io.IOException

      Description copied from interface: `RowSequence`
      Indicates that this sequence will not be required any more. This should release resources associated with this object. The effect of calling any of the other methods following a `close` is undefined.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in interface `RowSequence`
      Throws:
        `java.io.IOException`