/**
* {@inheritDoc}
*/
public void process(WayContainer wayContainer) {
Way way;
long wayId;
long objectOffset;
int minimumTile;
int maximumTile;
boolean tilesFound;
if (nodeObjectReader == null) {
nodeObjectStore.complete();
nodeObjectReader = nodeObjectStore.createReader();
}
if (nodeObjectOffsetIndexReader == null) {
nodeObjectOffsetIndexWriter.complete();
nodeObjectOffsetIndexReader = nodeObjectOffsetIndexWriter.createReader();
}
way = wayContainer.getEntity();
wayId = way.getId();
// Write the way to the object store and save the file offset in an
// index keyed by way id.
objectOffset = wayObjectStore.add(way);
wayObjectOffsetIndexWriter.write(
new LongLongIndexElement(wayId, objectOffset)
);
if (enableWayTileIndex) {
// Calculate the minimum and maximum tile indexes for the way.
tilesFound = false;
minimumTile = 0;
maximumTile = 0;
for (WayNode wayNode : way.getWayNodes()) {
long nodeId;
Node node;
int tile;
nodeId = wayNode.getNodeId();
try {
node = nodeObjectReader.get(
nodeObjectOffsetIndexReader.get(nodeId).getValue()
);
tile = (int) tileCalculator.calculateTile(node.getLatitude(), node.getLongitude());
if (tilesFound) {
if (uintComparator.compare(tile, minimumTile) < 0) {
minimumTile = tile;
}
if (uintComparator.compare(maximumTile, tile) < 0) {
maximumTile = tile;
}
} else {
minimumTile = tile;
maximumTile = tile;
tilesFound = true;
}
} catch (NoSuchIndexElementException e) {
// Ignore any referential integrity problems.
if (LOG.isLoggable(Level.FINER)) {
LOG.finest(
"Ignoring referential integrity problem where way " + wayId
+ " refers to non-existent node " + nodeId + "."
);
}
}
}
// Write the way id to an index keyed by tile but only if tiles were
// actually found.
if (tilesFound) {
wayTileIndexWriter.write(wayId, minimumTile, maximumTile);
}
} else {
for (WayNode wayNode : way.getWayNodes()) {
long nodeId;
nodeId = wayNode.getNodeId();
nodeWayIndexWriter.write(new LongLongIndexElement(nodeId, wayId));