Class SeriesMonitorDecorator<T>

java.lang.Object
org.refcodes.generator.SeriesMonitorDecorator<T>
Type Parameters:
T - the generic type of the elements being generated.
All Implemented Interfaces:
Iterator<T>, Generator<T>, SeriesMonitor<T>, org.refcodes.mixin.Clearable

public class SeriesMonitorDecorator<T> extends Object implements SeriesMonitor<T>
The SeriesMonitorDecorator decorates a Generator with means to monitor the last fully processed (completed) ID of the series of generated IDs with all preceding generated IDs also being fully processed (completed): All IDs till the last fully processed (completed) ID have been processed. Any IDs being processed after this last fully processed (completed) ID are not taken into account as between them and the the last fully processed (completed) ID there are gaps of uncompleted (not yet finished) IDs (which were not filled up yet e.g. as of a multi threaded environment).
  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • hasNext

      public boolean hasNext()
      Tests whether the Generator is capable of generating a Generator.next() item.
      Specified by:
      hasNext in interface Generator<T>
      Specified by:
      hasNext in interface Iterator<T>
      Returns:
      true, if successful
    • next

      public T next()
      Generates a next item.
      Specified by:
      next in interface Generator<T>
      Specified by:
      next in interface Iterator<T>
      Returns:
      The next item generated
    • forEachRemaining

      public void forEachRemaining(Consumer<? super T> aAction)
      Specified by:
      forEachRemaining in interface Iterator<T>
    • markAsProcessed

      public boolean markAsProcessed(T aId)
      Marks a ID previously generated using Generator.next() as being processed, the last ID of fully processed IDs in the series of generated IDs can be identified using the SeriesMonitor.lastProcessed() method.
      Specified by:
      markAsProcessed in interface SeriesMonitor<T>
      Parameters:
      aId - The ID to be marked as processed.
      Returns:
      True in case the ID has not been marked before as processed, false if the ID has never been generated or has already been Marked as processed.
    • lastProcessed

      public T lastProcessed()
      Returns the last ID of fully processed IDs in the series of generated IDs.
      Specified by:
      lastProcessed in interface SeriesMonitor<T>
      Returns:
      The according ID or null if nine ID has yet been marked as being processed.
    • clear

      public void clear()
      Clears the list of unprocessed IDs.
      Specified by:
      clear in interface org.refcodes.mixin.Clearable