public class DateRangePrefixTree extends NumberRangePrefixTree
Calendar
objects with the desired fields set and the unspecified
fields unset, which conveys the precision. The implementation makes some optimization assumptions about a
GregorianCalendar
; others could probably be supported easily.
Warning: If you construct a Calendar and then get something from the object like a field (e.g. year) or milliseconds, then every field is fully set by side-effect. So after setting the fields, pass it to this API first.
NumberRangePrefixTree.NRCell, NumberRangePrefixTree.NRShape, NumberRangePrefixTree.SpanUnitsNRShape, NumberRangePrefixTree.UnitNRShape
Modifier and Type | Field and Description |
---|---|
static java.util.Calendar |
DEFAULT_CAL
The Java platform default
Calendar with UTC & ROOT Locale. |
static DateRangePrefixTree |
INSTANCE
Deprecated.
|
static java.util.Calendar |
JAVA_UTIL_TIME_COMPAT_CAL
A Calendar instance compatible with
ZonedDateTime as seen from
GregorianCalendar.from(ZonedDateTime) . |
levelByTermLen, maxSubCellsByLevel, maxTermLen, termLenByLevel
ctx, maxLevels
Constructor and Description |
---|
DateRangePrefixTree(java.util.Calendar templateCal)
Constructs with the specified calendar used as a template to be cloned whenever a new
Calendar needs to be created.
|
Modifier and Type | Method and Description |
---|---|
void |
clearFieldsAfter(java.util.Calendar cal,
int field)
Calendar utility method:
Calls
Calendar.clear(int) for every field after field . |
int |
getCalPrecisionField(java.util.Calendar cal)
Calendar utility method:
Gets the Calendar field code of the last field that is set prior to an unset field.
|
int |
getNumSubCells(NumberRangePrefixTree.UnitNRShape lv)
Returns the number of sub-cells beneath the given UnitNRShape.
|
int |
getTreeLevelForCalendarField(int calField)
Calendar utility method:
Returns the spatial prefix tree level for the corresponding
Calendar field, such as
Calendar.YEAR . |
java.util.Calendar |
newCal()
Calendar utility method:
Returns a clone of the
Calendar passed to the constructor with all fields cleared. |
java.util.Calendar |
parseCalendar(java.lang.String str)
Calendar utility method:
The reverse of
toString(java.util.Calendar) . |
protected NumberRangePrefixTree.UnitNRShape |
parseUnitShape(java.lang.String str)
Parse a String to a UnitNRShape.
|
java.util.Calendar |
toCalendar(NumberRangePrefixTree.UnitNRShape lv)
Converts the
NumberRangePrefixTree.UnitNRShape shape to a
corresponding Calendar that is cleared below its level. |
java.lang.Object |
toObject(NumberRangePrefixTree.UnitNRShape shape)
|
NumberRangePrefixTree.UnitNRShape |
toShape(java.util.Calendar cal)
Converts the Calendar into a Shape.
|
java.lang.String |
toString(java.util.Calendar cal)
Calendar utility method consistent with
DateTimeFormatter.ISO_INSTANT except
has no trailing 'Z', and will be truncated to the units given according to
Calendar.isSet(int) . |
protected java.lang.String |
toString(NumberRangePrefixTree.UnitNRShape lv)
A string representation of the UnitNRShape that is parse-able by
NumberRangePrefixTree.parseUnitShape(String) . |
NumberRangePrefixTree.UnitNRShape |
toUnitShape(java.lang.Object value)
Converts
value from a Calendar or Date to a Shape . |
comparePrefix, getDistanceForLevel, getLevelForDistance, getWorldCell, newCellStack, parseShape, readCell, toRangeShape, toShape, toString, toStringUnitRaw
getMaxLevels, getSpatialContext, getTreeCellIterator
public static final java.util.Calendar DEFAULT_CAL
Calendar
with UTC & ROOT Locale. Generally a GregorianCalendar
.
Do not modify this!public static final java.util.Calendar JAVA_UTIL_TIME_COMPAT_CAL
ZonedDateTime
as seen from
GregorianCalendar.from(ZonedDateTime)
.
Do not modify this!@Deprecated public static final DateRangePrefixTree INSTANCE
Calendar.getInstance(TimeZone, Locale)
with UTC and Locale.Root. This
will (always?) be a GregorianCalendar
with a so-called "Gregorian Change Date" of 1582.public DateRangePrefixTree(java.util.Calendar templateCal)
DEFAULT_CAL
and JAVA_UTIL_TIME_COMPAT_CAL
.public int getNumSubCells(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree
getNumSubCells
in class NumberRangePrefixTree
public java.util.Calendar newCal()
Calendar
passed to the constructor with all fields cleared.public int getTreeLevelForCalendarField(int calField)
Calendar
field, such as
Calendar.YEAR
. If there's no match, the next greatest level is returned as a negative value.public int getCalPrecisionField(java.util.Calendar cal)
public void clearFieldsAfter(java.util.Calendar cal, int field)
Calendar.clear(int)
for every field after field
. Beware of Calendar underflow.public NumberRangePrefixTree.UnitNRShape toUnitShape(java.lang.Object value)
value
from a Calendar
or Date
to a Shape
. Other arguments
result in a IllegalArgumentException
.
If a Calendar is passed in, there might be problems if it is not created via newCal()
.toUnitShape
in class NumberRangePrefixTree
public NumberRangePrefixTree.UnitNRShape toShape(java.util.Calendar cal)
newCal()
.public java.lang.Object toObject(NumberRangePrefixTree.UnitNRShape shape)
toObject
in class NumberRangePrefixTree
public java.util.Calendar toCalendar(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree.UnitNRShape
shape to a
corresponding Calendar that is cleared below its level.protected java.lang.String toString(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree
NumberRangePrefixTree.parseUnitShape(String)
.toString
in class NumberRangePrefixTree
public java.lang.String toString(java.util.Calendar cal)
DateTimeFormatter.ISO_INSTANT
except
has no trailing 'Z', and will be truncated to the units given according to
Calendar.isSet(int)
.
A fully cleared calendar will yield the string "*".
The isSet() state of the Calendar is re-instated when done.protected NumberRangePrefixTree.UnitNRShape parseUnitShape(java.lang.String str) throws java.text.ParseException
NumberRangePrefixTree
parseUnitShape
in class NumberRangePrefixTree
java.text.ParseException
public java.util.Calendar parseCalendar(java.lang.String str) throws java.text.ParseException
toString(java.util.Calendar)
. It will only set the fields found, leaving
the remainder in an un-set state. A leading '-' or '+' is optional (positive assumed), and a
trailing 'Z' is also optional.str
- not null and not emptyjava.text.ParseException
Copyright © 2000–2019 The Apache Software Foundation. All rights reserved.