/** * {@inheritDoc} */ public T splitText(T textNode, int offset) { if (inconsistent) { throw new IllegalStateException("Cannot splitText() during a modification"); } if (offset == 0) { return textNode; } else if (offset >= substrate.getLength(textNode)) { return null; } currentLocation = getLocation(textNode) + offset; offsetList.performActionAt(currentLocation, locationUpdater); splitCurrent(); return asText(currentContainer.getValue()); }
/** * {@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); } } }
/** * {@inheritDoc} */ public T mergeText(T secondSibling) { if (inconsistent) { throw new IllegalStateException("Cannot mergeText() during a modification"); } currentLocation = getLocation(secondSibling); offsetList.performActionAt(currentLocation, locationUpdater); T mergedNode = substrate.mergeText(secondSibling); if (mergedNode != null) { OffsetList.Container<N> previous = currentContainer.getPreviousContainer(); currentContainer.increaseSize(previous.size()); previous.remove(); substrate.setIndexingContainer(mergedNode, currentContainer); } return mergedNode; }
assertEquals(0, doc.getLocation(element)); doc.getLocation(element); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException iae) { doc.getLocation(rawDoc.createElement("abc", Collections.<String, String>emptyMap(), doc.getDocumentElement(), null)); fail("Expected: IllegalArgumentException");
assertEquals(0, doc.getLocation(element)); doc.getLocation(element); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException iae) { doc.getLocation(rawDoc.createElement("abc", Collections.<String, String>emptyMap(), doc.getDocumentElement(), null)); fail("Expected: IllegalArgumentException");