Class AbstractCounterComposite<T>

java.lang.Object
org.refcodes.generator.AbstractCounterComposite<T>
Type Parameters:
T - the generic type of the elements being generated.
All Implemented Interfaces:
Iterator<T>, Counter<T>, Generator<T>, org.refcodes.mixin.ChildrenAccessor<Counter<T>[]>, org.refcodes.mixin.Resetable
Direct Known Subclasses:
IdCounterComposite

public abstract class AbstractCounterComposite<T> extends Object implements Counter<T>, org.refcodes.mixin.ChildrenAccessor<Counter<T>[]>
The AbstractCounterComposite combines several Counter instances which to use when generating data by daisy chaining the provided generator instances (end of counter 1 increases counter 2, end of counter 2 increases counter 3, ..., end of counter n-1 increases counter n, the end of a counter is determined with hasNext() and a counter is increased by Generator.next()).
  • Constructor Details

  • Method Details

    • 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
    • reset

      public void reset()
      Specified by:
      reset in interface org.refcodes.mixin.Resetable
    • getChildren

      public Counter<T>[] getChildren()
      Specified by:
      getChildren in interface org.refcodes.mixin.ChildrenAccessor<T>
    • actualCounters

      protected T[] actualCounters()
      Returns the current actual counters' state (an individual value for each counter in the returned array as of the order the counters have been added).
      Returns:
      The current actual counters' state.
    • nextCounters

      protected T[] nextCounters() throws NoSuchElementException
      Returns the Generator.next() value as of the individual underlying AlphabetCounter instances (an individual value for each counter in the returned array as of the order the counters have been added).
      Returns:
      The according array with the counters' individual next values.
      Throws:
      NoSuchElementException - in case no more elements can be generated by the encapsulated counters.