@Override public Wom3DefinitionListDef removeDef(int index) throws IndexOutOfBoundsException { Backbone parent = getParentNode(); if (parent != null) { Wom3DefinitionListDef old = getDef(index); // Is expected to assertWritable(); parent.removeChild(old); return old; } else { assertWritableOnDocument(); return defs.remove(index); } }
protected void defAdded(Backbone prev, Wom3DefinitionListDef added) { int i = 0; Backbone p = prev; while (true) { if (p == null) { defs.add(i, added); return; } else if (p instanceof Wom3DefinitionListTerm) { if (p != this) throw new InternalError(); defs.add(i, added); return; } else if (p instanceof Wom3DefinitionListDef) { ++i; } p = p.getPreviousSibling(); } }
protected void transfer(Backbone sFirst, Backbone sLast, DefinitionListTermImpl other) { Backbone d = sLast; int i = defs.size(); while (true) { if (d instanceof Wom3DefinitionListDef) { // Sanity check if (defs.get(--i) != d) throw new InternalError(); } if (d == sFirst) break; // Step over non defs d = d.getPreviousSibling(); } // Sanity check if (d != sFirst) throw new InternalError(); // Do it! other.appendAll(defs.subList(i, defs.size())); while (defs.size() > i) defs.remove(defs.size() - 1); }
@Override public void insertDef(int beforeIndex, Wom3DefinitionListDef def) throws IndexOutOfBoundsException { Backbone parent = getParentNode(); if (parent != null) { int size = defs.size(); if (beforeIndex < 0 || beforeIndex > size) throw new IndexOutOfBoundsException(); if (beforeIndex == size) { // Is expected to assertWritable(); appendDef(def); } else { // Is expected to assertWritable(); parent.insertBefore(def, defs.get(beforeIndex)); } } else { assertWritableOnDocument(); defs.add(beforeIndex, def); } }
@Override public void appendDef(Wom3DefinitionListDef def) { Backbone parent = getParentNode(); if (parent != null) { Wom3Node before = null; if (!defs.isEmpty()) { Wom3DefinitionListDef lastDef = defs.get(defs.size() - 1); before = lastDef.getNextSibling(); } else { before = this.getNextSibling(); } if (before == null) { // Is expected to assertWritable(); parent.appendChild(def); } else { // Is expected to assertWritable(); parent.insertBefore(def, before); } } else { assertWritableOnDocument(); defs.add(def); } }