Package: groovy.lang

## [Java] Class NumberRange

- groovy.lang.NumberRange

- All Implemented Interfaces and Traits:
    Range, Serializable

      public class NumberRange
      extends AbstractList

  Represents an immutable list of Numbers from a value to a value with a particular step size. In general, it isn't recommended using a NumberRange as a key to a map. The range 0..3 is deemed to be equal to 0.0..3.0 but they have different hashCode values, so storing a value using one of these ranges couldn't be retrieved using the other.

  Since:
    2.5.0

- - ### Constructor Summary

    Constructors
    Constructor and description
    `NumberRange (T from, U to)` Creates an inclusive NumberRange with step size 1.
    `NumberRange (T from, U to, boolean inclusive)` Creates a new NumberRange with step size 1.
    `NumberRange (T from, U to, V stepSize)` Creates an inclusive NumberRange.
    `NumberRange (T from, U to, V stepSize, boolean inclusive)` Creates a NumberRange.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `NumberRange` | `by(T stepSize)` For a NumberRange with step size 1, creates a new NumberRange with the same `from` and `to` as this NumberRange but with a step size of `stepSize`.
    `` | `boolean` | `contains(Object value)` iterates over all values and returns true if one value matches.
    `` | `boolean` | `containsWithinBounds(Object value)` Checks whether a value is between the from and to values of a Range
    `` | `boolean` | `equals(Object that)` An object is deemed equal to this NumberRange if it represents a List of items and those items equal the list of discrete items represented by this NumberRange.
    `` | `boolean` | `fastEquals(NumberRange that)` Compares a NumberRange to another NumberRange using only a strict comparison of the NumberRange properties.
    `` | `Comparable` | `get(int index)`
    `` | `Comparable` | `getFrom()`
    `` | `Comparable` | `getStepSize()`
    `` | `Comparable` | `getTo()`
    `` | `int` | `hashCode()` A NumberRange's hashCode is based on hashCode values of the discrete items it represents.
    `` | `String` | `inspect()`
    `` | `boolean` | `isReverse()`
    `` | `Iterator<Comparable>` | `iterator()` {@inheritDoc}
    `` | `int` | `size()`
    `` | `void` | `step(int numSteps, Closure closure)` {@inheritDoc}
    `` | `List<Comparable>` | `step(int numSteps)`
    `` | `List<Comparable>` | `subList(int fromIndex, int toIndex)`
    `` | `RangeInfo` | `subListBorders(int size)` A method for determining from and to information when using this IntRange to index an aggregate object of the specified size.
    `` | `String` | `toString()`

  - ### Inherited Methods Summary

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

- - ### Constructor Detail

    - #### public NumberRange(T from, U to)

      Creates an inclusive NumberRange with step size 1. Creates a reversed range if `from` < `to`.

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

    - #### public NumberRange(T from, U to, boolean inclusive)

      Creates a new NumberRange with step size 1. Creates a reversed range if `from` < `to`.

      Parameters:
        `from` - start of the range
        `to` - end of the range
        `inclusive` - whether the range is inclusive

    - #### public NumberRange(T from, U to, V stepSize)

      Creates an inclusive NumberRange. Creates a reversed range if `from` < `to`.

      Parameters:
        `from` - start of the range
        `to` - end of the range
        `stepSize` - the gap between discrete elements in the range

    - #### public NumberRange(T from, U to, V stepSize, boolean inclusive)

      Creates a NumberRange. Creates a reversed range if `from` < `to`.

      Parameters:
        `from` - start of the range
        `to` - end of the range
        `stepSize` - the gap between discrete elements in the range
        `inclusive` - whether the range is inclusive

  - ### Method Detail

    - #### public NumberRange by(T stepSize)

      For a NumberRange with step size 1, creates a new NumberRange with the same `from` and `to` as this NumberRange but with a step size of `stepSize`.

      Parameters:
        `stepSize` - the desired step size
      Returns:
        a new NumberRange

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public boolean contains(Object value)

      iterates over all values and returns true if one value matches. Also see containsWithinBounds.

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride 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

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public boolean equals(Object that)

      An object is deemed equal to this NumberRange if it represents a List of items and those items equal the list of discrete items represented by this NumberRange.

      Parameters:
        `that` - the object to be compared for equality with this NumberRange
      Returns:
        `true` if the specified object is equal to this NumberRange
      See Also:
        fastEquals(NumberRange)

    - #### public boolean fastEquals(NumberRange that)

      Compares a NumberRange to another NumberRange using only a strict comparison of the NumberRange properties. This won't return true for some ranges which represent the same discrete items, use equals instead for that but will be much faster for large lists.

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

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public Comparable get(int index)

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public Comparable getFrom()

    - #### public Comparable getStepSize()

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public Comparable getTo()

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public int hashCode()

      A NumberRange's hashCode is based on hashCode values of the discrete items it represents.

      Returns:
        the hashCode value

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public String inspect()

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public boolean isReverse()

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public Iterator<Comparable> iterator()

      {@inheritDoc}

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public int size()

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public void step(int numSteps, Closure closure)

      {@inheritDoc}

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public List<Comparable> step(int numSteps)

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public List<Comparable> subList(int fromIndex, int toIndex)

    - #### public RangeInfo subListBorders(int size)

      A method for determining from and to information when using this IntRange to index an aggregate object of the specified size. Normally only used internally within Groovy but useful if adding range indexing support for your own aggregates.

      Parameters:
        `size` - the size of the aggregate being indexed
      Returns:
        the calculated range information (with 1 added to the to value, ready for providing to subList

    - #### @com.github.javaparser.ast.expr.MarkerAnnotationExprOverride public String toString()