/** * {@inheritDoc} */ public int getLocation(Point<N> point) { Preconditions.checkNotNull(point, "Cannot get the location of a null point"); Point.checkPoint(this, point, "IndexedDocumentImpl#getLocation"); if (point.isInTextNode()) { return getLocation(point.getContainer()) + point.getTextOffset(); } else { N nodeAfter = point.getNodeAfter(); if (nodeAfter == null) { return getLastLocationIn(point.getContainer()); } else { return getLocation(nodeAfter); } } }
/** * Gets the last location inside an element node. * * @param node An element node. * @return The last location inside an element node. */ private int getLastLocationIn(N node) { N lastChild = substrate.getLastChild(node); if (lastChild != null) { if (substrate.asElement(lastChild) != null) { return getLastLocationIn(lastChild) + 1; } else { OffsetList.Container<N> indexingContainer = substrate.getIndexingContainer(lastChild); return indexingContainer.offset() + indexingContainer.size(); } } else if (node == getDocumentElement()) { return size(); } else { return substrate.getIndexingContainer(node).offset() + 1; } }