Package groovy.lang
Class IntRange
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
.- Version:
- $Revision$
- Author:
- James Strachan
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
containsAll
(Collection other) boolean
Indicates whether an object is greater than or equal to thefrom
value for the range and less than or equal to theto
value.boolean
boolean
Determines if this object is equal to another object.get
(int index) getFrom()
The lower value in the range.int
Gets the 'from' value as an integer.getTo()
The upper value in the range.int
getToInt()
Gets the 'to' value as an integer.inspect()
boolean
Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueiterator()
int
size()
step
(int step) Forms a list by stepping through the range by the indicated interval.void
Steps through the range, calling a closure for each number.subList
(int fromIndex, int toIndex) toString()
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set
Methods inherited from class java.util.AbstractCollection
addAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, toArray, toArray
-
Constructor Details
-
IntRange
public IntRange(int from, int to) Creates a newIntRange
. Iffrom
is greater thanto
, a reverse range is created withfrom
andto
swapped.- Parameters:
from
- the first number in the range.to
- the last number in the range.- Throws:
IllegalArgumentException
- if the range would contain more thanInteger.MAX_VALUE
values.
-
IntRange
protected IntRange(int from, int to, boolean reverse) Creates a newIntRange
.- Parameters:
from
- the first value in the range.to
- the last value in the range.reverse
-true
if the range should count fromto
tofrom
.- Throws:
IllegalArgumentException
- iffrom
is greater thanto
.
-
-
Method Details
-
equals
Determines if this object is equal to another object. Delegates toAbstractList.equals(Object)
ifthat
is anything other than anIntRange
. It is not necessary to overridehashCode
, asAbstractList.hashCode()
provides a suitable hash code.DefaultGroovyMethods.equals(List,List)
instead of this method.- Specified by:
equals
in interfaceCollection<Integer>
- Specified by:
equals
in interfaceList<Integer>
- Overrides:
equals
in classAbstractList<Integer>
- Parameters:
that
- the object to compare- Returns:
true
if the objects are equal
-
equals
- Parameters:
that
- the object to compare for equality- Returns:
true
if the ranges are equal
-
getFrom
The lower value in the range. -
getTo
The upper value in the range. -
getFromInt
public int getFromInt()Gets the 'from' value as an integer.- Returns:
- the 'from' value as an integer.
-
getToInt
public int getToInt()Gets the 'to' value as an integer.- Returns:
- the 'to' value as an integer.
-
isReverse
public boolean isReverse()Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value -
containsWithinBounds
Description copied from interface:Range
Indicates whether an object is greater than or equal to thefrom
value for the range and less than or equal to theto
value.- Specified by:
containsWithinBounds
in interfaceRange<Integer>
- Parameters:
o
- the object to check against the boundaries of the range- Returns:
true
if the object is between the from and to values
-
get
-
size
public int size()- Specified by:
size
in interfaceCollection<Integer>
- Specified by:
size
in interfaceList<Integer>
- Specified by:
size
in classAbstractCollection<Integer>
-
iterator
-
subList
-
toString
- Overrides:
toString
in classAbstractCollection<Integer>
-
inspect
-
contains
- Specified by:
contains
in interfaceCollection<Integer>
- Specified by:
contains
in interfaceList<Integer>
- Overrides:
contains
in classAbstractCollection<Integer>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<Integer>
- Specified by:
containsAll
in interfaceList<Integer>
- Overrides:
containsAll
in classAbstractCollection<Integer>
-
step
Steps through the range, calling a closure for each number. -
step
Forms a list by stepping through the range by the indicated interval.
-