Package groovy.lang

Class NumberRange

All Implemented Interfaces:
Range<Comparable>, Serializable, Iterable<Comparable>, Collection<Comparable>, List<Comparable>

public class NumberRange
extends AbstractList<Comparable>
implements Range<Comparable>, Serializable
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
See Also:
Serialized Form
  • Constructor Details

    • NumberRange

      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
    • NumberRange

      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
    • NumberRange

      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
    • NumberRange

      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 Details