Class DateRangePrefixTree
java.lang.Object
org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree
org.apache.lucene.spatial.prefix.tree.DateRangePrefixTree
A PrefixTree for date ranges in which the levels of the tree occur at natural periods of time
(e.g. years, months, ...). You pass in
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.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree
NumberRangePrefixTree.NRCell, NumberRangePrefixTree.NRShape, NumberRangePrefixTree.SpanUnitsNRShape, NumberRangePrefixTree.UnitNRShape -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CalendarThe Java platform defaultCalendarwith UTC & ROOT Locale.static final CalendarA Calendar instance compatible withZonedDateTimeas seen fromGregorianCalendar.from(ZonedDateTime).Fields inherited from class org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree
levelByTermLen, maxSubCellsByLevel, maxTermLen, termLenByLevelFields inherited from class org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
ctx, maxLevels -
Constructor Summary
ConstructorsConstructorDescriptionDateRangePrefixTree(Calendar templateCal) Constructs with the specified calendar used as a template to be cloned whenever a new Calendar needs to be created. -
Method Summary
Modifier and TypeMethodDescriptionvoidclearFieldsAfter(Calendar cal, int field) Calendar utility method: CallsCalendar.clear(int)for every field afterfield.intCalendar utility method: Gets the Calendar field code of the last field that is set prior to an unset field.intReturns the number of sub-cells beneath the given UnitNRShape.intgetTreeLevelForCalendarField(int calField) Calendar utility method: Returns the spatial prefix tree level for the correspondingCalendarfield, such asCalendar.YEAR.newCal()Calendar utility method: Returns a clone of theCalendarpassed to the constructor with all fields cleared.parseCalendar(String str) Calendar utility method: The reverse oftoString(java.util.Calendar).protected NumberRangePrefixTree.UnitNRShapeparseUnitShape(String str) Parse a String to a UnitNRShape.Converts theNumberRangePrefixTree.UnitNRShapeshape to a corresponding Calendar that is cleared below its level.Converts the Calendar into a Shape.Calendar utility method consistent withDateTimeFormatter.ISO_INSTANTexcept has no trailing 'Z', and will be truncated to the units given according toCalendar.isSet(int).protected StringA string representation of the UnitNRShape that is parse-able byNumberRangePrefixTree.parseUnitShape(String).toUnitShape(Object value) Methods inherited from class org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree
comparePrefix, getDistanceForLevel, getLevelForDistance, getWorldCell, newCellStack, parseShape, readCell, toRangeShape, toShape, toString, toStringUnitRawMethods inherited from class org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
getMaxLevels, getSpatialContext, getTreeCellIterator
-
Field Details
-
DEFAULT_CAL
The Java platform defaultCalendarwith UTC & ROOT Locale. Generally aGregorianCalendar. Do not modify this! -
JAVA_UTIL_TIME_COMPAT_CAL
A Calendar instance compatible withZonedDateTimeas seen fromGregorianCalendar.from(ZonedDateTime). Do not modify this!
-
-
Constructor Details
-
DateRangePrefixTree
Constructs with the specified calendar used as a template to be cloned whenever a new Calendar needs to be created. SeeDEFAULT_CALandJAVA_UTIL_TIME_COMPAT_CAL.
-
-
Method Details
-
getNumSubCells
Description copied from class:NumberRangePrefixTreeReturns the number of sub-cells beneath the given UnitNRShape.- Overrides:
getNumSubCellsin classNumberRangePrefixTree
-
newCal
Calendar utility method: Returns a clone of theCalendarpassed to the constructor with all fields cleared. -
getTreeLevelForCalendarField
public int getTreeLevelForCalendarField(int calField) Calendar utility method: Returns the spatial prefix tree level for the correspondingCalendarfield, such asCalendar.YEAR. If there's no match, the next greatest level is returned as a negative value. -
getCalPrecisionField
Calendar utility method: Gets the Calendar field code of the last field that is set prior to an unset field. It only examines fields relevant to the prefix tree. If no fields are set, it returns -1. -
clearFieldsAfter
Calendar utility method: CallsCalendar.clear(int)for every field afterfield. Beware of Calendar underflow. -
toUnitShape
Convertsvaluefrom aCalendarorDateto aShape. Other arguments result in aIllegalArgumentException. If a Calendar is passed in, there might be problems if it is not created vianewCal().- Specified by:
toUnitShapein classNumberRangePrefixTree
-
toShape
Converts the Calendar into a Shape. The isSet() state of the Calendar is re-instated when done. If a Calendar is passed in, there might be problems if it is not created vianewCal(). -
toObject
- Specified by:
toObjectin classNumberRangePrefixTree
-
toCalendar
Converts theNumberRangePrefixTree.UnitNRShapeshape to a corresponding Calendar that is cleared below its level. -
toString
Description copied from class:NumberRangePrefixTreeA string representation of the UnitNRShape that is parse-able byNumberRangePrefixTree.parseUnitShape(String).- Specified by:
toStringin classNumberRangePrefixTree
-
toString
Calendar utility method consistent withDateTimeFormatter.ISO_INSTANTexcept has no trailing 'Z', and will be truncated to the units given according toCalendar.isSet(int). A fully cleared calendar will yield the string "*". The isSet() state of the Calendar is re-instated when done. -
parseUnitShape
Description copied from class:NumberRangePrefixTreeParse a String to a UnitNRShape. "*" should be the full-range (level 0 shape).- Specified by:
parseUnitShapein classNumberRangePrefixTree- Throws:
ParseException
-
parseCalendar
Calendar utility method: The reverse oftoString(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.- Parameters:
str- not null and not empty- Returns:
- not null
- Throws:
ParseException
-