|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.ma2.Range
public class Range
Represents a range of integers, used as an index set for arrays.
To extract array sections from arrays, it is necessary to define ranges of indices along axes of arrays. Range objects are used for that purpose.
Ranges are monotonically increasing. Elements must be nonnegative. Ranges can be empty, if last = first - 1.
Note last is inclusive, so standard iteration is
for (int i=range.first(); i<=range.last(); i+= range.stride()) {
}
| Nested Class Summary | |
|---|---|
class |
Range.Iterator
|
| Constructor Summary | |
|---|---|
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(Range base,
Range r)
Create a range by combining two other ranges. |
|
| Method Summary | |
|---|---|
static java.util.List |
appendShape(java.util.List ranges,
int size)
Append a new Range(0,size-1) to the list |
static java.lang.String |
checkInRange(java.util.List section,
int[] shape)
|
static long |
computeSize(java.util.List section)
/** Compute total number of elements represented by the section. |
boolean |
contains(int i)
Is the ith element contained in this Range? |
int |
element(int i)
Return the i-th element of a range. |
protected int |
elementNC(int i)
Return the i-th element of a range, no check |
boolean |
equals(java.lang.Object o)
Range elements with same first, last, stride are equal. |
static java.util.List |
factory(int[] shape)
Convert shape array to List of Ranges. |
static java.util.List |
factory(int[] origin,
int[] shape)
Convert shape, origin array to List of Ranges. |
int |
first()
first in range |
int |
getFirstInInterval(int start)
return the smallest element k in the Range, such that k >= first k >= start k <= last k = first + i * stride for some integer i. |
Range.Iterator |
getIterator()
Iterate over Range index Usage: |
java.lang.String |
getName()
Get name |
static int[] |
getOrigin(java.util.List ranges)
Convert List of Ranges to origin array using the range.first. |
static int[] |
getShape(java.util.List ranges)
Convert List of Ranges to shape array using the range.length. |
int |
hashCode()
Override Object.hashCode() to implement equals. |
int |
last()
last in range, inclusive |
int |
length()
Return the number of elements in the range. |
static java.lang.String |
makeSectionSpec(java.util.List ranges)
Convert List of Ranges to String Spec. |
int |
max()
Maximum index, inclusive. |
int |
min()
Minimum index, inclusive. |
static java.util.List |
parseSpec(java.lang.String sectionSpec)
Parse an index section String specification, return equivilent list of ucar.ma2.Range objects. |
static java.util.List |
setDefaults(java.util.List rangeList,
int[] shape)
Check rangeList has no nulls, set from shape array. |
void |
setName(java.lang.String name)
Set name |
int |
stride()
stride, may be negetive |
static Range[] |
toArray(java.util.List ranges)
Convert List of Ranges to array of Ranges. |
static java.util.List |
toList(Range[] ranges)
Convert array of Ranges to List of Ranges. |
java.lang.String |
toString()
|
static java.lang.String |
toString(java.util.List ranges)
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Range(int first,
int last)
throws InvalidRangeException
first - first value in rangelast - last value in range, inclusive
InvalidRangeException - elements must be nonnegative
public Range(int first,
int last,
int stride)
throws InvalidRangeException
first - first value in rangelast - last value in range, inclusivestride - stride between consecutive elements (positive or negative)
InvalidRangeException - elements must be nonnegative
public Range(Range r)
throws InvalidRangeException
InvalidRangeException
public Range(Range base,
Range r)
throws InvalidRangeException
base - base ranger - range reletive to base
InvalidRangeException - elements must be nonnegative| Method Detail |
|---|
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 objects
public static java.util.List appendShape(java.util.List ranges,
int size)
throws InvalidRangeException
ranges - list of Rangesize - add this Range
InvalidRangeException - 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 optional
java.lang.IllegalArgumentException - when sectionSpec is misformed
InvalidRangeException
public static java.lang.String checkInRange(java.util.List section,
int[] shape)
public java.lang.String getName()
public void setName(java.lang.String name)
public int length()
public int element(int i)
throws InvalidRangeException
i - index of the element
InvalidRangeException - 0 <= i < lengthpublic boolean contains(int i)
i - index in the original Range
protected int elementNC(int i)
i - index of the elementpublic int first()
public int last()
public int stride()
public int min()
public int max()
public 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 Range.Iterator getIterator()
Iterator iter = range.getIterator();
while (iter.hasNext()) {
int index = iter.next();
doSomething(index);
}
public int getFirstInInterval(int start)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||