Package groovy.lang
Interface Range<T extends Comparable>
- All Superinterfaces:
Collection<T>,Iterable<T>,List<T>,SequencedCollection<T>
- All Known Implementing Classes:
EmptyRange,IntRange,ObjectRange
A Range represents the list of all items obtained by starting from a
from value and calling next() successively
until you reach the to value. For a reverse range,
the list is obtained by starting at the to value and
successively calling previous() until the from
value is reached.- Version:
- $Revision$
- Author:
- James Strachan
-
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.getFrom()The lower value in the range.getTo()The upper value in the range.inspect()booleanIndicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valuestep(int step) Forms a list by stepping through the range by the indicated interval.voidSteps through the range, calling a closure for each number.Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, size, sort, spliterator, subList, toArray, toArray
-
Method Details
-
getFrom
Comparable getFrom()The lower value in the range.- Returns:
- the lower value in the range.
-
getTo
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:
trueif this is a reverse range
-
containsWithinBounds
Indicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.- Parameters:
o- the object to check against the boundaries of the range- Returns:
trueif the object is between the from and to values
-
step
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- theClosureto call
-
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.
-
inspect
String inspect()
-