@Immutable
public final class Range
extends java.lang.Object
Note last is inclusive, so standard iteration is
for (int i=range.first(); i<=range.last(); i+= range.stride()) {
...
}
or use:
Range.Iterator iter = timeRange.getIterator();
while (iter.hasNext()) {
int index = iter.next();
...
}
| Modifier and Type | Class and Description |
|---|---|
class |
Range.Iterator |
| 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 stride.
|
Range(Range r)
Copy Constructor
|
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 stride.
|
Range(java.lang.String name,
Range r)
Copy Constructor with name
|
| Modifier and Type | Method and Description |
|---|---|
static java.util.List |
appendShape(java.util.List ranges,
int size)
Deprecated.
use Section.appendRange(int size)
|
static java.lang.String |
checkInRange(java.util.List section,
int[] shape)
Deprecated.
use Section.checkInRange(int shape[])
|
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.
|
static long |
computeSize(java.util.List section)
Deprecated.
use Section.computeSize()
|
boolean |
contains(int i)
Is the ith element contained in this Range?
|
int |
element(int i)
Get ith element
|
boolean |
equals(java.lang.Object o)
Range elements with same first, last, stride are equal.
|
static java.util.List |
factory(int[] shape)
Deprecated.
use Section(int[] shape)
|
static java.util.List |
factory(int[] origin,
int[] shape)
Deprecated.
use Section(int[] origin, int[] shape)
|
int |
first() |
int |
getFirstInInterval(int start)
Find the first element in a strided array after some index start.
|
Range.Iterator |
getIterator()
Iterate over Range index
Usage:
|
java.lang.String |
getName()
Get name
|
static int[] |
getOrigin(java.util.List ranges)
Deprecated.
use Section.getOrigin()
|
static int[] |
getShape(java.util.List ranges)
Deprecated.
use Section.getShape()
|
int |
hashCode()
Override Object.hashCode() to implement equals.
|
int |
index(int elem)
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.
|
int |
last() |
int |
length()
Get the number of elements in the range.
|
static java.lang.String |
makeSectionSpec(java.util.List ranges)
Deprecated.
use Section.toString()
|
int |
max()
Deprecated.
use last()
|
int |
min()
Deprecated.
use first()
|
static java.util.List |
parseSpec(java.lang.String sectionSpec)
Deprecated.
use new Section(String sectionSpec)
|
boolean |
past(Range want)
If this range is completely past the wanted range
|
static java.util.List |
setDefaults(java.util.List rangeList,
int[] shape)
Deprecated.
use Section.setDefaults(int[] shape)
|
Range |
shiftOrigin(int origin)
Create a new Range shifting this range by a constant factor.
|
int |
stride() |
static Range[] |
toArray(java.util.List ranges)
Deprecated.
use Section.getRanges()
|
static java.util.List |
toList(Range[] ranges)
Deprecated.
use Section.getRanges()
|
java.lang.String |
toString() |
static java.lang.String |
toString(java.util.List ranges)
Deprecated.
use Section.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 Rnagepublic 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 > 0public Range(Range r)
r - copy from herepublic Range(java.lang.String name,
Range r)
name - result namer - copy from herepublic 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 Range shiftOrigin(int origin) throws InvalidRangeException
origin - subtract this from first, lastInvalidRangeException - elements must be nonnegative, 0 <= first <= lastpublic 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 union(Range r) throws InvalidRangeException
r - range to addInvalidRangeException - elements must be nonnegativepublic int length()
public int element(int i)
throws InvalidRangeException
i - index of the elementInvalidRangeException - i must be: 0 <= i < lengthpublic int index(int elem)
throws InvalidRangeException
elem - the element of the rangeInvalidRangeException - if illegal elempublic boolean contains(int i)
i - index in the original Rangepublic int first()
public int last()
public int stride()
public java.lang.String getName()
public Range.Iterator getIterator()
Iterator iter = range.getIterator();
while (iter.hasNext()) {
int index = iter.next();
doSomething(index);
}
public 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 int min()
public int max()
public static java.util.List factory(int[] shape)
public static java.util.List setDefaults(java.util.List rangeList,
int[] shape)
public static java.util.List factory(int[] origin,
int[] shape)
throws InvalidRangeException
InvalidRangeExceptionpublic static int[] getShape(java.util.List ranges)
public static java.lang.String toString(java.util.List ranges)
public static long computeSize(java.util.List section)
section - List of Range objectspublic static java.util.List appendShape(java.util.List ranges,
int size)
throws InvalidRangeException
ranges - list of Rangesize - add this RangeInvalidRangeException - if size < 1public static int[] getOrigin(java.util.List ranges)
public static Range[] toArray(java.util.List ranges)
public static java.util.List toList(Range[] ranges)
public static java.lang.String makeSectionSpec(java.util.List ranges)
public static java.util.List parseSpec(java.lang.String sectionSpec)
throws InvalidRangeException
sectionSpec := dims dims := dim | dim, dims dim := ':' | slice | start ':' end | start ':' end ':' stride slice := INTEGER start := INTEGER stride := INTEGER end := INTEGER where nonterminals are in lower case, terminals are in upper case, literals are in single quotes. Meaning of index selector : ':' = all slice = hold index to that value start:end = all indices from start to end inclusive start:end:stride = all indices from start to end inclusive with given stride
sectionSpec - the token to parse, eg "(1:20,:,3,10:20:2)", parenthesis optionaljava.lang.IllegalArgumentException - when sectionSpec is misformedInvalidRangeExceptionpublic static java.lang.String checkInRange(java.util.List section,
int[] shape)
section - shape -