Package: groovy.lang

## [Java] Class ObjectRange

- groovy.lang.ObjectRange

- All Implemented Interfaces and Traits:
    Range

      public class ObjectRange
      extends AbstractList
      implements Range

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

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

- - ### Constructor Summary

    Constructors
    Constructor and description
    `ObjectRange(Comparable from, Comparable to)` Creates a new ObjectRange.
    `ObjectRange(Comparable smaller, Comparable larger, boolean reverse)` Creates a new ObjectRange assumes smaller <= larger, else behavior is undefined.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `checkBoundaryCompatibility()` throws IllegalArgumentException if to and from are incompatible, meaning they e.g.
    `` | `protected int` | `compareTo(Comparable first, Comparable second)` Compares two values using Groovy's number-aware comparison.
    `` | `public boolean` | `contains(Object value)` Iterates over all values and returns true if one value matches.
    `` | `public boolean` | `containsWithinBounds(Object value)` Checks whether a value is between the from and to values of a Range
    `` | `protected Object` | `decrement(Object value)` Decrements by one
    `` | `public boolean` | `equals(Object that)` {@inheritDoc}
    `` | `public boolean` | `equals(ObjectRange that)` Compares an ObjectRange to another ObjectRange.
    `` | `public Comparable` | `get(int index)` {@inheritDoc}
    `` | `public Comparable` | `getFrom()` The lower value in the range. Returns: the lower value in the range.
    `` | `public Comparable` | `getTo()` The upper value in the range. Returns: the upper value in the range
    `` | `protected Object` | `increment(Object value)` Increments by one
    `` | `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 Iterator<Comparable>` | `iterator()` {@inheritDoc}
    `` | `public int` | `size()` {@inheritDoc}
    `` | `public void` | `step(int step, Closure closure)` Steps through the range, calling a closure for each item. Parameters: `step` - the amount by which to step. If negative, steps through the range backwards. `closure` - the Closure to call
    `` | `public List<Comparable>` | `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.
    `` | `public List<Comparable>` | `subList(int fromIndex, int toIndex)` {@inheritDoc}
    `` | `public String` | `toString()` {@inheritDoc}

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public ObjectRange(Comparable from, 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.

    - #### public ObjectRange(Comparable smaller, Comparable larger, boolean reverse)

      Creates a new ObjectRange assumes smaller <= larger, else behavior is undefined. Caution: Prefer the other constructor when in doubt.

      Optimized Constructor avoiding initial computation of comparison.

  - ### Method Detail

    - #### protected void checkBoundaryCompatibility()

      throws IllegalArgumentException if to and from are incompatible, meaning they e.g. (likely) produce infinite sequences. Called at construction time, subclasses may override cautiously (using only members to and from).

    - #### protected int compareTo(Comparable first, Comparable second)

      Compares two values using Groovy's number-aware comparison.

      Parameters:
        `first` - the first value
        `second` - the second value
      Returns:
        the comparison result

    - #### public boolean contains(Object value)

      Iterates over all values and returns true if one value matches.

      See Also:
        containsWithinBounds(Object)

    - #### public boolean containsWithinBounds(Object value)

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

      Parameters:
        `value` - the value of interest
      Returns:
        true if the value is within the bounds

    - #### protected Object decrement(Object value)

      Decrements by one

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

    - #### public boolean equals(Object that)

      {@inheritDoc}

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

    - #### public Comparable get(int index)

      {@inheritDoc}

    - #### public Comparable getFrom()

      The lower value in the range.

      Returns:
        the lower value in the range.

    - #### public Comparable getTo()

      The upper value in the range.

      Returns:
        the upper value in the range

    - #### protected Object increment(Object value)

      Increments by one

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

    - #### 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 Iterator<Comparable> iterator()

      {@inheritDoc}

    - #### public int size()

      {@inheritDoc}

    - #### public void step(int step, Closure closure)

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

      Parameters:
        `step` - the amount by which to step. If negative, steps through the range backwards.
        `closure` - the Closure to call

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

    - #### public List<Comparable> subList(int fromIndex, int toIndex)

      {@inheritDoc}

    - #### public String toString()

      {@inheritDoc}