public class NumberRange extends AbstractList implements Range, 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.
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. |
NumberRange(T from, U to, boolean inclusiveLeft, boolean inclusiveRight) Creates a NumberRange. |
NumberRange(T from, U to, V stepSize, boolean inclusiveLeft, boolean inclusiveRight) Creates a NumberRange. |
Type Params | Return Type | Name and description |
---|---|---|
<T extends Number & Comparable> |
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 . |
|
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 |
|
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. |
|
public boolean |
fastEquals(NumberRange that) Compares a NumberRange to another NumberRange using only a strict comparison of the NumberRange properties. |
|
public Comparable |
get(int index) |
|
public Comparable |
getFrom() |
|
public Comparable |
getStepSize() |
|
public Comparable |
getTo() |
|
public int |
hashCode() A NumberRange's hashCode is based on hashCode values of the discrete items it represents. |
|
public String |
inspect() |
|
public boolean |
isReverse() |
|
public Iterator<Comparable> |
iterator() {@inheritDoc} |
|
public int |
size() |
|
public void |
step(int numSteps, Closure closure) {@inheritDoc} |
|
public List<Comparable> |
step(int numSteps) |
|
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. |
|
public String |
toString() |
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, size, toArray, toArray, contains, addAll, removeAll, retainAll, containsAll, wait, wait, wait, getClass, notify, notifyAll, toArray, stream, spliterator, removeIf, parallelStream, forEach, replaceAll, sort |
Creates an inclusive NumberRange with step size 1.
Creates a reversed range if from
< to
.
from
- the first value in the rangeto
- the last value in the range Creates a new NumberRange with step size 1.
Creates a reversed range if from
< to
.
from
- start of the rangeto
- end of the rangeinclusive
- whether the range is inclusive Creates an inclusive NumberRange.
Creates a reversed range if from
< to
.
from
- start of the rangeto
- end of the rangestepSize
- the gap between discrete elements in the range Creates a NumberRange.
Creates a reversed range if from
< to
.
from
- start of the rangeto
- end of the rangestepSize
- the gap between discrete elements in the rangeinclusive
- whether the range is inclusive (upper bound) Creates a NumberRange.
Creates a reversed range if from
< to
.
from
- start of the rangeto
- end of the rangeinclusiveLeft
- whether the range is includes the lower boundinclusiveRight
- whether the range is includes the upper bound Creates a NumberRange.
Creates a reversed range if from
< to
.
from
- start of the rangeto
- end of the rangestepSize
- the gap between discrete elements in the rangeinclusiveLeft
- whether the range is includes the lower boundinclusiveRight
- whether the range is includes the upper bound 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
.
stepSize
- the desired step sizeiterates over all values and returns true if one value matches. Also see containsWithinBounds.
Checks whether a value is between the from and to values of a Range
value
- the value of interestAn 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.
that
- the object to be compared for equality with this NumberRangetrue
if the specified object is equal to this NumberRangeCompares 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.
that
- the NumberRange to check equality withtrue
if the ranges are equalA NumberRange's hashCode is based on hashCode values of the discrete items it represents.
{@inheritDoc}
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.
size
- the size of the aggregate being indexedCopyright © 2003-2024 The Apache Software Foundation. All rights reserved.