public class IntRange extends AbstractList
Represents a list of Integer objects from a specified int up (or down) to and including a given to.
This class is a copy of ObjectRange optimized for int
. If you make any
changes to this class, you might consider making parallel changes to ObjectRange.
Instances of this class may be either inclusive aware or non-inclusive aware. See the
relevant constructors for creating each type. Inclusive aware IntRange instances are
suitable for use with Groovy's range indexing - in particular if the from or to values
might be negative. This normally happens underneath the covers but is worth keeping
in mind if creating these ranges yourself explicitly.
Type Params | Return Type | Name and description |
---|---|---|
|
def |
IntRange(int from, int to) Creates a new non-inclusive IntRange . |
|
protected def |
IntRange(int from, int to, boolean reverse) Creates a new non-inclusive aware IntRange . |
|
def |
IntRange(boolean inclusive, int from, int to) Creates a new inclusive aware IntRange . |
|
boolean |
contains(Object value) |
|
boolean |
containsAll(Collection other) |
|
boolean |
containsWithinBounds(Object o) |
|
boolean |
equals(Object that) Determines if this object is equal to another object. |
|
boolean |
equals(IntRange that) Compares an IntRange to another IntRange. |
|
Integer |
get(int index) |
|
Integer |
getFrom() |
|
int |
getFromInt() Gets the 'from' value as a primitive integer. |
|
Boolean |
getInclusive() Returns the inclusive flag. |
|
Integer |
getTo() |
|
int |
getToInt() Gets the 'to' value as a primitive integer. |
|
int |
hashCode() |
|
String |
inspect() |
|
boolean |
isReverse() |
|
Iterator<Integer> |
iterator() |
|
int |
size() |
|
void |
step(int step, Closure closure) |
|
List<Integer> |
step(int step) |
|
List<Integer> |
subList(int fromIndex, int toIndex) |
|
RangeInfo |
subListBorders(int size) A method for determining from and to information when using this IntRange to index an aggregate object of the specified size. |
|
String |
toString() |
Methods inherited from class | Name |
---|---|
class AbstractList |
add, add, remove, get, equals, hashCode, indexOf, clear, iterator, lastIndexOf, subList, addAll, set, listIterator, listIterator, remove, toString, contains, isEmpty, size, toArray, toArray, addAll, containsAll, removeAll, retainAll, wait, wait, wait, getClass, notify, notifyAll, stream, removeIf, parallelStream, forEach, replaceAll, size, spliterator, sort |
class AbstractCollection |
add, remove, toString, clear, contains, isEmpty, iterator, size, toArray, toArray, addAll, containsAll, removeAll, retainAll, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll, spliterator, stream, removeIf, parallelStream, forEach |
Creates a new non-inclusive IntRange
. If from
is greater than
to
, a reverse range is created with from
and to
swapped.
from
- the first number in the range.to
- the last number in the range. Creates a new non-inclusive aware IntRange
.
from
is greater than to
.from
- the first value in the range.to
- the last value in the range.reverse
- true
if the range should count from
to
to from
. Creates a new inclusive aware IntRange
.
from
- the first value in the range.to
- the last value in the range.inclusive
- true
if the to value is included in the range. Determines if this object is equal to another object. Delegates to
AbstractList.equals if that
is anything
other than an IntRange.
It is not necessary to override hashCode
, as
AbstractList.hashCode provides a suitable hash code.
Note that equals is generally handled by DefaultGroovyMethods.equals instead of this method.
true
if the objects are equalthat
- the object to compareCompares an IntRange to another IntRange.
true
if the ranges are equalthat
- the object to compare for equalityGets the 'from' value as a primitive integer.
Returns the inclusive flag. Null for non-inclusive aware ranges or non-null for inclusive aware ranges.
Gets the 'to' value as a primitive integer.
A method for determining from and to information when using this IntRange to index an aggregate object of the specified size. Normally only used internally within Groovy but useful if adding range indexing support for your own aggregates.
size
- the size of the aggregate being indexed