Class CancelHandlingIterator<T>

java.lang.Object
ch.tocco.nice2.rest.action.spi.tasks.CancelHandlingIterator<T>
All Implemented Interfaces:
Iterator<CancelHandlingIterator.Indexed<T>>

public class CancelHandlingIterator<T> extends Object implements Iterator<CancelHandlingIterator.Indexed<T>>
can be used to loop through some iterable until the task is cancelled or the end is reached
  • Method Details

    • withCancelHandling

      public static <T> Iterable<T> withCancelHandling(Iterable<T> values, TaskContext taskContext)
      Type Parameters:
      T - the type of the values you loop over
      Parameters:
      values - the original iterable
      taskContext - the task context to check for cancellation
      Returns:
      a new iterable that loops until cancelled or the end is reached
    • withIndexedCancelHandling

      public static <T> Iterable<CancelHandlingIterator.Indexed<T>> withIndexedCancelHandling(Iterable<T> values, TaskContext taskContext)
      Type Parameters:
      T - the type of the values you loop over
      Parameters:
      values - the original iterable
      taskContext - the task context to check for cancellation
      Returns:
      a new iterable, combining values with their index, that loops until cancelled or the end is reached
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • next

      Specified by:
      next in interface Iterator<T>