@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?
|
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)
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.
|
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.
|
Iterator<Integer> |
iterator() |
int |
last() |
int |
length()
The number of index in this iterator.
|
static Range |
make(int first,
int last) |
static Range |
make(String name,
int len) |
boolean |
past(Range want)
If this range is completely past the wanted range
|
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 length)
length
- number of elements in the Rangepublic 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 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) throws InvalidRangeException
name
- name of Rangefirst
- first value in rangelast
- last value in range, inclusiveInvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic 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 compact() throws InvalidRangeException
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range compose(Range r) throws InvalidRangeException
r
- range reletive to baseInvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic boolean contains(int want)
want
- index in the original Rangepublic Range copyWithName(String name)
copyWithName
in interface RangeIterator
public Range copyWithStride(int stride) throws InvalidRangeException
InvalidRangeException
public int element(int i) throws InvalidRangeException
i
- index of the elementInvalidRangeException
- i must be: 0 <= i < lengthpublic boolean equals(Object o)
public int first()
public int getFirstInInterval(int start)
start
- starting indexpublic String getName()
RangeIterator
getName
in interface RangeIterator
public int hashCode()
public 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 Iterator<Integer> iterator()
iterator
in interface Iterable<Integer>
iterator
in interface RangeIterator
public int last()
public int length()
RangeIterator
length
in interface RangeIterator
public static Range make(int first, int last)
public 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 int stride()
public Range union(Range r) throws InvalidRangeException
r
- range to addInvalidRangeException
- elements must be nonnegative