Package org.eclipse.xtext.xbase.lib
Class ExclusiveRange
- java.lang.Object
-
- org.eclipse.xtext.xbase.lib.ExclusiveRange
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>
@GwtCompatible public class ExclusiveRange extends java.lang.Object implements java.lang.Iterable<java.lang.Integer>
A sequence of integers starting fromstart
toend
counting up or down. It excludes theend
value when counting up and thestart
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
-
-
Constructor Summary
Constructors Constructor Description ExclusiveRange(int start, int end, boolean increment)
Constructs a new ExclusiveRange object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(int number)
Checks whether this contains the given number, i.e.boolean
isEmpty()
Returns whether this is range is empty.java.util.ListIterator<java.lang.Integer>
iterator()
int
size()
Returns the number of elements in this ExclusiveRange.
-
-
-
Constructor Detail
-
ExclusiveRange
@Pure public ExclusiveRange(int start, int end, boolean increment)
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 Detail
-
iterator
@Pure public java.util.ListIterator<java.lang.Integer> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Integer>
- Returns:
- a read-only
ListIterator
for this.
-
size
@Pure public int size()
Returns the number of elements in this ExclusiveRange.- Returns:
- the number of elements in this ExclusiveRange.
-
isEmpty
@Pure public boolean isEmpty()
Returns whether this is range is empty.- Returns:
- true if this range is empty.
-
contains
@Pure public boolean contains(int number)
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.
-
-