## org.das2.datum.DatumRange

A DatumRange is provided as a means to carry an ordered pair of Datums representing an interval. This sort of data structure comes up often in processing, and it's useful to define once and get the operators implemented correctly. Consider using this object whenever you see pairs of Datums in interfaces and codes (e.g. tbegin,tend), they are probably a DatumRange!

## DatumRange( Datum s1, Datum s2 )

Creates valid DatumRange from two Datums.

## DatumRange( double s1, double s2, Units units )

create a datum range from two doubles in the context of units.

## compareTo

compareTo( Object o ) → int

Compare this to another DatumRange, ordered by the lesser datum, then the greater datum. This is mostly provided for .equals, but also so there is a consistent ordering convention though out the system.

### Parameters

o - the DatumRange to compare this DatumRange to.

### Returns:

an int < 0 if this comes before DatumRange a in this DatumRange's units space, 0 if they are equal, and > 0 otherwise.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## contains

contains( DatumRange dr ) → boolean

returns true of param dr is contained by this, so that this.union(dr).equals(this).

### Parameters

dr - the datum range to test.

### Returns:

true iff this.union(dr).equals(this);
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## contains

contains( Datum d ) → boolean

returns true if the Datum is in the range, inclusive of the lesser point but exclusive of the greater point.

### Parameters

d - the datum

### Returns:

true if d is in the range, exclusive of max.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## convertTo

convertTo( Units u ) → DatumRange

return this DatumRange in new units. Note this may cause some functions of a DatumRange to change, such as the next() for a MonthDatumRange, but implementations should attempt to preserve type.

### Parameters

u - the new units.

### Returns:

the DatumRange in the new units.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## equals

equals( Object o ) → boolean

returns true if the two endpoints are equal.

### Parameters

o - an Object

### Returns:

a boolean
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getUnits

getUnits( ) → Units

return the units of the DatumRange.

### Returns:

the units of the DatumRange.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## hashCode

hashCode( ) → int

### Returns:

int
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## include

include( Datum d ) → DatumRange

return a new DatumRange that includes the given Datum, extending the range if necessary. For example,

     [0,1).include(2)→ [0,2)  (note this is exclusive of 2 since it's the end).
     [0,1).include(-1)→ [-1,1).
     [0,1).include(0.5) → [0,1]  (and returns the same DatumRange object)

Also, including a fill Datum returns the same DatumRange as well.

### Parameters

d - the Datum to include

### Returns:

the new range.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## intersection

intersection( DatumRange dr ) → DatumRange

returns the intersection of the two intersecting ranges. This is a range that contains(d) if and only if this.contains(d) and dr.contains(d).

### Parameters

dr - a valid datum range.

### Returns:

the intersection of the two intersecting ranges.

### See Also:

DatumRangeUtil#sloppyIntersection(org.das2.datum.DatumRange, org.das2.datum.DatumRange)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## intersects

intersects( DatumRange dr ) → boolean

returns true of the DatumRange overlaps this. Note that the endpoints are not included in the comparison, so that Tuesday.intersects(Wednesday)==false.

### Parameters

dr - a valid datum range

### Returns:

true of the DatumRange overlaps this
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## max

max( ) → Datum

returns the bigger value or stop of the range.

### Returns:

the bigger value or stop of the range.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## middle

middle( ) → Datum

returns the middle value of the range, often useful when the most descriptive value is needed.

### Returns:

the middle value of the range.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## min

min( ) → Datum

returns the smaller value or start of the range.

### Returns:

the smaller value or start of the range.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## newDatumRange

Deprecated:

## newRange

newRange( Datum lower, Datum upper ) → DatumRange

create a new DatumRange. In the case where lower is greater than upper, the two will be reversed automatically.

### Parameters

lower - the lower bound
upper - the upper bound

### Returns:

a new DatumRange
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## newRange

newRange( double lower, double upper, Units units ) → DatumRange

create a new DatumRange. In the case where lower is greater than upper, the two will be reversed automatically.

### Parameters

lower - the lower bound
upper - the upper bound
units - the units

### Returns:

a new DatumRange
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## newRange

newRange( double lower, double upper ) → DatumRange

create a new DatumRange. In the case where lower is greater than upper, the two will be reversed automatically.

### Parameters

lower - a double
upper - a double

### Returns:

a DatumRange
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## next

next( ) → DatumRange

returns the next DatumRange covering the space defined by Units. Typically, this will be a range with a min equal to this datum's max, and the same width. Some implementations of DatumRange may return a range with a different width than this DatumRange's width, for example, when advancing month-by-month with a MonthDatumRange. When there is no next interval, then this same range will be returned.

### Returns:

the next DatumRange covering the space defined by Units.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## previous

previous( ) → DatumRange

returns the previous DatumRange covering the space defined by Units. See next(). When there is no previous interval, then this same range will be returned.

### Returns:

the previous DatumRange covering the space defined by Units
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## rescale

rescale( double min, double max ) → DatumRange

returns DatumRange relative to this, where 0.0 is the minimum, and 1.0 is the maximum. For example rescale(1,2) is scanNext, rescale(-0.5,1.5) is zoomOut.

### Parameters

min - the new min normalized with respect to this range. 0.0 is this range's min, 1.0 is this range's max.
max - the new max with normalized with respect to this range. 0.0 is this range's min, 1.0 is this range's max.

### Returns:

new DatumRange.

### See Also:

DatumRangeUtil#rescale(org.das2.datum.DatumRange, double, double)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## toString

toString( ) → String

returns a human consumable representation of the string. This should also be parsable with DatumRangeUtil.parseDatumRange, but this has not been verified to complete certainty.

### Returns:

the DatumRange as a String.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## union

union( DatumRange dr ) → DatumRange

returns the union of the two intersecting or adjacent ranges.

### Parameters

dr - the other range of consistent units.

### Returns:

DatumRange union of the two DatumRanges
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## width

width( ) → Datum

returns the width of the range, which is simply the greater minus the lessor. Note that the units of the result will not necessarily be the same as the endpoints, for example with LocationDatums.

### Returns:

Datum that is the width of the range (max.subtract(min)).
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## zoomOut

zoomOut( double factor ) → DatumRange

returns a scaled DatumRange, with a new width that is the this datumRange's width multiplied by factor, and the same center. 1.0 is the same range, 2.0 has twice the width, etc.

### Parameters

factor - double representing the new range's width divided by this range's width.

### Returns:

a scaled DatumRange, with a new width that is the this datumRange's width multiplied by factor, and the same center.
[search for examples] [view on GitHub] [view on old javadoc] [view source]