Class IntRange
- All Implemented Interfaces:
Range<Integer>, Iterable<Integer>, Collection<Integer>, List<Integer>, SequencedCollection<Integer>
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 AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancontainsAll(Collection other) booleanIndicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.booleanbooleanDetermines if this object is equal to another object.get(int index) getFrom()The lower value in the range.intGets the 'from' value as an integer.getTo()The upper value in the range.intgetToInt()Gets the 'to' value as an integer.inspect()booleanIndicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueiterator()intsize()step(int step) Forms a list by stepping through the range by the indicated interval.voidSteps through the range, calling a closure for each number.subList(int fromIndex, int toIndex) toString()Methods inherited from class AbstractList
add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, setMethods inherited from class AbstractCollection
addAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
add, add, addAll, addAll, addFirst, addLast, clear, getFirst, getLast, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, sort, spliterator, toArray, toArray
-
Constructor Details
-
IntRange
public IntRange(int from, int to) Creates a newIntRange. Iffromis greater thanto, a reverse range is created withfromandtoswapped.- 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_VALUEvalues.
-
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-trueif the range should count fromtotofrom.- Throws:
IllegalArgumentException- iffromis greater thanto.
-
-
Method Details
-
equals
Determines if this object is equal to another object. Delegates toAbstractList.equals(Object)ifthatis anything other than anIntRange. It is not necessary to overridehashCode, asAbstractList.hashCode()provides a suitable hash code.
Note that equals is generally handled byDefaultGroovyMethods.equals(List,List)instead of this method.- Specified by:
equalsin interfaceCollection<Integer>- Specified by:
equalsin interfaceList<Integer>- Overrides:
equalsin classAbstractList<Integer>- Parameters:
that- the object to compare- Returns:
trueif the objects are equal
-
equals
-
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
-
containsWithinBounds
Description copied from interface:RangeIndicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.- Specified by:
containsWithinBoundsin interfaceRange<Integer>- Parameters:
o- the object to check against the boundaries of the range- Returns:
trueif the object is between the from and to values
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<Integer>- Specified by:
sizein interfaceList<Integer>- Specified by:
sizein classAbstractCollection<Integer>
-
iterator
-
subList
-
toString
- Overrides:
toStringin classAbstractCollection<Integer>
-
inspect
-
contains
- Specified by:
containsin interfaceCollection<Integer>- Specified by:
containsin interfaceList<Integer>- Overrides:
containsin classAbstractCollection<Integer>
-
containsAll
- Specified by:
containsAllin interfaceCollection<Integer>- Specified by:
containsAllin interfaceList<Integer>- Overrides:
containsAllin classAbstractCollection<Integer>
-
step
-
step
Forms a list by stepping through the range by the indicated interval.
-