|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList
groovy.lang.IntRange
public 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.
| Nested Class Summary | |
|---|---|
private class |
IntRange.IntRangeIterator
Iterates through each number in an IntRange. |
| Field Summary | |
|---|---|
private int |
from
The first number in the range. |
private boolean |
reverse
If false, counts up from from to to. |
private int |
to
The last number in the range. |
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
|
IntRange(int from,
int to)
Creates a new IntRange. |
protected |
IntRange(int from,
int to,
boolean reverse)
Creates a new IntRange. |
| Method Summary | |
|---|---|
boolean |
contains(java.lang.Object value)
|
boolean |
containsAll(java.util.Collection other)
|
boolean |
containsWithinBounds(java.lang.Object o)
Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value |
boolean |
equals(IntRange that)
Compares an IntRange to another IntRange. |
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()
Gets the lower value in the range. |
int |
getFromInt()
Gets the 'from' value as an integer. |
java.lang.Comparable |
getTo()
Gets the lower 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()
|
| 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.List |
|---|
add, add, addAll, addAll, clear, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, toArray, toArray |
| Field Detail |
|---|
private int from
from is always less than or equal to to.
private int to
to is always greater than or eqaul to from.
private boolean reverse
false, counts up from from to to. Otherwise, counts down
from to to from.
| Constructor Detail |
|---|
public 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.| Method Detail |
|---|
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 compare
true if the objects are equalpublic boolean equals(IntRange that)
IntRange to another IntRange.
that - the object to compare for equality
true if the ranges are equalpublic java.lang.Comparable getFrom()
getFrom in interface Rangepublic java.lang.Comparable getTo()
getTo in interface Rangepublic int getFromInt()
public int getToInt()
public boolean isReverse()
isReverse in interface Rangetrue if this is a reverse rangepublic boolean containsWithinBounds(java.lang.Object o)
Range
containsWithinBounds in interface Rangeo - the object to check against the boundaries of the range
true 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.AbstractList
public 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()
inspect in interface RangeString representation of this Range as would be typed into a console
to create the Range instancepublic 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.AbstractCollection
public void step(int step,
Closure closure)
step in interface Rangestep - the amount by which to step. If negative, steps through the
range backwards.closure - the Closure to callpublic java.util.List step(int step)
step in interface Rangestep - the amount by which to step. If negative, steps through the
range backwards.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||