groovy.lang

## Class ObjectRange

- java.lang.Object
- - java.util.AbstractCollection<E>
  - - java.util.AbstractList
    - - groovy.lang.ObjectRange

All Implemented Interfaces:
  Range, java.lang.Iterable, java.util.Collection, java.util.List

    public class ObjectRange
    extends java.util.AbstractList
    implements Range

Represents an inclusive list of objects from a value to a value using comparators.

This class is similar to `IntRange`. If you make any changes to this class, you might consider making parallel changes to `IntRange`.

### Field Summary

### Fields inherited from class java.util.AbstractList

`modCount`

### Constructor Summary

Constructors
Constructor and Description
`ObjectRange(java.lang.Comparable from, java.lang.Comparable to)` Creates a new `ObjectRange`.
`ObjectRange(java.lang.Comparable from, java.lang.Comparable to, boolean reverse)`

### Method Summary

Methods
`boolean` `contains(java.lang.Object value)`
`boolean` `containsWithinBounds(java.lang.Object value)` Checks whether a value is between the from and to values of a Range
`protected java.lang.Object` `decrement(java.lang.Object value)` Decrements by one
`boolean` `equals(java.lang.Object that)`
`boolean` `equals(ObjectRange that)` Compares an `ObjectRange` to another `ObjectRange`.
`java.lang.Object` `get(int index)`
`java.lang.Comparable` `getFrom()` The lower value in the range.
`java.lang.Comparable` `getTo()` The upper value in the range.
`protected java.lang.Object` `increment(java.lang.Object value)` Increments by one
`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 value
`java.util.Iterator` `iterator()`
`int` `size()`
`java.util.List` `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.
`java.util.List` `subList(int fromIndex, int toIndex)`
`java.lang.String` `toString()`

### Methods inherited from class java.util.AbstractList

`add, add, addAll, clear, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set`

### Methods inherited from class java.util.AbstractCollection

`addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.List

`add, add, addAll, addAll, clear, containsAll, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, toArray, toArray`

### Constructor Detail

#### ObjectRange

    public ObjectRange(java.lang.Comparable from,
               java.lang.Comparable to)

Creates a new `ObjectRange`. Creates a reversed range if `from` < `to`.

Parameters:
  `from` - the first value in the range.
  `to` - the last value in the range.

#### ObjectRange

    public ObjectRange(java.lang.Comparable from,
               java.lang.Comparable to,
               boolean reverse)

### Method Detail

#### equals

    public boolean equals(java.lang.Object that)

Specified by:
  `equals` in interface `java.util.Collection`
Specified by:
  `equals` in interface `java.util.List`
Overrides:
  `equals` in class `java.util.AbstractList`

#### equals

    public boolean equals(ObjectRange that)

Compares an `ObjectRange` to another `ObjectRange`.

Parameters:
  `that` - the object to check equality with
Returns:
  `true` if the ranges are equal

#### getFrom

    public java.lang.Comparable getFrom()

The lower value in the range.

Specified by:
  `getFrom` in interface `Range`
Returns:
  the lower value in the range.

#### getTo

    public java.lang.Comparable getTo()

The upper value in the range.

Specified by:
  `getTo` in interface `Range`
Returns:
  the upper value in the range

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

Specified by:
  `isReverse` in interface `Range`
Returns:
  `true` if this is a reverse range

#### get

    public java.lang.Object get(int index)

Specified by:
  `get` in interface `java.util.List`
Specified by:
  `get` in class `java.util.AbstractList`

#### iterator

    public java.util.Iterator iterator()

Specified by:
  `iterator` in interface `java.lang.Iterable`
Specified by:
  `iterator` in interface `java.util.Collection`
Specified by:
  `iterator` in interface `java.util.List`
Overrides:
  `iterator` in class `java.util.AbstractList`

#### containsWithinBounds

    public boolean containsWithinBounds(java.lang.Object value)

Checks whether a value is between the from and to values of a Range

Specified by:
  `containsWithinBounds` in interface `Range`
Parameters:
  `value` - the value of interest
Returns:
  true if the value is within the bounds

#### size

    public int size()

Specified by:
  `size` in interface `java.util.Collection`
Specified by:
  `size` in interface `java.util.List`
Specified by:
  `size` in class `java.util.AbstractCollection`

#### subList

    public java.util.List subList(int fromIndex,
                         int toIndex)

Specified by:
  `subList` in interface `java.util.List`
Overrides:
  `subList` in class `java.util.AbstractList`

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.util.AbstractCollection`

#### inspect

    public java.lang.String inspect()

Specified by:
  `inspect` in interface `Range`
Returns:
  the verbose `String` representation of this `Range` as would be typed into a console to create the `Range` instance

#### contains

    public boolean contains(java.lang.Object value)

Specified by:
  `contains` in interface `java.util.Collection`
Specified by:
  `contains` in interface `java.util.List`
Overrides:
  `contains` in class `java.util.AbstractCollection`

#### step

    public void step(int step,
            Closure closure)

Steps through the range, calling a closure for each number.

Specified by:
  `step` in interface `Range`
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.

Specified by:
  `step` in interface `Range`
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.

#### increment

    protected java.lang.Object increment(java.lang.Object value)

Increments by one

Parameters:
  `value` - the value to increment
Returns:
  the incremented value

#### decrement

    protected java.lang.Object decrement(java.lang.Object value)

Decrements by one

Parameters:
  `value` - the value to decrement
Returns:
  the decremented value