}
private static void replaceChildLeftTuple(LeftTuple peer, LeftTuple leftPrevious, LeftTuple leftNext, LeftTuple rightPrevious, LeftTuple rightNext, LeftTuple newPeer) {boolean isHandle = peer.getLeftParent() == null;
InternalFactHandle fh = peer.getLastHandle();
LeftTuple leftParent = peer.getLeftParent();
RightTuple rightParent = peer.getRightParent();
newPeer.setLeftParent( peer.getLeftParent() );
newPeer.setRightParent( peer.getRightParent() );
// replace left
if ( leftPrevious == null && leftNext == null ) {
// no other tuples, simply replace
if ( isHandle ) {
fh.removeLeftTuple( peer );
fh.addFirstLeftTuple( newPeer );
} else {
peer.unlinkFromLeftParent();
leftParent.setFirstChild(newPeer);
leftParent.setLastChild(newPeer);
}
} else if ( leftNext != null ) {
// replacing first
newPeer.setLeftParentNext(leftNext);
leftNext.setLeftParentPrevious(newPeer);
if ( isHandle ) {
fh.setFirstLeftTuple(newPeer);
} else {
leftParent.setFirstChild(newPeer);
}
} else {
// replacing last
newPeer.setLeftParentPrevious(leftPrevious);
leftPrevious.setLeftParentNext(newPeer);
if ( isHandle ) {
fh.setLastLeftTuple(newPeer);
} else {
leftParent.setLastChild(newPeer);
}
}
// replace right
if ( rightParent != null ) {
// LiaNode LeftTuples have no right parents
if ( rightPrevious == null && rightNext == null ) {
// no other tuples, simply replace
peer.unlinkFromRightParent();
rightParent.setFirstChild(newPeer);
rightParent.setLastChild(newPeer);
} else if ( rightNext != null ) {
// replacing first
newPeer.setRightParentNext(rightNext);
rightNext.setRightParentPrevious(newPeer);
rightParent.setFirstChild(newPeer);
} else {
// replacing last
newPeer.setRightParentPrevious(rightPrevious);
rightPrevious.setRightParentNext(newPeer);
rightParent.setLastChild(newPeer);
}
}
}