public class RangeBuilder
extends java.lang.Object
implements java.lang.Iterable<java.lang.Integer>
| Constructor and Description |
|---|
RangeBuilder()
Creates a new
RangeBuilder with 'from', 'to', and 'step' value of 0. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Iterable<java.lang.Integer> |
build()
Builds the range, whose
Iterator will generate Integer
values as set by calls to RangeBuilder's methods. |
boolean |
equals(java.lang.Object o) |
RangeBuilder |
from(int start)
Sets the beginning of the range to be built.
|
int |
hashCode() |
java.util.PrimitiveIterator.OfInt |
iterator()
Returns an
Iterator for a range built using the current values set
for this RangeBuilder. |
RangeBuilder |
reverse()
Reverses the range to be built, so that its
Iterator will iterate from the given 'to'
value, to the given 'from' value. |
RangeBuilder |
step(int step)
Sets the 'step' of the range to be built.
|
RangeBuilder |
to(int end)
Sets the end of the range to be built.
|
java.lang.String |
toString() |
RangeBuilder |
until(int end)
Sets the end of the half-closed range to be built.
|
public RangeBuilder()
RangeBuilder with 'from', 'to', and 'step' value of 0.public RangeBuilder from(int start)
start - The beginning of the range to be built, and the first Integer to
be returned by the built range's Iterator.RangeBuilder object on which this method was called.public RangeBuilder to(int end)
end - The end of the range. This value may or may not be returned by the built
range's Iterator (depending on the chosen 'step' value), but it
is guaranteed to never go beyond this value.RangeBuilder object on which this method was called.public RangeBuilder until(int end)
Iterator.end - The end of the range. This value will not be returned by the built
range's Iterator.RangeBuilder object on which this method was called.public RangeBuilder step(int step)
step need not be negative, and a negative or positive
step will have no impact on the function of the range, either way.step - The value by which the value returned by the Iterable's Iterator
will change upon each successive call to next().RangeBuilder object on which this method was called.public RangeBuilder reverse()
Iterator will iterate from the given 'to'
value, to the given 'from' value.RangeBuilder object on which this method was called.reverse() will cancel each other out, so calling
rangeBuilder.reverse().reverse() will be the same as never calling it,
and calling rangeBuilder.reverse().reverse().reverse() will be the same
as only calling it once, and so on.public java.lang.Iterable<java.lang.Integer> build()
Iterator will generate Integer
values as set by calls to RangeBuilder's methods.
Be aware that there is no functionality in place to ensure that the 'step' value is not
0, and, if it is, the built range's Iterator might iterate indefinitely.Iterable<Integer>, whose Iterator will generate Integer
values as set by calls to RangeBuilder's methods.public java.util.PrimitiveIterator.OfInt iterator()
Iterator for a range built using the current values set
for this RangeBuilder.iterator in interface java.lang.Iterable<java.lang.Integer>Iterator for a range built using the current values set
for this RangeBuilder.build().iterator() on this
RangeBuilder, and is included for convenience, when storing the built
range is not important.
Be aware that there is no functionality in place to ensure that the 'step' value is not
0, and, if it is, the built range's Iterator might iterate indefinitely.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object