ChildReferences references = getChildReferences(session);
ChildReference before = null;
if (nextNode != null) {
before = references.getChild(nextNode);
if (before == null) throw new NodeNotFoundException(key);
}
// Remove the node from where it is ...
MutableChildReferences appended = this.appended.get();
ChildReference toBeMoved = null;
if (appended != null) {
// Try to remove it from the appended nodes ...
toBeMoved = appended.remove(key);
}
if (toBeMoved == null) {
// It wasn't appended, so verify it is really a child ...
toBeMoved = references.getChild(key);
if (toBeMoved == null) throw new NodeNotFoundException(key);
if (changedChildren.inserted(key) == null) {
// And mark it as removed only if it doesn't appear as inserted
// a node can be transient, not appended but inserted in the case of transient reorderings
changedChildren.remove(key);
}