use of org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape in project lucene-solr by apache.
the class DateRangePrefixTreeTest method roundTrip.
private void roundTrip(Calendar calOrig) throws ParseException {
Calendar cal = (Calendar) calOrig.clone();
String lastString = null;
while (true) {
String calString;
{
Calendar preToStringCalClone = (Calendar) cal.clone();
calString = tree.toString(cal);
//ensure toString doesn't modify cal state
assertEquals(preToStringCalClone, cal);
}
//test parseCalendar
assertEquals(cal, tree.parseCalendar(calString));
//to Shape and back to Cal
UnitNRShape shape = tree.toShape(cal);
Calendar cal2 = tree.toCalendar(shape);
assertEquals(calString, tree.toString(cal2));
if (!calString.equals("*")) {
//not world cell
//to Term and back to Cell
Cell cell = (Cell) shape;
BytesRef term = cell.getTokenBytesNoLeaf(null);
Cell cell2 = tree.readCell(BytesRef.deepCopyOf(term), null);
assertEquals(calString, cell, cell2);
Calendar cal3 = tree.toCalendar((UnitNRShape) cell2.getShape());
assertEquals(calString, tree.toString(cal3));
// setLeaf comparison
cell2.setLeaf();
BytesRef termLeaf = cell2.getTokenBytesWithLeaf(null);
assertTrue(term.compareTo(termLeaf) < 0);
assertEquals(termLeaf.length, term.length + 1);
assertEquals(0, termLeaf.bytes[termLeaf.offset + termLeaf.length - 1]);
assertTrue(cell.isPrefixOf(cell2));
}
//end of loop; decide if should loop again with lower precision
final int calPrecField = tree.getCalPrecisionField(cal);
if (calPrecField == -1)
break;
int fieldIdx = Arrays.binarySearch(CAL_FIELDS, calPrecField);
assert fieldIdx >= 0;
int prevPrecField = (fieldIdx == 0 ? -1 : CAL_FIELDS[--fieldIdx]);
try {
tree.clearFieldsAfter(cal, prevPrecField);
} catch (AssertionError e) {
if (e.getMessage().equals("Calendar underflow"))
return;
throw e;
}
lastString = calString;
}
}
Aggregations