- Line p = (Line) prevFrag;
- ArrayList<Cell> newCells = new ArrayList<Cell>(this.cells.size() +
- p.cells.size());
- newCells.addAll(p.cells);
- newCells.addAll(this.cells);
- this.cells = newCells;
- ((Line) p.prevFrag).nextFrag = this;
- prevFrag = p.prevFrag;
- return true;
- }
-
- /**
- * Set the next Fragment in the list. Note that this performs no sanity
- * checking or modifications on fragment; this function can break
- * connectivity in the list.
- *
- * @param fragment the next Fragment, or null
- */
- public void setNext(Fragment fragment) {
- nextFrag = fragment;
- }
-
- /**
- * Set the previous Fragment in the list. Note that this performs no
- * sanity checking or modifications on fragment; this function can break
- * connectivity in the list.
- *
- * @param fragment the previous Fragment, or null
- */
- public void setPrev(Fragment fragment) {
- prevFrag = fragment;
- }
-
- /**
- * 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);