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 DateRangePrefixTree |
INSTANCE |
levelByTermLen, maxSubCellsByLevel, maxTermLen, termLenByLevel
ctx, maxLevels
Modifier | Constructor and Description |
---|---|
protected |
DateRangePrefixTree() |
Modifier and Type | Method and Description |
---|---|
void |
clearFieldsAfter(Calendar cal,
int field)
Calendar utility method:
Calls
Calendar.clear(int) for every field after field . |
int |
getCalPrecisionField(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 . |
Calendar |
newCal()
Calendar utility method:
Returns a new
Calendar in UTC TimeZone, ROOT Locale, with all fields cleared. |
Calendar |
parseCalendar(String str)
Calendar utility method:
The reverse of
toString(java.util.Calendar) . |
protected NumberRangePrefixTree.UnitNRShape |
parseUnitShape(String str)
Parse a String to a UnitNRShape.
|
Calendar |
toCalendar(NumberRangePrefixTree.UnitNRShape lv)
Converts the
NumberRangePrefixTree.UnitNRShape shape to a
corresponding Calendar that is cleared below its level. |
Object |
toObject(NumberRangePrefixTree.UnitNRShape shape)
|
NumberRangePrefixTree.UnitNRShape |
toShape(Calendar cal)
Converts the Calendar into a Shape.
|
String |
toString(Calendar cal)
Calendar utility method:
Formats the calendar to ISO-8601 format, to include proper BC handling (1BC is "0000", 2BC is "-0001", etc.);
and WITHOUT a trailing 'Z'.
|
protected String |
toString(NumberRangePrefixTree.UnitNRShape lv)
A string representation of the UnitNRShape that is parse-able by
NumberRangePrefixTree.parseUnitShape(String) . |
NumberRangePrefixTree.UnitNRShape |
toUnitShape(Object value)
|
comparePrefix, getDistanceForLevel, getLevelForDistance, getWorldCell, newCellStack, parseShape, readCell, toRangeShape, toShape, toString, toStringUnitRaw
getMaxLevels, getSpatialContext, getTreeCellIterator
public static final DateRangePrefixTree INSTANCE
public int getNumSubCells(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree
getNumSubCells
in class NumberRangePrefixTree
public Calendar newCal()
Calendar
in UTC TimeZone, ROOT Locale, 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(Calendar cal)
public void clearFieldsAfter(Calendar cal, int field)
Calendar.clear(int)
for every field after field
. Beware of Calendar underflow.public NumberRangePrefixTree.UnitNRShape toUnitShape(Object value)
value
from a Calendar
or Date
to a Shape
. Other arguments
result in a IllegalArgumentException
.toUnitShape
in class NumberRangePrefixTree
public NumberRangePrefixTree.UnitNRShape toShape(Calendar cal)
public Object toObject(NumberRangePrefixTree.UnitNRShape shape)
toObject
in class NumberRangePrefixTree
public Calendar toCalendar(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree.UnitNRShape
shape to a
corresponding Calendar that is cleared below its level.protected String toString(NumberRangePrefixTree.UnitNRShape lv)
NumberRangePrefixTree
NumberRangePrefixTree.parseUnitShape(String)
.toString
in class NumberRangePrefixTree
public String toString(Calendar cal)
protected NumberRangePrefixTree.UnitNRShape parseUnitShape(String str) throws ParseException
NumberRangePrefixTree
parseUnitShape
in class NumberRangePrefixTree
ParseException
public Calendar parseCalendar(String str) throws 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 emptyParseException
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.