- /**
- * 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);