}
public void delete(LogicalDependency node,
BeliefSet beliefSet,
PropagationContext context) {
JTMSBeliefSetImpl jtmsBeliefSet = (JTMSBeliefSetImpl) beliefSet;
boolean wasConflicting = jtmsBeliefSet.isUndecided();
boolean wasNegated = jtmsBeliefSet.isNegated();
// If the prime object is removed, we need to update the FactHandle, and tell the callback to update
boolean primeChanged = false;
if ( (jtmsBeliefSet.getPositiveFactHandle() != null && jtmsBeliefSet.getPositiveFactHandle().getObject() == node.getObject()) ||
(jtmsBeliefSet.getNegativeFactHandle() != null && jtmsBeliefSet.getNegativeFactHandle().getObject() == node.getObject()) ) {
primeChanged = true;
}
beliefSet.remove( node.getJustifierEntry() );
if ( beliefSet.isEmpty() ) {
if ( wasNegated ) {
defEP.getObjectStore().addHandle( beliefSet.getFactHandle(), beliefSet.getFactHandle().getObject() ); // was negated, so add back in, so main retract works
retractOrUpdateBelief( node, context, jtmsBeliefSet.getNegativeFactHandle(), false, true );
}
if ( !(context.getType() == PropagationContext.DELETION && context.getFactHandle() == beliefSet.getFactHandle()) ) { // don't start retract, if the FH is already in the process of being retracted
// do not if the FH is the root of the context, it means it's already in the process of retraction
retractOrUpdateBelief( node, context, jtmsBeliefSet.getFactHandle(), false, true );
}
} else if ( wasConflicting && !jtmsBeliefSet.isUndecided() ) {
insertBelief( node,
defEP.getObjectTypeConfigurationRegistry().getObjectTypeConf( defEP.getEntryPoint(), node.getObject() ),
jtmsBeliefSet,
wasNegated,
wasConflicting );
} else if ( primeChanged ) {
// we know there must be at least one more of the same type, as they are still in conflict
String value;
InternalFactHandle handle;
Object object = null;
if ( jtmsBeliefSet.isNegated() ) {
value = MODE.NEGATIVE.getId();
handle = jtmsBeliefSet.getNegativeFactHandle();
// Find the new node, and update the handle to it, Negatives iterate from the last
for ( LinkedListEntry<LogicalDependency> entry = (LinkedListEntry<LogicalDependency>) jtmsBeliefSet.getLast(); entry != null; entry = (LinkedListEntry<LogicalDependency>) entry.getPrevious() ) {
if ( entry.getObject().getValue().equals( value ) ) {
object = entry.getObject().getObject();
break;
}
}
} else {
value = MODE.POSITIVE.getId();
handle = jtmsBeliefSet.getPositiveFactHandle();
// Find the new node, and update the handle to it, Positives iterate from the front
for ( LinkedListEntry<LogicalDependency> entry = (LinkedListEntry<LogicalDependency>) jtmsBeliefSet.getFirst(); entry != null; entry = (LinkedListEntry<LogicalDependency>) entry.getNext() ) {
if ( entry.getObject().getValue().equals( value ) ) {
object = entry.getObject().getObject();
break;
}
}