Class IntegerSequence.Range

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.Integer>
    Enclosing class:
    IntegerSequence

    public static class IntegerSequence.Range
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.Integer>
    Generates a sequence of integers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int max
      Final value.
      private int size
      Number of integers contained in this range.
      private int start
      First value.
      private int step
      Increment.
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(int start, int max, int step)
      Creates a sequence \( a_i, i < 0 <= n \) where \( a_i = start + i * step \) and \( n \) is such that \( a_n <= max \) and \( a_{n+1} > max \).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Iterator<java.lang.Integer> iterator()
      int size()
      Gets the number of elements contained in the range.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • size

        private final int size
        Number of integers contained in this range.
      • start

        private final int start
        First value.
      • max

        private final int max
        Final value.
      • step

        private final int step
        Increment.
    • Constructor Detail

      • Range

        public Range​(int start,
                     int max,
                     int step)
        Creates a sequence \( a_i, i < 0 <= n \) where \( a_i = start + i * step \) and \( n \) is such that \( a_n <= max \) and \( a_{n+1} > max \).
        Parameters:
        start - First value of the range.
        max - Last value of the range that satisfies the above construction rule.
        step - Increment.
    • Method Detail

      • size

        public int size()
        Gets the number of elements contained in the range.
        Returns:
        the size of the range.
      • iterator

        public java.util.Iterator<java.lang.Integer> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Integer>