📄 leftinputadapternode.java
字号:
}
}
memory.put( handle,
list );
}
/**
* Retract an existing <code>FactHandleImpl</code> by placing it in a new <code>ReteTuple</code> before
* proagating to the <code>TupleSinks</code>
*
* @param handle
* The <code>FactHandle/code> to retract.
* @param context
* The <code>PropagationContext</code> of the <code>WorkingMemory<code> action.
* @param workingMemory
* the <code>WorkingMemory</code> session.
*/
public void retractObject(final DefaultFactHandle handle,
final PropagationContext context,
final ReteooWorkingMemory workingMemory) {
final Map memory = (Map) workingMemory.getNodeMemory( this );
final LinkedList list = (LinkedList) memory.remove( handle );
// the handle might have been filtered out by the binder
if ( list != null ) {
int i = 0;
for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) {
((TupleSink) getTupleSinks().get( i++ )).retractTuple( (ReteTuple) ((LinkedListObjectWrapper) node).getObject(),
context,
workingMemory );
}
}
}
public void modifyObject(final DefaultFactHandle handle,
final PropagationContext context,
final ReteooWorkingMemory workingMemory) {
final Map memory = (Map) workingMemory.getNodeMemory( this );
if ( (this.binder == null) || (this.binder.isAllowed( handle,
null,
workingMemory )) ) {
final LinkedList list = (LinkedList) memory.get( handle );
if ( list != null ) {
// already existed, so propagate as a modify
int i = 0;
for ( LinkedListNode node = list.getFirst(); node != null; node = node.getNext() ) {
((TupleSink) getTupleSinks().get( i++ )).modifyTuple( (ReteTuple) ((LinkedListObjectWrapper) node).getObject(),
context,
workingMemory );
}
} else {
// didn't existed, so propagate as an assert
this.createAndAssertTuple( handle,
context,
workingMemory,
memory );
}
} else {
final LinkedList list = (LinkedList) memory.remove( handle );
if ( list != null ) {
int i = 0;
for ( LinkedListNode node = list.getFirst(); node != null; node = node.getNext() ) {
((TupleSink) getTupleSinks().get( i++ )).retractTuple( (ReteTuple) ((LinkedListObjectWrapper) node).getObject(),
context,
workingMemory );
}
}
}
}
/* (non-Javadoc)
* @see org.drools.reteoo.BaseNode#updateNewNode(org.drools.reteoo.WorkingMemoryImpl, org.drools.spi.PropagationContext)
*/
public void updateNewNode(final ReteooWorkingMemory workingMemory,
final PropagationContext context) {
this.attachingNewNode = true;
// Get the newly attached TupleSink
final TupleSink sink = (TupleSink) getTupleSinks().get( getTupleSinks().size() - 1 );
// Iterate the memory and assert all tuples into the newly attached TupleSink
final Map memory = (Map) workingMemory.getNodeMemory( this );
for ( final Iterator it = memory.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
DefaultFactHandle handle = (DefaultFactHandle) entry.getKey();
LinkedList list = (LinkedList) entry.getValue();
ReteTuple newTuple = new ReteTuple( handle );
list.add( new LinkedListObjectWrapper( newTuple ) );
sink.assertTuple( newTuple,
context,
workingMemory );
}
this.attachingNewNode = false;
}
public void remove(final BaseNode node,
final ReteooWorkingMemory[] workingMemories) {
if ( !node.isInUse() ) {
final int index = this.getTupleSinks().indexOf( node );
getTupleSinks().remove( node );
// as we store the tuples propagated to each sink,
// we need to remove all these tuples from memory
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
final Map memory = (Map) workingMemories[i].getNodeMemory( this );
for ( final Iterator it = memory.values().iterator(); it.hasNext(); ) {
final LinkedList tuples = (LinkedList) it.next();
LinkedListObjectWrapper wrapper = (LinkedListObjectWrapper) tuples.getFirst();
for ( int j = 0; j < index; j++ ) {
wrapper = (LinkedListObjectWrapper) wrapper.getNext();
}
tuples.remove( wrapper );
}
}
}
removeShare();
if ( !this.isInUse() ) {
for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
workingMemories[i].clearNodeMemory( this );
}
}
this.objectSource.remove( this,
workingMemories );
}
/**
* LeftInputAdapter uses a HashMap for memory. The key is the received <code>FactHandleImpl</code> and the
* created <code>ReteTuple</code> is the value.
*/
public Object createMemory(final RuleBaseConfiguration config) {
return new HashMap();
}
public int hashCode() {
return this.objectSource.hashCode();
}
public boolean equals(final Object object) {
if ( object == this ) {
return true;
}
if ( object == null || object.getClass() != LeftInputAdapterNode.class ) {
return false;
}
final LeftInputAdapterNode other = (LeftInputAdapterNode) object;
if ( this.binder == null ) {
return this.objectSource.equals( other.objectSource ) && other.binder == null;
} else {
return this.objectSource.equals( other.objectSource ) && this.binder.equals( other.binder );
}
}
/**
* @inheritDoc
*/
public List getPropagatedTuples(final ReteooWorkingMemory workingMemory,
final TupleSink sink) {
final Map memory = (Map) workingMemory.getNodeMemory( this );
final int index = this.getTupleSinks().indexOf( sink );
final List propagatedTuples = new ArrayList();
for ( final Iterator it = memory.values().iterator(); it.hasNext(); ) {
final LinkedList tuples = (LinkedList) it.next();
LinkedListObjectWrapper wrapper = (LinkedListObjectWrapper) tuples.getFirst();
for ( int i = 0; i < index; i++ ) {
wrapper = (LinkedListObjectWrapper) wrapper.getNext();
}
propagatedTuples.add( wrapper.getObject() );
}
return propagatedTuples;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -