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

public Class IntegerRange

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 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.
Authors
Jan Koehnlein - Initial contribution and API, Karsten Thoms - Bug#381140
Since
2.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final int
private final int
private final int

Constructor Summary

AccessConstructor and Description
public
IntegerRange(int
the start value (inclusive)
start
,
int
the end value (inclusive)
end
)

Constructs a new IntegerRange object.

public
IntegerRange(int
the start value (inclusive)
start
,
int
the end value (inclusive if end-start%step == 0)
end
,
int
the increment
step
)

Constructs a new IntegerRange 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 int

Returns:

the end value
getEnd
()

public int

Returns:

the number of elements in this IntegerRange.
getSize
()

Returns the number of elements in this IntegerRange.

public int

Returns:

the start value
getStart
()

public int

Returns:

the step value
getStep
()

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 IntegerRange

Returns:

a new IntegerRange with the given step.
withStep
(int
the step of the new range.
step
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endback to summary
private final int end
startback to summary
private final int start
stepback to summary
private final int step

Constructor Detail

IntegerRangeback to summary
public IntegerRange(int start, int end)

Constructs a new IntegerRange object. The step will be set to -1 if end<start or to 1 otherwise.

Parameters
start:int

the start value (inclusive)

end:int

the end value (inclusive)

Annotations
@Pure
IntegerRangeback to summary
public IntegerRange(int start, int end, int step)

Constructs a new IntegerRange object.

Parameters
start:int

the start value (inclusive)

end:int

the end value (inclusive if end-start%step == 0)

step:int

the increment

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
getEndback to summary
public int getEnd()
Returns:int

the end value

Annotations
@Pure
getSizeback to summary
public int getSize()

Returns the number of elements in this IntegerRange. That is not the length of the interval, but (end-start)/step + 1.

Returns:int

the number of elements in this IntegerRange.

Annotations
@Pure
getStartback to summary
public int getStart()
Returns:int

the start value

Annotations
@Pure
getStepback to summary
public int getStep()
Returns:int

the step value

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
withStepback to summary
public IntegerRange withStep(int step)
Parameters
step:int

the step of the new range.

Returns:IntegerRange

a new IntegerRange with the given step.

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

private Class IntegerRange.RangeIterator

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

Author
Jan Koehnlein - Initial contribution and API

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