jparfor
Class Range

java.lang.Object
  extended by jparfor.Range
All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>

public class Range
extends java.lang.Object
implements java.lang.Iterable<java.lang.Integer>

Implement an iterable range that is computed lazily. The range will start at the start value (inclusive) and end at the end value (exclusive) doing increments of step size each time towards the end. A for loop as for (int i = 5; i < 22; i += 3) can now be replaced by for (int i : new Range(5, 22, 3))


Nested Class Summary
 class Range.RangeIterator
          Iterator object for the range object.
 
Constructor Summary
Range(int end)
          Create an iterable range object with the following properties (start = 0, step = 1).
Range(int start, int end)
          Create an iterable range object with the following properties (step = 1).
Range(int start, int end, int step)
          Create an iterable range object with the following properties.
 
Method Summary
 int getEnd()
          Return the end of the range object.
 int getStart()
          Return the start of the range object.
 int getStep()
          Return the step of the rage object.
 java.util.Iterator<java.lang.Integer> iterator()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Range

public Range(int start,
             int end,
             int step)
Create an iterable range object with the following properties.

Parameters:
start - start value (inclusive).
end - end value (exclusive).
step - size of the increment between values (> 0).

Range

public Range(int start,
             int end)
Create an iterable range object with the following properties (step = 1).

Parameters:
start - start value (inclusive).
end - end value (exclusive).

Range

public Range(int end)
Create an iterable range object with the following properties (start = 0, step = 1).

Parameters:
end - end value (exclusive).
Method Detail

getStart

public int getStart()
Return the start of the range object.

Returns:
the start of the range object.

getEnd

public int getEnd()
Return the end of the range object.

Returns:
the end of the range object.

getStep

public int getStep()
Return the step of the rage object.

Returns:
the step of the rage object.

iterator

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