Package groovy.lang
Interface Range<T extends Comparable>
-
- All Superinterfaces:
Collection<T>,Iterable<T>,List<T>
- All Known Implementing Classes:
EmptyRange,IntRange,ObjectRange
public interface Range<T extends Comparable> extends List<T>
A Range represents the list of all items obtained by starting from afromvalue and callingnext()successively until you reach thetovalue. For a reverse range, the list is obtained by starting at thetovalue and successively callingprevious()until thefromvalue is reached.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancontainsWithinBounds(Object o)Indicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.TgetFrom()The lower value in the range.TgetTo()The upper value in the range.Stringinspect()booleanisReverse()Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from valueList<T>step(int step)Forms a list by stepping through the range by the indicated interval.voidstep(int step, Closure closure)Steps through the range, calling a closure for each number.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
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
T getFrom()
The lower value in the range.- Returns:
- the lower value in the range.
-
getTo
T 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
boolean containsWithinBounds(Object o)
Indicates whether an object is greater than or equal to thefromvalue for the range and less than or equal to thetovalue.This may be true even for values not contained in the range.
Example: from = 1.5 , to = 3, next() increments by 1 containsWithinBounds(2) == true contains(2) == false
- Parameters:
o- the object to check against the boundaries of the range- Returns:
trueif 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- theClosureto call
-
step
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.
-
-