public final class Range extends 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 |
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(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 stride.
|
Range(String name,
Range r)
Copy Constructor with name
|
Modifier and Type | Method and Description |
---|---|
static List |
appendShape(List ranges,
int size)
Deprecated.
use Section.appendRange(int size)
|
static String |
checkInRange(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(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(Object o)
Range elements with same first, last, stride are equal.
|
static List |
factory(int[] shape)
Deprecated.
use Section(int[] shape)
|
static 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:
|
String |
getName()
Get name
|
static int[] |
getOrigin(List ranges)
Deprecated.
use Section.getOrigin()
|
static int[] |
getShape(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 String |
makeSectionSpec(List ranges)
Deprecated.
use Section.toString()
|
int |
max()
Deprecated.
use last()
|
int |
min()
Deprecated.
use first()
|
static List |
parseSpec(String sectionSpec)
Deprecated.
use new Section(String sectionSpec)
|
boolean |
past(Range want)
If this range is completely past the wanted range
|
static List |
setDefaults(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(List ranges)
Deprecated.
use Section.getRanges()
|
static List |
toList(Range[] ranges)
Deprecated.
use Section.getRanges()
|
String |
toString() |
static String |
toString(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 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(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(Range r)
r
- 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 intersectUnsupportedOperationException
- 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 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 boolean equals(Object o)
public int hashCode()
public int min()
public int max()
public static List factory(int[] shape)
public static List setDefaults(List rangeList, int[] shape)
public static List factory(int[] origin, int[] shape) throws InvalidRangeException
InvalidRangeException
public static int[] getShape(List ranges)
public static long computeSize(List section)
section
- List of Range objectspublic static List appendShape(List ranges, int size) throws InvalidRangeException
ranges
- list of Rangesize
- add this RangeInvalidRangeException
- if size < 1public static int[] getOrigin(List ranges)
public static Range[] toArray(List ranges)
public static List toList(Range[] ranges)
public static String makeSectionSpec(List ranges)
public static List parseSpec(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 optionalIllegalArgumentException
- when sectionSpec is misformedInvalidRangeException
Copyright © 1999–2013 UCAR/Unidata. All rights reserved.