@Override public String toString() { final StringBuilder sb = new StringBuilder(); final DataSegment prev = getPrevious(); final DataSegment next = getNext(); if (prev != null) { sb.append(prev.get() + "<"); } sb.append(getPosition()); if (next != null) { sb.append(">" + next.get()); } return sb.toString(); } }
start = _last.getPosition();
/** * Get an anchor at the specified position. Breaks up the segment at the given point if * necessary. If there already is an anchor, it is reused. * * @param pos * a position. * @return an anchor. */ public Anchor getAnchor(final int pos) { if (pos == 0) { return _first; } // Split up segment final AbstractDataSegment prefix = getSegmentAt(pos, true); if (prefix.isAnchor()) { return (Anchor) prefix; } else { final AbstractDataSegment suffix = prefix.split(pos); // Insert segment final AnchorSegment seg = new AnchorSegment(prefix, suffix); prefix._next = seg; suffix._prev = seg; // Drop useless segments dropSuperflourous(prefix); dropSuperflourous(suffix); return seg; } }
@Override public AbstractDataSegment split(final int position) { // Normally anchors are unsplittable (they have a width of zero), // but an attempt to split an anchor will return the anchor itself // if the split position is exactly the anchor position. if (position == getPosition()) { return this; } else { throw new IndexOutOfBoundsException("Split position [" + position + "] does not match anchor position [" + getPosition() + "]"); } }
@Override public int getPosition() { return getStart(); }