public class IntRange extends java.util.AbstractList implements Range
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.| Modifier | Constructor and Description |
|---|---|
|
IntRange(int from,
int to)
Creates a new
IntRange. |
protected |
IntRange(int from,
int to,
boolean reverse)
Creates a new
IntRange. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(java.lang.Object value) |
boolean |
containsAll(java.util.Collection other) |
boolean |
containsWithinBounds(java.lang.Object o)
Indicates whether an object is greater than or equal to the
from
value for the range and less than or equal to the to value. |
boolean |
equals(IntRange that)
|
boolean |
equals(java.lang.Object that)
Determines if this object is equal to another object.
|
java.lang.Object |
get(int index) |
java.lang.Comparable |
getFrom()
The lower value in the range.
|
int |
getFromInt()
Gets the 'from' value as an integer.
|
java.lang.Comparable |
getTo()
The upper value in the range.
|
int |
getToInt()
Gets the 'to' value as an integer.
|
java.lang.String |
inspect() |
boolean |
isReverse()
Indicates whether this is a reverse range which iterates backwards
starting from the to value and ending on the from value
|
java.util.Iterator |
iterator() |
int |
size() |
java.util.List |
step(int step)
Forms a list by stepping through the range by the indicated interval.
|
void |
step(int step,
Closure closure)
Steps through the range, calling a closure for each number.
|
java.util.List |
subList(int fromIndex,
int toIndex) |
java.lang.String |
toString() |
add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, setaddAll, isEmpty, remove, removeAll, retainAll, toArray, toArraypublic IntRange(int from,
int to)
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.java.lang.IllegalArgumentException - if the range would contain more than
Integer.MAX_VALUE values.protected IntRange(int from,
int to,
boolean reverse)
IntRange.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.java.lang.IllegalArgumentException - if from is greater than to.public boolean equals(java.lang.Object that)
AbstractList.equals(Object) if that is anthing
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(List,List)
instead of this method.equals in interface java.util.Collectionequals in interface java.util.Listequals in class java.util.AbstractListthat - the object to comparetrue if the objects are equalpublic boolean equals(IntRange that)
that - the object to compare for equalitytrue if the ranges are equalpublic java.lang.Comparable getFrom()
public java.lang.Comparable getTo()
public int getFromInt()
public int getToInt()
public boolean isReverse()
public boolean containsWithinBounds(java.lang.Object o)
Rangefrom
value for the range and less than or equal to the to value.containsWithinBounds in interface Rangeo - the object to check against the boundaries of the rangetrue if the object is between the from and to valuespublic java.lang.Object get(int index)
get in interface java.util.Listget in class java.util.AbstractListpublic int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class java.util.AbstractListpublic java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListsubList in class java.util.AbstractListpublic java.lang.String toString()
toString in class java.util.AbstractCollectionpublic java.lang.String inspect()
public boolean contains(java.lang.Object value)
contains in interface java.util.Collectioncontains in interface java.util.Listcontains in class java.util.AbstractCollectionpublic boolean containsAll(java.util.Collection other)
containsAll in interface java.util.CollectioncontainsAll in interface java.util.ListcontainsAll in class java.util.AbstractCollectionpublic void step(int step,
Closure closure)
public java.util.List step(int step)