int deleteBlock = 0;
for (int i = 0; i < nodeCount; i++) {
// get the node name
ATermAppl a = nodeList.get(i);
// and the corresponding node
Node node = abox.getNode(a);
// node dependency tells us if the node was created after the branch
// and if that is the case we remove it completely
// NOTE: for literals, node.getNodeDepends() may be null when a literal value branch is
// restored, in that case we can remove the literal since there is no other reference
// left for that literal
if (node.getNodeDepends() == null || node.getNodeDepends().getBranch() > br.getBranch()) {
// remove the node from the node map
abox.removeNode(a);
// if the node is merged to another one we should remove it from
// the other node's merged list
if (node.isMerged()) {
node.undoSetSame();
}
// increment the size of block that will be deleted
deleteBlock++;
}
else {
// this node will be restored to previous state not removed
// first if there are any nodes collected earlier delete them
if (deleteBlock > 0) {
// create the sub list for nodes to be removed
List<ATermAppl> subList = nodeList.subList(i - deleteBlock, i);
if (log.isLoggable(Level.FINE)) {
log.fine("Remove nodes " + subList);
}
// clear the sublist causing all elements to removed from nodeList
subList.clear();
// update counters
nodeCount -= deleteBlock;
i -= deleteBlock;
deleteBlock = 0;
}
// restore only if not tracking branch effects
if (!PelletOptions.TRACK_BRANCH_EFFECTS) {
node.restore(br.getBranch());
}
}
}
// if there were nodes to be removed at the end of the list do it now
if (deleteBlock > 0) {
nodeList.subList(nodeCount - deleteBlock, nodeCount).clear();
}
if (PelletOptions.TRACK_BRANCH_EFFECTS) {
// when tracking branch effects only restore nodes explicitly stored in the effected list
Set<ATermAppl> effected = abox.getBranchEffectTracker().removeAll(br.getBranch() + 1);
for (ATermAppl a : effected) {
Node n = abox.getNode(a);
if (n != null) {
n.restore(br.getBranch());
}
}
}
restoreAllValues();