Package groovy.lang
Interface Range<T extends java.lang.Comparable>
-
- All Superinterfaces:
java.util.Collection<T>
,java.lang.Iterable<T>
,java.util.List<T>
- All Known Implementing Classes:
EmptyRange
,IntRange
,ObjectRange
public interface Range<T extends java.lang.Comparable> extends java.util.List<T>
A Range represents the list of all items obtained by starting from afrom
value and callingnext()
successively until you reach theto
value. For a reverse range, the list is obtained by starting at theto
value and successively callingprevious()
until thefrom
value is reached.- Version:
- $Revision$
- Author:
- James Strachan
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
containsWithinBounds(java.lang.Object o)
Indicates whether an object is greater than or equal to thefrom
value for the range and less than or equal to theto
value.java.lang.Comparable
getFrom()
The lower value in the range.java.lang.Comparable
getTo()
The upper value in the range.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 valuejava.util.List<T>
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.-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
Method Detail
-
getFrom
java.lang.Comparable getFrom()
The lower value in the range.- Returns:
- the lower value in the range.
-
getTo
java.lang.Comparable getTo()
The upper value in the range.- Returns:
- the upper value in the range
-
isReverse
boolean isReverse()
Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value- Returns:
true
if this is a reverse range
-
containsWithinBounds
boolean containsWithinBounds(java.lang.Object o)
Indicates whether an object is greater than or equal to thefrom
value for the range and less than or equal to theto
value.- Parameters:
o
- the object to check against the boundaries of the range- Returns:
true
if the object is between the from and to values
-
step
void step(int step, Closure closure)
Steps through the range, calling a closure for each number.- Parameters:
step
- the amount by which to step. If negative, steps through the range backwards.closure
- theClosure
to call
-
step
java.util.List<T> step(int step)
Forms a list by stepping through the range by the indicated interval.- Parameters:
step
- the amount by which to step. If negative, steps through the range backwards.- Returns:
- the list formed by stepping through the range by the indicated interval.
-
-