@Immutable public class Range extends java.lang.Object implements RangeIterator
Elements must be nonnegative and unique. EMPTY is the empty Range. VLEN is for variable length dimensions.
Standard iteration is
for (int idx : range) {
...
}
| Modifier and Type | Field and Description |
|---|---|
static Range |
EMPTY |
static Range |
ONE |
static Range |
VLEN |
| Modifier | 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 values.
|
|
Range(java.lang.String name,
int first,
int last)
Create a named range with unit stride.
|
|
Range(java.lang.String name,
int first,
int last,
int stride)
Create a named range with a specified name and values.
|
protected |
Range(java.lang.String name,
int first,
int last,
int stride,
int length) |
| 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 relative to this Range.
|
boolean |
contains(int want)
Is want contained in this Range?
|
Range |
copyWithName(java.lang.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(java.lang.Object o)
Range elements with same first, last, stride are equal.
|
int |
first() |
int |
getFirstInInterval(int start)
Find the first element in a strided array after some index start.
|
java.util.Iterator<java.lang.Integer> |
getIterator()
Deprecated.
use iterator() or foreach
|
java.lang.String |
getName()
The name of this Range iterator.
|
int |
hashCode()
Override Object.hashCode() to implement equals.
|
int |
index(int want)
Get the index for this element: inverse of element
|
Range |
intersect(Range r)
Create a new Range by intersecting with a Range using same interval as this Range.
|
boolean |
intersects(Range r)
Determine if a given Range intersects this one.
|
java.util.Iterator<java.lang.Integer> |
iterator() |
int |
last() |
int |
length()
The number of index in this iterator.
|
static Range |
make(int first,
int last) |
static Range |
make(java.lang.String name,
int len) |
boolean |
past(Range want)
If this range is completely past the wanted range
|
Range |
setName(java.lang.String name)
Deprecated.
use copyWithName()
|
Range |
setStride(int stride)
Deprecated.
use copyWithStride()
|
Range |
shiftOrigin(int origin)
Create a new Range shifting this range by a constant factor.
|
int |
stride() |
java.lang.String |
toString() |
Range |
union(Range r)
Create a new Range by making the union with a Range using same interval as this Range.
|
public static final Range EMPTY
public static final Range ONE
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(java.lang.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(java.lang.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 > 0protected Range(java.lang.String name,
int first,
int last,
int stride,
int length)
throws InvalidRangeException
InvalidRangeExceptionpublic static Range make(java.lang.String name, int len)
public static Range make(int first, int last)
@Deprecated public Range setStride(int stride) throws InvalidRangeException
InvalidRangeExceptionpublic Range copyWithStride(int stride) throws InvalidRangeException
InvalidRangeException@Deprecated public Range setName(java.lang.String name)
setName in interface RangeIteratorpublic Range copyWithName(java.lang.String name)
copyWithName in interface RangeIteratorpublic java.lang.String getName()
RangeIteratorgetName 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 relative to baseInvalidRangeException - 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 r) throws InvalidRangeException
r - range to intersectInvalidRangeException - elements must be nonnegativepublic boolean intersects(Range r)
r - range to intersectjava.lang.UnsupportedOperationException - if both Ranges have stridespublic boolean past(Range want)
want - desired rangepublic Range shiftOrigin(int origin) throws InvalidRangeException
origin - subtract this from each elementInvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic Range union(Range r) throws InvalidRangeException
r - range to addInvalidRangeException - elements must be nonnegativepublic int getFirstInInterval(int start)
start - starting indexpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.util.Iterator<java.lang.Integer> getIterator()
public java.util.Iterator<java.lang.Integer> iterator()
iterator in interface java.lang.Iterable<java.lang.Integer>iterator in interface RangeIterator