@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 |
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.
|
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.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 |
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 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(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(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 > 0public Range compact() throws InvalidRangeException
InvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic Range compose(Range r) throws InvalidRangeException
r
- range relative to baseInvalidRangeException
- elements must be nonnegative, 0 <= first <= lastpublic boolean contains(int want)
want
- index in the original Rangepublic Range copyWithName(java.lang.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(java.lang.Object o)
equals
in class java.lang.Object
public int first()
public int getFirstInInterval(int start)
start
- starting indexpublic java.lang.String getName()
RangeIterator
getName
in interface RangeIterator
public int hashCode()
hashCode
in class java.lang.Object
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 intersectjava.lang.UnsupportedOperationException
- if both Ranges have stridespublic java.util.Iterator<java.lang.Integer> iterator()
iterator
in interface java.lang.Iterable<java.lang.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 static Range make(java.lang.String name, int len)
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 java.lang.String toString()
toString
in class java.lang.Object
public Range union(Range r) throws InvalidRangeException
r
- range to addInvalidRangeException
- elements must be nonnegative