@Immutable public class Range extends 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 |
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(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 and values.
|
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?
|
int |
element(int i)
Get ith element
|
boolean |
equals(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.
|
Iterator<Integer> |
getIterator()
Deprecated.
use iterator() or foreach
|
String |
getName() |
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.
|
Iterator<Integer> |
iterator() |
int |
last() |
int |
length() |
static Range |
make(String name,
int len) |
boolean |
past(Range want)
If this range is completely past the wanted range
|
Range |
setName(String name) |
Range |
setStride(int stride) |
Range |
shiftOrigin(int origin)
Create a new Range shifting this range by a constant factor.
|
int |
stride() |
String |
toString() |
Range |
union(Range r)
Create a new Range by making the union with a Range using same interval as this Range.
|
forEach, spliterator
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(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 Range setStride(int stride) throws InvalidRangeException
InvalidRangeException
public Range setName(String name)
setName
in interface RangeIterator
public String getName()
getName
in interface RangeIterator
public int first()
public int last()
public int length()
length
in interface RangeIterator
public int stride()
public boolean contains(int want)
want
- index in the original Rangepublic Range compose(Range r) throws InvalidRangeException
r
- range reletive 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 intersectUnsupportedOperationException
- 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 boolean equals(Object o)
public int hashCode()
public Iterator<Integer> getIterator()