InnerLeaf (int index) { if (index < 0) throw outOfRange(index); CharSequence node = myNode; int nodeLength = node.length(); int offset = 0; while (true) { if (index >= nodeLength) { throw outOfRange(index); } if (!(node instanceof CompositeNode)) { return new InnerLeaf(node, offset, offset + nodeLength); } CompositeNode composite = (CompositeNode)node; int headLength = composite.head.length(); if (index < headLength) { node = composite.head; nodeLength = headLength; } else { offset += headLength; index -= headLength; node = composite.tail; nodeLength -= headLength; } } }