/** Side-effects, will add the created key to the handle. */ private EqualityKey createEqualityKey(InternalFactHandle handle) { EqualityKey key = new EqualityKey( handle ); handle.setEqualityKey( key ); return key; }
public static void writeTruthMaintenanceSystem(MarshallerWriteContext context) throws IOException { ObjectOutputStream stream = context.stream; ObjectHashMap assertMap = context.wm.getTruthMaintenanceSystem().getAssertMap(); EqualityKey[] keys = new EqualityKey[assertMap.size()]; org.drools.core.util.Iterator it = assertMap.iterator(); int i = 0; for ( org.drools.core.util.ObjectHashMap.ObjectEntry entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next(); entry != null; entry = (org.drools.core.util.ObjectHashMap.ObjectEntry) it.next() ) { EqualityKey key = (EqualityKey) entry.getKey(); keys[i++] = key; } Arrays.sort( keys, EqualityKeySorter.instance ); // write the assert map of Equality keys for ( EqualityKey key : keys ) { stream.writeShort( PersisterEnums.EQUALITY_KEY ); stream.writeInt( key.getStatus() ); InternalFactHandle handle = key.getFactHandle(); stream.writeInt( handle.getId() ); //context.out.println( "EqualityKey int:" + key.getStatus() + " int:" + handle.getId() ); if ( key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty() ) { for ( InternalFactHandle handle2 : key.getOtherFactHandle() ) { stream.writeShort( PersisterEnums.FACT_HANDLE ); stream.writeInt( handle2.getId() ); //context.out.println( "OtherHandle int:" + handle2.getId() ); } } stream.writeShort( PersisterEnums.END ); } stream.writeShort( PersisterEnums.END ); }
status = handle.getEqualityKey().getStatus(); key.removeFactHandle( handle ); if ( key.isEmpty() ) { tms.remove( key ); key = new EqualityKey( handle, status ); tms.put( key ); } else { key.addFactHandle( handle );
if ( key.getStatus() == EqualityKey.STATED ) { key.setStatus( EqualityKey.STATED ); tms.removeLogicalDependencies( handle ); } else { key.setStatus( EqualityKey.STATED ); } else { key.setStatus( EqualityKey.JUSTIFIED ); tms.addLogicalDependency( handle, tmsValue, if ( key.getStatus() == EqualityKey.JUSTIFIED ) { final InternalFactHandle justifiedHandle = key.getFactHandle(); tms.removeLogicalDependencies( justifiedHandle ); key.setStatus( EqualityKey.STATED ); handle = key.getFactHandle(); key.setStatus( EqualityKey.STATED ); handle = createHandle( object, typeConf ); handle.setEqualityKey( key ); key.addFactHandle( handle ); handle = createHandle( object, typeConf ); key.addFactHandle( handle );
if ( key.getStatus() == EqualityKey.JUSTIFIED ) { tms.removeLogicalDependencies( handle ); key.removeFactHandle( handle ); handle.setEqualityKey( null ); if ( key.isEmpty() ) { tms.remove( key );
public static void readTruthMaintenanceSystem( MarshallerReaderContext context ) throws IOException { ObjectInputStream stream = context.stream; TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem(); while (stream.readShort() == PersisterEnums.EQUALITY_KEY) { int status = stream.readInt(); int factHandleId = stream.readInt(); InternalFactHandle handle = (InternalFactHandle) context.handles.get( factHandleId ); // ObjectTypeConf state is not marshalled, so it needs to be re-determined ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.wm.getEntryPoint(), handle.getObject() ); if (!typeConf.isTMSEnabled()) { typeConf.enableTMS(); } EqualityKey key = new EqualityKey( handle, status ); handle.setEqualityKey( key ); while (stream.readShort() == PersisterEnums.FACT_HANDLE) { factHandleId = stream.readInt(); handle = (InternalFactHandle) context.handles.get( factHandleId ); key.addFactHandle( handle ); handle.setEqualityKey( key ); } tms.put( key ); } }
public int compare(EqualityKey key1, EqualityKey key2) { return key1.getFactHandle().getId() - key2.getFactHandle().getId(); } }
key.setStatus(EqualityKey.STATED); this.wm.getTruthMaintenanceSystem().put(key);
EqualityKey key = new EqualityKey( handle, _key.getStatus() ); handle.setEqualityKey( key ); for( Integer factHandleId : _key.getOtherHandleList() ) { handle = (InternalFactHandle) context.handles.get( factHandleId.intValue() ); key.addFactHandle( handle ); handle.setEqualityKey( key );
public int compare(EqualityKey key1, EqualityKey key2) { return key1.getFactHandle().getId() - key2.getFactHandle().getId(); } }
_key.setStatus(key.getStatus()); _key.setHandleId(key.getFactHandle().getId()); if (key.getOtherFactHandle() != null && !key.getOtherFactHandle().isEmpty()) { for (InternalFactHandle handle : key.getOtherFactHandle()) { _key.addOtherHandle(handle.getId());