- * Split this Fragment into two. 'this' Fragment will contain length
- * cells, 'this.next()' will contain (getCellCount() - length) cells.
- *
- * @param length the number of cells to leave in this Fragment
- * @throws IndexOutOfBoundsException if length is negative, or 0, greater
- * than (getCellCount() - 1)
- */
- public void split(final int length) {
- // Create the next node
- Line q = new Line();
- q.nextFrag = nextFrag;
- q.prevFrag = this;
- ((Line) nextFrag).prevFrag = q;
- nextFrag = q;
-
- // Split cells
- q.cells = new ArrayList<Cell>(cells.size() - length);
- q.cells.addAll(cells.subList(length, cells.size()));
- cells = cells.subList(0, length);
- }
-
- /**
- * Insert a new Fragment at a position, splitting the contents of this
- * Fragment into two around it. 'this' Fragment will contain the cells
- * between 0 and index, 'this.next()' will be the inserted fragment, and
- * 'this.next().next()' will contain the cells between 'index' and
- * getCellCount() - 1.
- *
- * @param index the number of cells to leave in this Fragment
- * @param fragment the Fragment to insert
- * @throws IndexOutOfBoundsException if length is negative, or 0, greater
- * than (getCellCount() - 1)
- */
- public void split(final int index, Fragment fragment) {
- // Create the next node and insert into the list.
- Line q = new Line();
- q.nextFrag = nextFrag;
- q.nextFrag.setPrev(q);
- q.prevFrag = fragment;
- fragment.setNext(q);
- fragment.setPrev(this);
- nextFrag = fragment;
-
- // Split cells
- q.cells = new ArrayList<Cell>(cells.size() - index);
- q.cells.addAll(cells.subList(index, cells.size()));
- cells = cells.subList(0, index);
- }
-
- /**
- * Insert a new Fragment before this one.
- *
- * @param fragment the Fragment to insert
- */
- public void insert(Fragment fragment) {
- fragment.setNext(this);
- fragment.setPrev(prevFrag);
- prevFrag.setNext(fragment);
- prevFrag = fragment;
- }
-
- /**
- * Append a new Fragment at the end of this one.
- *
- * @param fragment the Fragment to append
- */
- public void append(Fragment fragment) {
- fragment.setNext(nextFrag);
- fragment.setPrev(this);
- nextFrag.setPrev(fragment);
- nextFrag = fragment;
- }
-
- /**
- * Delete this Fragment from the list, and return its next().
- *
- * @return this Fragment's next(), or null if it was at the end of the
- * list
- */
- public Fragment deleteGetNext() {
- Fragment result = nextFrag;
- nextFrag.setPrev(prevFrag);
- prevFrag.setNext(nextFrag);
- prevFrag = null;
- nextFrag = null;
- return result;
- }
-
- /**
- * Delete this Fragment from the list, and return its prev().
- *
- * @return this Fragment's next(), or null if it was at the beginning of
- * the list
- */
- public Fragment deleteGetPrev() {
- Fragment result = prevFrag;
- nextFrag.setPrev(prevFrag);
- prevFrag.setNext(nextFrag);
- prevFrag = null;
- nextFrag = null;
- return result;
- }
-
- /**
- * Get the anchor position.
- *
- * @return the anchor number