public class NumberRange extends AbstractList<Comparable> implements Range<Comparable>
modCount| 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. |
| Modifier and Type | Method and Description |
|---|---|
<T extends Number & Comparable> |
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()
The lower value in the range.
|
Comparable |
getStepSize() |
Comparable |
getTo()
The upper value in the range.
|
int |
hashCode()
A NumberRange's hashCode is based on hashCode values of the discrete items it represents.
|
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
|
Iterator<Comparable> |
iterator() |
int |
size() |
List<Comparable> |
step(int numSteps)
Forms a list by stepping through the range by the indicated interval.
|
void |
step(int numSteps,
Closure closure)
Steps through the range, calling a closure for each item.
|
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() |
add, add, addAll, clear, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, setaddAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, add, addAll, addAll, clear, containsAll, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, sort, spliterator, toArray, toArrayparallelStream, removeIf, streampublic NumberRange(T from,
U to)
from - the first value in the rangeto - the last value in the rangepublic NumberRange(T from,
U to,
boolean inclusive)
from - start of the rangeto - end of the rangeinclusive - whether the range is inclusivepublic NumberRange(T from,
U to,
V stepSize)
from - start of the rangeto - end of the rangestepSize - the gap between discrete elements in the rangepublic NumberRange(T from,
U to,
V stepSize,
boolean inclusive)
from - start of the rangeto - end of the rangestepSize - the gap between discrete elements in the rangeinclusive - whether the range is inclusivepublic RangeInfo subListBorders(int size)
size - the size of the aggregate being indexedpublic <T extends Number & Comparable> NumberRange by(T stepSize)
from and to as this NumberRange
but with a step size of stepSize.stepSize - the desired step sizepublic boolean equals(Object that)
equals in interface Collection<Comparable>equals in interface List<Comparable>equals in class AbstractList<Comparable>that - the object to be compared for equality with this NumberRangetrue if the specified object is equal to this NumberRangefastEquals(NumberRange)public int hashCode()
hashCode in interface Collection<Comparable>hashCode in interface List<Comparable>hashCode in class AbstractList<Comparable>public boolean fastEquals(NumberRange that)
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 equalpublic Comparable getFrom()
RangegetFrom in interface Range<Comparable>public Comparable getTo()
RangegetTo in interface Range<Comparable>public Comparable getStepSize()
public boolean isReverse()
RangeisReverse in interface Range<Comparable>true if this is a reverse rangepublic Comparable get(int index)
get in interface List<Comparable>get in class AbstractList<Comparable>public boolean containsWithinBounds(Object value)
containsWithinBounds in interface Range<Comparable>value - the value of interestpublic int size()
size in interface Collection<Comparable>size in interface List<Comparable>size in class AbstractCollection<Comparable>public List<Comparable> subList(int fromIndex, int toIndex)
subList in interface List<Comparable>subList in class AbstractList<Comparable>public String toString()
toString in class AbstractCollection<Comparable>public String inspect()
public boolean contains(Object value)
contains in interface Collection<Comparable>contains in interface List<Comparable>contains in class AbstractCollection<Comparable>public void step(int numSteps,
Closure closure)
step in interface Range<Comparable>numSteps - the amount by which to step. If negative, steps through the range backwards.closure - the Closure to callpublic Iterator<Comparable> iterator()
iterator in interface Iterable<Comparable>iterator in interface Collection<Comparable>iterator in interface List<Comparable>iterator in class AbstractList<Comparable>public List<Comparable> step(int numSteps)
Rangestep in interface Range<Comparable>numSteps - the amount by which to step. If negative, steps through the range backwards.