java.lang.Object
org.eclipse.xtext.xbase.lib.IntegerRange
A sequence of integers starting from
start up to end with an increment of step.
The value of start is always included.
The value of end is included only if the difference between end-start is a multiple of step.
The step can be positive or negative, but never 0. It must have the same signum as of end-start.- Since:
- 2.3
- Author:
- Jan Koehnlein - Initial contribution and API, Karsten Thoms - Bug#381140
-
Constructor Summary
ConstructorsConstructorDescriptionIntegerRange(int start, int end) Constructs a new IntegerRange object.IntegerRange(int start, int end, int step) Constructs a new IntegerRange object. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
IntegerRange
Constructs a new IntegerRange object. The step will be set to -1 if end<start or to 1 otherwise.- Parameters:
start- the start value (inclusive)end- the end value (inclusive)
-
IntegerRange
Constructs a new IntegerRange object.- Parameters:
start- the start value (inclusive)end- the end value (inclusive if end-start%step == 0)step- the increment
-
-
Method Details
-
iterator
- Specified by:
iteratorin interfaceIterable<Integer>- Returns:
- a read-only
ListIteratorfor this.
-
getStart
- Returns:
- the start value
-
getStep
- Returns:
- the step value
-
getEnd
- Returns:
- the end value
-
getSize
Returns the number of elements in this IntegerRange. That is not the length of the interval, but(end-start)/step + 1.- Returns:
- the number of elements in this IntegerRange.
-
withStep
- Parameters:
step- the step of the new range.- Returns:
- a new IntegerRange with the given step.
-
contains
Checks whether this contains the given number, i.e. whether the iterator will yield the number. This is different from interval containment:0..2.by(2)will not contain 1.- Parameters:
number- the number to be checked for containment.- Returns:
- whether this sequence contains the given number or not.
-