Package org.drools.reteoo

Source Code of org.drools.reteoo.ModifyPreviousTuples

/*
* Copyright 2010 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.reteoo;

import org.drools.common.InternalWorkingMemory;
import org.drools.common.LeftTupleSets;
import org.drools.common.Memory;
import org.drools.common.MemoryFactory;
import org.drools.common.NetworkNode;
import org.drools.reteoo.AccumulateNode.AccumulateMemory;
import org.drools.reteoo.LeftInputAdapterNode.LiaNodeMemory;
import org.drools.spi.PropagationContext;

public class ModifyPreviousTuples {
    private LeftTuple                       leftTuple;
    private RightTuple                      rightTuple;
    private boolean                         unlinkingEnabled;

    public ModifyPreviousTuples(LeftTuple leftTuple,                               
                                RightTuple rightTuple,
                                boolean unlinkingEnabled) {
        this.leftTuple = leftTuple;
        this.rightTuple = rightTuple;
        this.unlinkingEnabled = unlinkingEnabled;
    }
   
    public LeftTuple peekLeftTuple() {
        return this.leftTuple;
    }
   
    public RightTuple peekRightTuple() {
        return this.rightTuple;
    }

    public void removeLeftTuple() {
        LeftTuple current = this.leftTuple;
        current.setLeftParentPrevious( null );
        this.leftTuple = current.getLeftParentNext();
        current.setLeftParentNext( null );       
    }
   
    public void removeRightTuple() {
        RightTuple current = this.rightTuple;
        current.setHandlePrevious( null );
        this.rightTuple = current.getHandleNext();
        current.setHandleNext( null );      
    }       
   
    public void retractTuples(PropagationContext context,
                              InternalWorkingMemory wm) {
        // retract any remaining LeftTuples
        if ( this.leftTuple != null ) {
            for ( LeftTuple current = this.leftTuple; current != null; current = (LeftTuple) current.getLeftParentNext() ) {
                if ( unlinkingEnabled ) {
                    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) current.getLeftTupleSink().getLeftTupleSource();
                    LiaNodeMemory lm = ( LiaNodeMemory wm.getNodeMemory( liaNode );
                    LeftInputAdapterNode.doDeleteObject( current, context, lm.getSegmentMemory(), wm, liaNode, lm );
                } else {
                    current.getLeftTupleSink().retractLeftTuple( current,
                                                                 context,
                                                                 wm );                   
                }
            }
        }
       
        // retract any remaining RightTuples
        if (this.rightTuple != null ) {
            for ( RightTuple current = this.rightTuple; current != null; current = (RightTuple) current.getHandleNext() ) {
                BetaNode node = ( BetaNode ) current.getRightTupleSink();
                if ( unlinkingEnabled) {
                    BetaMemory bm = BetaNode.getBetaMemory( node, wm );
                    BetaNode.doDeleteRightTuple( current, wm, bm );                   
                } else {
                    node.retractRightTuple( current,
                                            context,
                                            wm );
                }
            }
        }
    }

}
TOP

Related Classes of org.drools.reteoo.ModifyPreviousTuples

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.