Interface RangeIterator

  • All Known Implementing Classes:
    DisposableRangeBoundIterator, DisposableRangeIterator

    public interface RangeIterator
    An interface to declare range iterator.

    A range iterator can be iterated in 2 ways: bottom-up (from lower bound to upper bound)
    and top-down (from upper bound to lower bound).
    To iterate in bottom-up way, first call bottomUpInit(), then hasNext() and next().
    To iterate in bottom-up way, first call topDownInit(), then hasPrevious() and previous().

    Once a way is selected, using the wrong methods can lead to unexpected behaviour.

     RangeIterator rit = ...;
     rit.bottomUpInit();
     while (rit.hasNext()) {
         int from = rit.min();
         int to = rit.max();
         // operate on range [from,to] here
         rit.next();
     }
    OR
     DisposableRangeIterator rit = ...;
     rit.topDownInit();
     while (rit.hasPrevious()) {
         int from = rit.min();
         int to = rit.max();
         // operate on range [from,to] here
         rit.previous();
     }

    Based on
    "Views and Iterators for Generic Constraint Implementations"
    C. Shulte and G. Tack.
    Eleventh International Conference on Principles and Practice of Constraint Programming
    Since:
    05/10/11
    Author:
    Charles Prud'homme
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void bottomUpInit()  
      boolean hasNext()
      Returns true if the iteration has more ranges.
      boolean hasPrevious()
      Returns true if the iteration has more ranges.
      int max()
      Return the upper bound of the current range (inclusive)
      int min()
      Return the lower bound of the current range (inclusive)
      void next()
      Compute the next range.
      void previous()
      Compute the previous range.
      void topDownInit()  
    • Method Detail

      • bottomUpInit

        void bottomUpInit()
      • topDownInit

        void topDownInit()
      • hasNext

        boolean hasNext()
        Returns true if the iteration has more ranges. (In other words, returns true if next would return a valid range.)
        Returns:
        true if the getIterator has more ranges.
      • hasPrevious

        boolean hasPrevious()
        Returns true if the iteration has more ranges. (In other words, returns true if previous would return a valid range.)
        Returns:
        true if the getIterator has more ranges.
      • next

        void next()
        Compute the next range.
      • previous

        void previous()
        Compute the previous range.
      • min

        int min()
        Return the lower bound of the current range (inclusive)
        Returns:
        lower bound of the current range
      • max

        int max()
        Return the upper bound of the current range (inclusive)
        Returns:
        upper bound of the current range