@Immutable public class Range extends Object implements RangeIterator
Elements must be nonnegative and unique. EMPTY is the empty Range. SCALAR is the set {0}. VLEN is for variable length dimensions.
Standard iteration is
for (int idx : range) {
...
}
| Modifier and Type | Field and Description |
|---|---|
static Range |
EMPTY |
static Range |
SCALAR |
static Range |
VLEN |
| Constructor and Description |
|---|
Range(int length)
Create a range starting at zero, with unit stride.
|
Range(int first,
int last)
Create a range with unit stride.
|
Range(int first,
int last,
int stride)
Create a range with a specified first, last, stride.
|
Range(String name,
int first,
int last)
Create a named range with unit stride.
|
Range(String name,
int first,
int last,
int stride)
Create a named range with a specified name, first, last, stride.
|
| Modifier and Type | Method and Description |
|---|---|
Range |
compact()
Create a new Range by compacting this Range by removing the stride.
|
Range |
compose(Range r)
Create a new Range by composing a Range that is reletive to this Range.
|
boolean |
contains(int want)
Is want contained in this Range?
|
Range |
copyWithName(String name)
Make a copy with a different name.
|
Range |
copyWithStride(int stride)
Make a copy with a different stride.
|
int |
element(int i)
Get ith element
|
boolean |
equals(Object o)
Does not include the name.
|
int |
first() |
int |
getFirstInInterval(int start)
Find the first element in a strided array after some index start.
|
int |
hashCode() |
int |
index(int want)
Given an element in the Range, find its index in the array of elements.
|
Range |
intersect(Range other)
Create a new Range by intersecting with another Range that must have stride 1.
|
boolean |
intersects(Range other)
Determine if a given Range interval intersects this one.
|
Iterator<Integer> |
iterator() |
int |
last() |
int |
length()
The number of elements in this iterator.
|
static Range |
make(int first,
int last)
Make an unnamed Range from first to last.
|
static Range |
make(String name,
int len)
Make a named Range from 0 to len-1.
|
String |
name()
The name of this Range iterator.
|
int |
stride() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static final Range EMPTY
public static final Range SCALAR
public static final Range VLEN
public Range(int first,
int last)
throws InvalidRangeException
first - first value in rangelast - last value in range, inclusiveInvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic Range(int length)
length - number of elements in the Rangepublic Range(String name, int first, int last) throws InvalidRangeException
name - name of Rangefirst - first value in rangelast - last value in range, inclusiveInvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic Range(int first,
int last,
int stride)
throws InvalidRangeException
first - first value in rangelast - last value in range, inclusivestride - stride between consecutive elements, must be > 0InvalidRangeException - elements must be nonnegative: 0 <= first <= last, stride > 0public Range(String name, int first, int last, int stride) throws InvalidRangeException
name - name of Rangefirst - first value in rangelast - last value in range, inclusivestride - stride between consecutive elements, must be > 0InvalidRangeException - elements must be nonnegative: 0 <= first <= last, stride > 0public static Range make(int first, int last)
public Range copyWithStride(int stride) throws InvalidRangeException
InvalidRangeExceptionpublic Range copyWithName(String name)
copyWithName in interface RangeIterator@Nullable public String name()
RangeIteratorname in interface RangeIteratorpublic int first()
public int last()
public int length()
RangeIteratorlength in interface RangeIteratorpublic int stride()
public boolean contains(int want)
want - index in the original Rangepublic Range compose(Range r) throws InvalidRangeException
r - range elements are reletive to thisInvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic Range compact() throws InvalidRangeException
InvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic int element(int i)
throws InvalidRangeException
i - index of the elementInvalidRangeException - i must be: 0 <= i < lengthpublic int index(int want)
throws InvalidRangeException
want - the element of the rangeInvalidRangeException - if illegal elempublic Range intersect(Range other) throws InvalidRangeException
other - range to intersect, must have stride 1.InvalidRangeException - elements must be nonnegativepublic boolean intersects(Range other)
other - range to intersectpublic int getFirstInInterval(int start)
start - starting index