Package: groovy.lang

## [Java] Interface Range<T extends Comparable>

- java.lang.Iterable

- All Superinterfaces:
    Collection, Iterable

  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.

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `boolean` | `containsWithinBounds(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.
    `` | `T` | `getFrom()` The lower value in the range.
    `` | `T` | `getTo()` The upper value in the range.
    `` | `String` | `inspect()` @return the verbose 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.
    `` | `List<T>` | `step(int step)` Forms a list by stepping through the range by the indicated interval.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface List` | `add, add, remove, remove, get, equals, hashCode, indexOf, clear, isEmpty, lastIndexOf, contains, replaceAll, size, subList, toArray, toArray, iterator, spliterator, addAll, addAll, set, containsAll, removeAll, retainAll, listIterator, listIterator, sort, stream, removeIf, parallelStream, forEach`
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Method Detail

    - #### public boolean containsWithinBounds(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.

      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:
        `true` if the object is between the from and to values

    - #### public T getFrom()

      The lower value in the range.

      Returns:
        the lower value in the range.

    - #### public T getTo()

      The upper value in the range.

      Returns:
        the upper value in the range

    - #### public String inspect()

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

    - #### 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

    - #### 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

    - #### public 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.