java.lang.Object
org.eclipse.xtext.xbase.lib.ExclusiveRange
A sequence of integers starting from
As opposed to
start to end counting up or down.
It excludes the end value when counting up and the start value when counting down.
Examples:
new ExclusiveRange(1, 5, true) | (1,2,3,4) |
new ExclusiveRange(0, 0, true) | () |
new ExclusiveRange(0, -1, true) | () |
new ExclusiveRange(-1, 0, true) | (-1) |
new ExclusiveRange(5, 1, false) | (4,3,2,1) |
new ExclusiveRange(0, 0, false) | () |
new ExclusiveRange(-1, 0, false) | () |
new ExclusiveRange(0, -1, false) | (-1) |
IntegerRange this class meets the requirements to iterate arrays or lists without
the need for further guards, e.g.
for(i: new ExclusiveRange(0, list.size, true))
list.get(i)...
for(i: new ExclusiveRange(array.length, 0, false))
array.get(i)...
for(i: new ExclusiveRange(0, string.indexOf('x'), true)
string.charAt(i)...
- Since:
- 2.4
- Author:
- Jan Koehnlein - Initial contribution and API
-
Constructor Summary
ConstructorsConstructorDescriptionExclusiveRange(int start, int end, boolean increment) Constructs a new ExclusiveRange 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
-
ExclusiveRange
Constructs a new ExclusiveRange object.- Parameters:
start- the start valueend- the end valueincrement- if true, the range goes from start up to end (exclusive) if false, the range goes from end down to start (exclusive)
-
-
Method Details
-
iterator
- Specified by:
iteratorin interfaceIterable<Integer>- Returns:
- a read-only
ListIteratorfor this.
-
size
Returns the number of elements in this ExclusiveRange.- Returns:
- the number of elements in this ExclusiveRange.
-
isEmpty
Returns whether this is range is empty.- Returns:
- true if this range is empty.
-
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.
-