- @Override
- long getNextIndex() {
- if (lastEntry != null) {
- return lastEntry.index() + 1;
- } else {
- return firstIndex;
- }
- }
-
- @Override
- void append(Indexed<E> entry) {
- final long nextIndex = getNextIndex();
-
- // If the entry's index is greater than the next index in the segment, skip some entries.
- if (entry.index() > nextIndex) {
- throw new IndexOutOfBoundsException("Entry index is not sequential");
- }
-
- // If the entry's index is less than the next index, truncate the segment.
- if (entry.index() < nextIndex) {
- truncate(entry.index() - 1);
- }
- append(entry.entry());
- }
-