类 Range
- java.lang.Object
-
- org.meteoinfo.ndarray.Range
-
@Immutable public final class Range extends java.lang.ObjectRepresents a set of integers, used as an index for arrays. It should be considered as a subset of the interval of integers [0, length-1] inclusive. For example Range(1:11:3) represents the set of integers {1,4,7,10} Immutable. Ranges are monotonically increasing. Elements must be nonnegative. EMPTY is the empty Range. VLEN is for variable length dimensions.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(); ... }- 作者:
- caron
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 classRange.Iterator
-
构造器概要
构造器 构造器 说明 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(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 nameRange(Range r)Copy Constructor
-
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static java.util.ListappendShape(java.util.List ranges, int size)已过时。use Section.appendRange(int size)static java.lang.StringcheckInRange(java.util.List section, int[] shape)已过时。use Section.checkInRange(int shape[])Rangecompact()Create a new Range by compacting this Range by removing the stride.Rangecompose(Range r)Create a new Range by composing a Range that is reletive to this Range.static longcomputeSize(java.util.List section)已过时。use Section.computeSize()booleancontains(int i)Is the ith element contained in this Range?intelement(int i)Get ith elementintelementNC(int i)Get ith element; skip checking, for speed.booleanequals(java.lang.Object o)Range elements with same first, last, stride are equal.static java.util.Listfactory(int[] shape)已过时。use Section(int[] shape)static java.util.Listfactory(int[] origin, int[] shape)已过时。use Section(int[] origin, int[] shape)intfirst()intgetFirstInInterval(int start)Find the first element in a strided array after some index start.Range.IteratorgetIterator()Iterate over Range index Usage:java.lang.StringgetName()Get namestatic int[]getOrigin(java.util.List ranges)已过时。use Section.getOrigin()static int[]getShape(java.util.List ranges)已过时。use Section.getShape()inthashCode()Override Object.hashCode() to implement equals.intindex(int elem)Get the index for this element: inverse of elementRangeintersect(Range r)Create a new Range by intersecting with a Range using same interval as this Range.booleanintersects(Range r)Determine if a given Range intersects this one.intlast()intlength()Get the number of elements in the range.static java.lang.StringmakeSectionSpec(java.util.List ranges)已过时。use Section.toString()intmax()已过时。use last()intmin()已过时。use first()static java.util.ListparseSpec(java.lang.String sectionSpec)已过时。use new Section(String sectionSpec)booleanpast(Range want)If this range is completely past the wanted rangestatic java.util.ListsetDefaults(java.util.List rangeList, int[] shape)已过时。use Section.setDefaults(int[] shape)RangeshiftOrigin(int origin)Create a new Range shifting this range by a constant factor.intstride()static Range[]toArray(java.util.List ranges)已过时。use Section.getRanges()static java.util.ListtoList(Range[] ranges)已过时。use Section.getRanges()java.lang.StringtoString()static java.lang.StringtoString(java.util.List ranges)已过时。use Section.toString()Rangeunion(Range r)Create a new Range by making the union with a Range using same interval as this Range.
-
-
-
构造器详细资料
-
Range
public Range(int first, int last) throws InvalidRangeExceptionCreate a range with unit stride.- 参数:
first- first value in rangelast- last value in range, inclusive- 抛出:
InvalidRangeException- elements must be nonnegative, 0 <= first <= last
-
Range
public Range(int length)
Create a range starting at zero, with unit stride.- 参数:
length- number of elements in the Rnage
-
Range
public Range(java.lang.String name, int first, int last) throws InvalidRangeExceptionCreate a named range with unit stride.- 参数:
name- name of Rangefirst- first value in rangelast- last value in range, inclusive- 抛出:
InvalidRangeException- elements must be nonnegative, 0 <= first <= last
-
Range
public Range(int first, int last, int stride) throws InvalidRangeExceptionCreate a range with a specified stride.- 参数:
first- first value in rangelast- last value in range, inclusivestride- stride between consecutive elements, must be > 0- 抛出:
InvalidRangeException- elements must be nonnegative: 0 <= first <= last, stride > 0
-
Range
public Range(java.lang.String name, int first, int last, int stride) throws InvalidRangeExceptionCreate a named range with a specified stride.- 参数:
name- name of Rangefirst- first value in rangelast- last value in range, inclusivestride- stride between consecutive elements, must be > 0- 抛出:
InvalidRangeException- elements must be nonnegative: 0 <= first <= last, stride > 0
-
Range
public Range(Range r)
Copy Constructor- 参数:
r- copy from here
-
Range
public Range(java.lang.String name, Range r)Copy Constructor with name- 参数:
name- result namer- copy from here
-
-
方法详细资料
-
compose
public Range compose(Range r) throws InvalidRangeException
Create a new Range by composing a Range that is reletive to this Range. Revised 2013/04/19 by Dennis Heimbigner to handle edge cases. See the commentary associated with the netcdf-c file dceconstraints.h, function dceslicecompose().- 参数:
r- range reletive to base- 返回:
- combined Range, may be EMPTY
- 抛出:
InvalidRangeException- elements must be nonnegative, 0 <= first <= last
-
compact
public Range compact() throws InvalidRangeException
Create a new Range by compacting this Range by removing the stride. first = first/stride, last=last/stride, stride=1.- 返回:
- compacted Range
- 抛出:
InvalidRangeException- elements must be nonnegative, 0 <= first <= last
-
shiftOrigin
public Range shiftOrigin(int origin) throws InvalidRangeException
Create a new Range shifting this range by a constant factor.- 参数:
origin- subtract this from first, last- 返回:
- shiften range
- 抛出:
InvalidRangeException- elements must be nonnegative, 0 <= first <= last
-
intersect
public Range intersect(Range r) throws InvalidRangeException
Create a new Range by intersecting with a Range using same interval as this Range. NOTE: we dont yet support intersection when both Ranges have strides- 参数:
r- range to intersect- 返回:
- intersected Range, may be EMPTY
- 抛出:
InvalidRangeException- elements must be nonnegative
-
intersects
public boolean intersects(Range r)
Determine if a given Range intersects this one. NOTE: we dont yet support intersection when both Ranges have strides- 参数:
r- range to intersect- 返回:
- true if they intersect
- 抛出:
java.lang.UnsupportedOperationException- if both Ranges have strides
-
past
public boolean past(Range want)
If this range is completely past the wanted range- 参数:
want- desired range- 返回:
- true if first() > want.last()
-
union
public Range union(Range r) throws InvalidRangeException
Create a new Range by making the union with a Range using same interval as this Range. NOTE: no strides- 参数:
r- range to add- 返回:
- intersected Range, may be EMPTY
- 抛出:
InvalidRangeException- elements must be nonnegative
-
length
public int length()
Get the number of elements in the range.- 返回:
- the number of elements in the range.
-
element
public int element(int i) throws InvalidRangeExceptionGet ith element- 参数:
i- index of the element- 返回:
- the i-th element of a range.
- 抛出:
InvalidRangeException- i must be: 0 <= i < length
-
index
public int index(int elem) throws InvalidRangeExceptionGet the index for this element: inverse of element- 参数:
elem- the element of the range- 返回:
- index
- 抛出:
InvalidRangeException- if illegal elem
-
contains
public boolean contains(int i)
Is the ith element contained in this Range?- 参数:
i- index in the original Range- 返回:
- true if the ith element would be returned by the Range iterator
-
elementNC
public int elementNC(int i)
Get ith element; skip checking, for speed.- 参数:
i- index of the element- 返回:
- the i-th element of a range, no check
-
first
public int first()
- 返回:
- first in range
-
last
public int last()
- 返回:
- last in range, inclusive
-
stride
public int stride()
- 返回:
- stride, must be >= 1
-
getName
public java.lang.String getName()
Get name- 返回:
- name, or null if none
-
getIterator
public Range.Iterator getIterator()
Iterate over Range index Usage:Iterator iter = range.getIterator(); while (iter.hasNext()) { int index = iter.next(); doSomething(index); }- 返回:
- Iterator over element indices
-
getFirstInInterval
public int getFirstInInterval(int start)
Find the first element in a strided array after some index 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.
- 参数:
start- starting index- 返回:
- first in interval, else -1 if there is no such element.
-
toString
public java.lang.String toString()
- 覆盖:
toString在类中java.lang.Object
-
equals
public boolean equals(java.lang.Object o)
Range elements with same first, last, stride are equal.- 覆盖:
equals在类中java.lang.Object
-
hashCode
public int hashCode()
Override Object.hashCode() to implement equals.- 覆盖:
hashCode在类中java.lang.Object
-
min
public int min()
已过时。use first()- 返回:
- Minimum index, inclusive.
-
max
public int max()
已过时。use last()- 返回:
- Maximum index, inclusive.
-
factory
public static java.util.List factory(int[] shape)
已过时。use Section(int[] shape)Convert shape array to List of Ranges. Assume 0 origin for all.
-
setDefaults
public static java.util.List setDefaults(java.util.List rangeList, int[] shape)已过时。use Section.setDefaults(int[] shape)Check rangeList has no nulls, set from shape array.
-
factory
public static java.util.List factory(int[] origin, int[] shape) throws InvalidRangeException已过时。use Section(int[] origin, int[] shape)Convert shape, origin array to List of Ranges.
-
getShape
public static int[] getShape(java.util.List ranges)
已过时。use Section.getShape()Convert List of Ranges to shape array using the range.length.
-
toString
public static java.lang.String toString(java.util.List ranges)
已过时。use Section.toString()
-
computeSize
public static long computeSize(java.util.List section)
已过时。use Section.computeSize()/** Compute total number of elements represented by the section.- 参数:
section- List of Range objects- 返回:
- total number of elements
-
appendShape
public static java.util.List appendShape(java.util.List ranges, int size) throws InvalidRangeException已过时。use Section.appendRange(int size)Append a new Range(0,size-1) to the list- 参数:
ranges- list of Rangesize- add this Range- 返回:
- same list
- 抛出:
InvalidRangeException- if size < 1
-
getOrigin
public static int[] getOrigin(java.util.List ranges)
已过时。use Section.getOrigin()Convert List of Ranges to origin array using the range.first.
-
toArray
public static Range[] toArray(java.util.List ranges)
已过时。use Section.getRanges()Convert List of Ranges to array of Ranges. *
-
toList
public static java.util.List toList(Range[] ranges)
已过时。use Section.getRanges()Convert array of Ranges to List of Ranges.
-
makeSectionSpec
public static java.lang.String makeSectionSpec(java.util.List ranges)
已过时。use Section.toString()Convert List of Ranges to String Spec. Inverse of parseSpec
-
parseSpec
public static java.util.List parseSpec(java.lang.String sectionSpec) throws InvalidRangeException已过时。use new Section(String sectionSpec)Parse an index section String specification, return equivilent list of ucar.ma2.Range objects. The sectionSpec string uses fortran90 array section syntax, namely: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- 返回:
- return List of ucar.ma2.Range objects corresponding to the index selection. A null Range means "all" (i.e.":") indices in that dimension.
- 抛出:
java.lang.IllegalArgumentException- when sectionSpec is misformedInvalidRangeException
-
checkInRange
public static java.lang.String checkInRange(java.util.List section, int[] shape)已过时。use Section.checkInRange(int shape[])Check ranges are valid- 参数:
section-shape-- 返回:
- error message, or null if all ok
-
-