public class NumberRange extends java.util.AbstractList<java.lang.Comparable> implements Range<java.lang.Comparable>
| 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 java.lang.Number & java.lang.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(java.lang.Object value)
iterates over all values and returns true if one value matches.
|
boolean |
containsWithinBounds(java.lang.Object value)
Checks whether a value is between the from and to values of a Range
|
boolean |
equals(java.lang.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. |
java.lang.Comparable |
get(int index) |
java.lang.Comparable |
getFrom()
The lower value in the range.
|
java.lang.Comparable |
getStepSize() |
java.lang.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.
|
java.lang.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
|
java.util.Iterator<java.lang.Comparable> |
iterator() |
int |
size() |
java.util.List<java.lang.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.
|
java.util.List<java.lang.Comparable> |
subList(int fromIndex,
int toIndex) |
java.lang.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, waitpublic 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 <T extends java.lang.Number & java.lang.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(java.lang.Object that)
equals in interface java.util.Collection<java.lang.Comparable>equals in interface java.util.List<java.lang.Comparable>equals in class java.util.AbstractList<java.lang.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 java.util.Collection<java.lang.Comparable>hashCode in interface java.util.List<java.lang.Comparable>hashCode in class java.util.AbstractList<java.lang.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 java.lang.Comparable getFrom()
Rangepublic java.lang.Comparable getTo()
Rangepublic java.lang.Comparable getStepSize()
public boolean isReverse()
Rangepublic java.lang.Comparable get(int index)
get in interface java.util.List<java.lang.Comparable>get in class java.util.AbstractList<java.lang.Comparable>public boolean containsWithinBounds(java.lang.Object value)
containsWithinBounds in interface Range<java.lang.Comparable>value - the value of interestpublic int size()
size in interface java.util.Collection<java.lang.Comparable>size in interface java.util.List<java.lang.Comparable>size in class java.util.AbstractCollection<java.lang.Comparable>public java.util.List<java.lang.Comparable> subList(int fromIndex,
int toIndex)
subList in interface java.util.List<java.lang.Comparable>subList in class java.util.AbstractList<java.lang.Comparable>public java.lang.String toString()
toString in class java.util.AbstractCollection<java.lang.Comparable>public java.lang.String inspect()
public boolean contains(java.lang.Object value)
contains in interface java.util.Collection<java.lang.Comparable>contains in interface java.util.List<java.lang.Comparable>contains in class java.util.AbstractCollection<java.lang.Comparable>public void step(int numSteps,
Closure closure)
public java.util.Iterator<java.lang.Comparable> iterator()
iterator in interface java.lang.Iterable<java.lang.Comparable>iterator in interface java.util.Collection<java.lang.Comparable>iterator in interface java.util.List<java.lang.Comparable>iterator in class java.util.AbstractList<java.lang.Comparable>public java.util.List<java.lang.Comparable> step(int numSteps)
Range