Package it.unimi.di.prog2.h15
Class IntRange.Builder
java.lang.Object
it.unimi.di.prog2.h15.IntRange.Builder
- Enclosing class:
- IntRange
Iterable of integers with configurable initial from, to, and step values.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprivate
Builder()
Constructs the iterable from 0 toInteger.MAX_VALUE
(exclusive) with step 1. -
Method Summary
Modifier and TypeMethodDescriptionprivate IntRange.Builder
from
(int from) Returns an instance of this iterable, with the assigned initial value.iterator()
Returns the iterator for this iterable.private IntRange.Builder
step
(int step) Returns an instance of this iterable, with the assigned step.private IntRange.Builder
to
(int to) Returns an instance of this iterable, with the assigned end value.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 Details
-
start
private int start -
stop
private int stop -
step
private int step
-
-
Constructor Details
-
Builder
private Builder()Constructs the iterable from 0 toInteger.MAX_VALUE
(exclusive) with step 1.
-
-
Method Details
-
from
Returns an instance of this iterable, with the assigned initial value.- Parameters:
from
- the initial value.- Returns:
- the iterable.
-
to
Returns an instance of this iterable, with the assigned end value.- Parameters:
to
- the end value.- Returns:
- the iterable.
-
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
Returns the iterator for this iterable.- Specified by:
iterator
in interfaceIterable<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.
-