Class IntRange.Builder

java.lang.Object
it.unimi.di.prog2.h15.IntRange.Builder
All Implemented Interfaces:
Iterable<Integer>
Enclosing class:
IntRange

static class IntRange.Builder extends Object implements Iterable<Integer>
Iterable of integers with configurable initial from, to, and step values.
  • Field Details

    • start

      private int start
    • stop

      private int stop
    • step

      private int step
  • Constructor Details

    • Builder

      private Builder()
      Constructs the iterable from 0 to Integer.MAX_VALUE (exclusive) with step 1.
  • Method Details

    • from

      private IntRange.Builder from(int from)
      Returns an instance of this iterable, with the assigned initial value.
      Parameters:
      from - the initial value.
      Returns:
      the iterable.
    • to

      private IntRange.Builder to(int to)
      Returns an instance of this iterable, with the assigned end value.
      Parameters:
      to - the end value.
      Returns:
      the iterable.
    • step

      private IntRange.Builder step(int step)
      Returns an instance of this iterable, with the assigned step.
      Parameters:
      step - the step value.
      Returns:
      the iterable.
      Throws:
      IllegalArgumentException - if the step is 0.
    • iterator

      public Iterator<Integer> iterator()
      Returns the iterator for this iterable.
      Specified by:
      iterator in interface Iterable<Integer>
      Returns:
      the iterator.
      Throws:
      IllegalArgumentException - if the initial value is less than the final, but the step is negative, or conversely if the initial value is greater than the final, but the step is positive.