Groovy Documentation

## groovy.lang
[Java] Interface Range

    java.lang.Iterable
      groovy.lang.Range
          java.util.Collection

All Superinterfaces:
  java.lang.Iterable, java.util.Collection

    public interface Range
    extends java.util.List

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.

Authors:
  James Strachan

Version:
  \$Revision\$

Method Summary
`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.
`java.lang.Comparable` | `getFrom()` The lower value in the range.
`java.lang.Comparable` | `getTo()` The upper value in the range.
`java.lang.String` | `inspect()` @return the verbose java.lang.String representation of this Range as would be typed into a console to create the Range instance
`boolean` | `isReverse()` Indicates whether this is a reverse range which iterates backwards starting from the to value and ending on the from value
`void` | `step(int step, Closure closure)` Steps through the range, calling a closure for each number.
`java.util.List` | `step(int step)` Forms a list by stepping through the range by the indicated interval.

Methods inherited from interface java.util.List

java.util.List#add(java.lang.Object), java.util.List#add(int, java.lang.Object), java.util.List#get(int), java.util.List#equals(java.lang.Object), java.util.List#hashCode(), java.util.List#indexOf(java.lang.Object), java.util.List#clear(), java.util.List#size(), java.util.List#isEmpty(), java.util.List#lastIndexOf(java.lang.Object), java.util.List#contains(java.lang.Object), java.util.List#subList(int, int), java.util.List#toArray(), java.util.List#toArray([Ljava.lang.Object;), java.util.List#remove(java.lang.Object), java.util.List#remove(int), java.util.List#addAll(java.util.Collection), java.util.List#addAll(int, java.util.Collection), java.util.List#iterator(), java.util.List#set(int, java.lang.Object), java.util.List#containsAll(java.util.Collection), java.util.List#removeAll(java.util.Collection), java.util.List#retainAll(java.util.Collection), java.util.List#listIterator(), java.util.List#listIterator(int)

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Method Detail

### containsWithinBounds

    public 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.
  Parameters:
    `o` - the object to check against the boundaries of the range
  Returns:
    `true` if the object is between the from and to values

### getFrom

    public java.lang.Comparable getFrom()

  The lower value in the range.
  Returns:
    the lower value in the range.

### getTo

    public java.lang.Comparable getTo()

  The upper value in the range.
  Returns:
    the upper value in the range

### inspect

    public java.lang.String inspect()

  Returns:
    the verbose java.lang.String representation of this Range as would be typed into a console to create the Range instance

### isReverse

    public 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

### step

    public 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` - the Closure to call

### step

    public java.util.List 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.

Groovy Documentation