public class DatumRangeUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DatumRangeUtil.DateDescriptor |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
iso8601duration |
static java.util.regex.Pattern |
iso8601DurationPattern |
Constructor and Description |
---|
DatumRangeUtil() |
Modifier and Type | Method and Description |
---|---|
static DatumRange |
createCentered(Datum middle,
Datum width)
create a DatumRange with the value for the center, and the width.
|
static java.lang.String |
formatISO8601Datum(int[] result)
for convenience, this formats the decomposed time.
|
static java.lang.String |
formatISO8601Duration(int[] t)
format ISO8601 duration string, for example [1,0,0,1,0,0,0] → P1YT1H
|
static java.lang.String |
formatTimeRange(DatumRange self) |
static java.lang.String |
formatTimeRange(DatumRange self,
boolean bothDoyYMD)
format the time into an efficient string.
|
static boolean |
fuzzyEqual(DatumRange timeRange1,
DatumRange timeRange2,
double percent)
return true if the time ranges are overlapping with bounds within
|
static java.util.List<DatumRange> |
generateList(DatumRange bounds,
DatumRange element)
return a list of DatumRanges that together cover the space identified
by bounds.
|
static java.util.List<DatumRange> |
intersection(java.util.List<DatumRange> bounds,
java.util.List<DatumRange> elements,
boolean remove)
return the elements of src that intersect with elements of the list contains.
|
static boolean |
isAcceptable(DatumRange dr,
boolean log)
put limits on the typical use when looking at data:
* both min and max are finite numbers
* time range is between year 1000 and year 3000.
|
static boolean |
isISO8601Range(java.lang.String stringIn)
true true for parseable ISO8601 time ranges.
|
static void |
main(java.lang.String[] ss) |
static DatumRange |
newDimensionless(double lower,
double upper)
create a new DatumRange.
|
static double |
normalize(DatumRange dr,
Datum d)
returns the position within dr, where 0.
|
static double |
normalize(DatumRange dr,
Datum d,
boolean log) |
static double |
normalizeLog(DatumRange dr,
Datum d)
returns the position within dr, where 0.
|
static int[] |
normalizeTimeComponents(int[] components)
Normalize all the components, so no component is
greater than its expected range or less than zero.
|
static DatumRange |
parseDatumRange(java.lang.String str)
This provides unambiguous rules for parsing all types datum ranges strictly
from strings, with no out of band information.
|
static DatumRange |
parseDatumRange(java.lang.String str,
DatumRange orig) |
static DatumRange |
parseDatumRange(java.lang.String str,
Units units)
Parse the datum range in the context of units.
|
static int[] |
parseISO8601(java.lang.String str)
Parser for ISO8601 formatted times.
|
static int |
parseISO8601Datum(java.lang.String str,
int[] result,
int lsd)
new attempt to write a clean ISO8601 parser.
|
static int[] |
parseISO8601Duration(java.lang.String stringIn)
returns a 7 element array with [year,mon,day,hour,min,sec,nanos].
|
static DatumRange |
parseISO8601Range(java.lang.String stringIn)
returns the time found in an iso8601 string, or null.
|
static Datum[] |
parseRescaleStr(java.lang.String s,
Datum[] result)
parse position strings like "100%-5hr" into [ npos, datum ].
|
static DatumRange |
parseTimeRange(java.lang.String string)
parse the string into a DatumRange with time location units.
|
static DatumRange |
parseTimeRangeValid(java.lang.String s)
parse the string into a DatumRange with time location units.
|
static DatumRange |
parseValidISO8601Range(java.lang.String stringIn)
returns the time found in an iso8601 string, or throws a
runtime exception.
|
static Datum |
rescale(DatumRange dr,
double n)
returns Datum relative to dr, where 0 is the minimum, and 1 is the maximum.
|
static DatumRange |
rescale(DatumRange dr,
double min,
double max)
returns DatumRange relative to dr, where 0 is the minimum, and 1 is the maximum.
|
static DatumRange |
rescale(DatumRange dr,
java.lang.String rescale)
rescale the DatumRange with a specification like "50%,150%" or "0%-1hr,100%+1hr".
|
static DatumRange |
rescaleInverse(DatumRange dr,
double min,
double max)
inverse of rescale function
|
static DatumRange |
rescaleInverse(DatumRange dr,
java.lang.String rescale)
rescale the DatumRange with a specification like "50%,150%" or
"0%-1hr,100%+1hr".
|
static DatumRange |
rescaleLog(DatumRange dr,
double min,
double max)
returns DatumRange relative to this, where 0.
|
static DatumRange |
roundSections(DatumRange dr,
int n)
round to a nice interval with very roughly n divisions.
|
static void |
setUseDoy(boolean v) |
static boolean |
sloppyContains(DatumRange context,
Datum datum)
Like DatumRange.contains, but includes the end point.
|
static DatumRange |
sloppyIntersection(DatumRange range,
DatumRange include)
Like DatumRange.intersects, but returns a zero-width range when the two do
not intersect.
|
static java.lang.String |
toStringInclusive(DatumRange datumRange)
represent the string to indicate that the calling code will also consider
the maximum value part of the datum range.
|
static DatumRange |
union(Datum d1,
Datum d2)
return a datum range that sloppily covers the d1 and d2.
|
static DatumRange |
union(DatumRange range,
Datum include)
return the union of a DatumRange and Datum.
|
static DatumRange |
union(DatumRange range,
DatumRange include)
return the union of two DatumRanges.
|
public static final java.lang.String iso8601duration
public static final java.util.regex.Pattern iso8601DurationPattern
public static boolean isAcceptable(DatumRange dr, boolean log)
dr
- the DatumRange, which can contain infinite values that would make is inacceptable.log
- if true, then only allow 1e100 cycles.public static java.lang.String toStringInclusive(DatumRange datumRange)
datumRange
- "5 to 15 Kg"public static java.lang.String formatISO8601Datum(int[] result)
result
- seven-element time [ Y,m,d,H,M,S,nanos ]public static int parseISO8601Datum(java.lang.String str, int[] result, int lsd)
str
- the ISO8601 stringresult
- the datum, decomposed into [year,month,day,hour,minute,second,nano]lsd
- -1 or the current position ???public static int[] normalizeTimeComponents(int[] components)
components
- int[7]: [ Y, m, d, H, M, S, nano ]public static int[] parseISO8601(java.lang.String str)
str
- iso8601 string.public static int[] parseISO8601Duration(java.lang.String stringIn) throws java.text.ParseException
stringIn
- java.text.ParseException
- if the string does not appear to be valid.public static java.lang.String formatISO8601Duration(int[] t)
t
- 6 or 7-element array with [year,mon,day,hour,min,sec,nanos]public static boolean isISO8601Range(java.lang.String stringIn)
stringIn
- public static DatumRange parseISO8601Range(java.lang.String stringIn) throws java.text.ParseException
stringIn
- java.text.ParseException
public static DatumRange parseValidISO8601Range(java.lang.String stringIn)
stringIn
- public static void main(java.lang.String[] ss) throws java.text.ParseException
java.text.ParseException
public static DatumRange parseTimeRange(java.lang.String string) throws java.text.ParseException
string
- java.text.ParseException
- when the string cannot be parsed.java.lang.IllegalArgumentException
- when an orbits file cannot be readpublic static DatumRange parseTimeRangeValid(java.lang.String s)
s
- java.lang.IllegalArgumentException
- when the string cannot be parsed.public static void setUseDoy(boolean v)
public static java.lang.String formatTimeRange(DatumRange self)
public static java.lang.String formatTimeRange(DatumRange self, boolean bothDoyYMD)
self
- bothDoyYMD
- if true, use $Y-$m-$d ($j) for formatting days.public static java.util.List<DatumRange> generateList(DatumRange bounds, DatumRange element)
DatumRange bounds= DatumRangeUtil.parseTimeRangeValid( '2006' ); DatumRange first= DatumRangeUtil.parseTimeRangeValid( 'Jan 2006' ); List list= generateList( bounds, first );Note the procedure calls element.previous until bound.min() is contained, then calls bound.max until bound.max() is contained.
bounds
- range to be covered.element
- range defining the width and phase of each list DatumRange.public static DatumRange newDimensionless(double lower, double upper)
lower
- upper
- public static DatumRange parseDatumRange(java.lang.String str, Units units) throws java.text.ParseException
str
- input like "5 to 15 cm"units
- unit like Units.kmjava.text.ParseException
public static DatumRange parseDatumRange(java.lang.String str, DatumRange orig) throws java.text.ParseException
java.text.ParseException
public static DatumRange parseDatumRange(java.lang.String str) throws java.text.ParseException
str
- the string representing a time.java.text.ParseException
public static Datum[] parseRescaleStr(java.lang.String s, Datum[] result) throws java.text.ParseException
s
- the string, like "100%-5hr"result
- a two-element Datum array with [npos,datum] result[1] provides the units.java.text.ParseException
public static DatumRange rescale(DatumRange dr, java.lang.String rescale) throws java.text.ParseException
dr
- rescale
- java.text.ParseException
public static DatumRange rescaleInverse(DatumRange dr, java.lang.String rescale) throws java.text.ParseException
dr
- rescale
- java.text.ParseException
public static DatumRange rescale(DatumRange dr, double min, double max)
dr
- a DatumRange with nonzero width.min
- the new min normalized with respect to this range. 0. is this range's min, 1 is this range's maxmax
- the new max with normalized wrt this range. 0. is this range's min, 1 is this range's max.public static Datum rescale(DatumRange dr, double n)
dr
- a DatumRange with nonzero width.n
- the location normalized with respect to this range. 0. is the range's min, 1 is the range's max.public static DatumRange rescaleInverse(DatumRange dr, double min, double max)
dr
- a DatumRange with nonzero width.min
- the new min normalized with respect to this range. 0. is this range's min, 1 is this range's maxmax
- the new max with normalized wrt this range. 0. is this range's min, 1 is this range's max.public static DatumRange rescaleLog(DatumRange dr, double min, double max)
dr
- a DatumRange with nonzero width.min
- the new min normalized with respect to this range. 0. is this range's min, 1 is this range's max, 0 is
min-width.max
- the new max with normalized wrt this range. 0. is this range's min, 1 is this range's max, 0 is
min-width.public static DatumRange createCentered(Datum middle, Datum width)
middle
- width
- public static double normalize(DatumRange dr, Datum d)
dr
- a datum range with non-zero width.d
- a datum to normalize with respect to the range.rescale(org.das2.datum.DatumRange, double, double)
public static double normalize(DatumRange dr, Datum d, boolean log)
public static double normalizeLog(DatumRange dr, Datum d)
dr
- a datum range with non-zero width.d
- a datum to normalize with respect to the range.public static DatumRange sloppyIntersection(DatumRange range, DatumRange include)
range
- the first DatumRangeinclude
- the second DatumRangeDatumRange.intersection(org.das2.datum.DatumRange)
public static java.util.List<DatumRange> intersection(java.util.List<DatumRange> bounds, java.util.List<DatumRange> elements, boolean remove)
bounds
- sorted list of non-overlapping ranges.elements
- sorted list of non-overlapping ranges. If remove is true, then
the elements intersecting are removed and the result will contain non-overlapping elements.remove
- if true, remove intersecting elements from the elements list, leaving the elements that
did not intersect with any of the ranges in bounds.public static boolean sloppyContains(DatumRange context, Datum datum)
context
- the datum range.datum
- the data pointDatumRange.contains(org.das2.datum.DatumRange)
public static DatumRange union(Datum d1, Datum d2)
d1
- d2
- InconvertibleUnitsException
public static DatumRange union(DatumRange range, Datum include)
range
- the range or null. If range is null, then new DatumRange( include, include ) is returned.include
- a datum to add this this range. If its the max, then
it will be the end of the datum range, not included.InconvertibleUnitsException
public static DatumRange union(DatumRange range, DatumRange include)
range
- the range, or null. If range is null then include is returned.include
- the DatumRange to include.InconvertibleUnitsException
public static boolean fuzzyEqual(DatumRange timeRange1, DatumRange timeRange2, double percent)
timeRange1
- timeRange2
- percent
- double from 0 to 100.public static DatumRange roundSections(DatumRange dr, int n)
-0.048094730687625806 to 0.047568, 100 → -0.048 to 0.048 2012-04-18 0:00:00 to 23:59:40, 24 → 2012-04-18 2014-08-10 0:00:00 to 2014-08-11T00:00:59, 24 → 2014-08-10
dr
- n
-