@Override public void delete(int deleteSize) { if (deleteSize > size() - currentLocation) { throw new OpCursorException("attempt to delete beyond end of document (cursor at " + currentLocation + ", size is " + size() + ", deleteSize is " + deleteSize + ")"); } traverse(deleteTraverser, deleteSize); }
@Override public void skip(int skipSize) { if (skipSize > size() - currentLocation) { throw new OpCursorException("attempt to skip beyond end of document (cursor at " + currentLocation + ", size is " + size() + ", distance is " + skipSize + ")"); } traverse(skipTraverser, skipSize); currentLocation += skipSize; }
@Override public Iterable<AnnotationInterval<Object>> annotationIntervals(int start, int end, ReadableStringSet keys) { if (keys == null) { if (start > 0 || end < size()) { throw new RuntimeException("not implemented"); } return new Iterable<AnnotationInterval<Object>>() { @Override public Iterator<AnnotationInterval<Object>> iterator() { return new RangesIterator(); } }; } return new GenericAnnotationIntervalIterable<Object>(this, start, end, keys); }
@Override public Object getAnnotation(int location, String key) { Preconditions.checkElementIndex(location, size()); checkKeyNotNull(key); Values values = ranges.performActionAt(location, finder).getValue(); return values == null ? null : values.get(key); }
@Override public int firstAnnotationChange(int start, int end, String key, Object fromValue) { Preconditions.checkPositionIndexes(start, end, size()); checkKeyNotNull(key); start = Math.max(0, start); end = Math.min(end, ranges.size()); OffsetPoint<Values> point = ranges.performActionAt(start, finder); OffsetList.Container<Values> container = point.getContainer(); int offset = point.getOffset(); int location = start; while (location < end) { if (!eq(getValue(container, key), fromValue)) { return location; } if (container == ranges.sentinel()) { break; } location += container.size() - offset; container = container.getNextContainer(); offset = 0; } return -1; }
@Override public int lastAnnotationChange(int start, int end, String key, Object fromValue) { Preconditions.checkPositionIndexes(start, end, size()); checkKeyNotNull(key); start = Math.max(0, start); end = Math.min(end, ranges.size()); OffsetPoint<Values> point = ranges.performActionAt(end, finder); OffsetList.Container<Values> container = point.getContainer(); int offset = point.getOffset(); if (offset == 0) { container = container.getPreviousContainer(); offset = container == ranges.sentinel() ? 0 : container.size(); } int location = end; while (location > start) { if (!eq(getValue(container, key), fromValue)) { return location; } if (container == null) { break; } location -= offset; container = container.getPreviousContainer(); offset = container == ranges.sentinel() ? 0 : container.size(); } return -1; }