Top Description Inners Fields Constructors Methods
org.eclipse.xtext.xbase.lib

public Class ExclusiveRange

extends Object
implements Iterable<Integer>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Annotations
@GwtCompatible
Imports
java.util.ListIterator, .NoSuchElementException, com.google.common.annotations.GwtCompatible

A sequence of integers starting from 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)
As opposed to 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)...
Author
Jan Koehnlein - Initial contribution and API
Since
2.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private static final ListIterator<Integer>
private final int
private final int
private final int

Constructor Summary

AccessConstructor and Description
public
ExclusiveRange(int
the start value
start
,
int
the end value
end
,
boolean
if true, the range goes from start up to end (exclusive) if false, the range goes from end down to start (exclusive)
increment
)

Constructs a new ExclusiveRange object.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether this sequence contains the given number or not.
contains
(int
the number to be checked for containment.
number
)

Checks whether this contains the given number, i.e. whether the iterator will yield the number.

public boolean

Returns:

true if this range is empty.
isEmpty
()

Returns whether this is range is empty.

public ListIterator<Integer>

Returns:

a read-only ListIterator for this.
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public int

Returns:

the number of elements in this ExclusiveRange.
size
()

Returns the number of elements in this ExclusiveRange.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_LIST_ITERATORback to summary
private static final ListIterator<Integer> EMPTY_LIST_ITERATOR
firstback to summary
private final int first
lastback to summary
private final int last
stepback to summary
private final int step

Constructor Detail

ExclusiveRangeback to summary
public ExclusiveRange(int start, int end, boolean increment)

Constructs a new ExclusiveRange object.

Parameters
start:int

the start value

end:int

the end value

increment:boolean

if true, the range goes from start up to end (exclusive) if false, the range goes from end down to start (exclusive)

Annotations
@Pure

Method Detail

containsback to summary
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:int

the number to be checked for containment.

Returns:boolean

whether this sequence contains the given number or not.

Annotations
@Pure
isEmptyback to summary
public boolean isEmpty()

Returns whether this is range is empty.

Returns:boolean

true if this range is empty.

Annotations
@Pure
iteratorback to summary
public ListIterator<Integer> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:ListIterator<Integer>

a read-only ListIterator for this.

Annotations
@Override
@Pure
sizeback to summary
public int size()

Returns the number of elements in this ExclusiveRange.

Returns:int

the number of elements in this ExclusiveRange.

Annotations
@Pure
org.eclipse.xtext.xbase.lib back to summary

private Class ExclusiveRange.RangeIterator

extends Object
implements ListIterator<Integer>
Class Inheritance
All Implemented Interfaces
java.util.ListIterator, java.util.Iterator

Field Summary

Modifier and TypeField and Description
private int
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
add(Integer e)

Implements java.util.ListIterator.add.

Inserts the specified element into the list (optional operation).

public boolean
hasNext()

Implements java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction.

public boolean
hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction.

public Integer
next()

Implements java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position.

public int
nextIndex()

Implements java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next.

public Integer
previous()

Implements java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards.

public int
previousIndex()

Implements java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous.

public void
remove()

Implements java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation).

public void
set(Integer e)

Implements java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextback to summary
private int next
nextIndexback to summary
private int nextIndex

Constructor Detail

RangeIteratorback to summary
private RangeIterator()

Method Detail

addback to summary
public void add(Integer e)

Implements java.util.ListIterator.add.

Doc from java.util.ListIterator.add.

Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Annotations
@Override
hasNextback to summary
public boolean hasNext()

Implements java.util.ListIterator.hasNext.

Doc from java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.)

Annotations
@Override
hasPreviousback to summary
public boolean hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Doc from java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Annotations
@Override
nextback to summary
public Integer next()

Implements java.util.ListIterator.next.

Doc from java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Annotations
@Override
nextIndexback to summary
public int nextIndex()

Implements java.util.ListIterator.nextIndex.

Doc from java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.)

Annotations
@Override
previousback to summary
public Integer previous()

Implements java.util.ListIterator.previous.

Doc from java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Annotations
@Override
previousIndexback to summary
public int previousIndex()

Implements java.util.ListIterator.previousIndex.

Doc from java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.)

Annotations
@Override
removeback to summary
public void remove()

Implements java.util.ListIterator.remove.

Doc from java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if add has not been called after the last call to next or previous.

Annotations
@Override
setback to summary
public void set(Integer e)

Implements java.util.ListIterator.set.

Doc from java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation). This call can be made only if neither remove nor add have been called after the last call to next or previous.

Annotations
@Override