⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenevaluator.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @return
     * @throws Exception
     */
    final static boolean processAfterAllPositiveConstraintOk( final LeapsTuple tuple,
                                                              final LeapsRule leapsRule,
                                                              final LeapsWorkingMemory workingMemory ) {
        if (leapsRule.containsEvalConditions( )
                && !TokenEvaluator.evaluateEvalConditions( leapsRule, tuple, workingMemory )) {
            return false;
        }
        if (leapsRule.containsExistsColumns( )) {
            TokenEvaluator.evaluateExistsConditions( tuple, leapsRule, workingMemory );
        }
        if (leapsRule.containsNotColumns( )) {
            TokenEvaluator.evaluateNotConditions( tuple, leapsRule, workingMemory );
        }
        // put tuple onto fact tables that might affect activation status
        // via exists or not conditions
        final Class[] classes = leapsRule.getExistsNotColumnsClasses( );
        for (int i = 0, length = classes.length; i < length; i++) {
            workingMemory.getFactTable( classes[i] ).addTuple( tuple );
        }

        // 
        if (tuple.isReadyForActivation( )) {
            // let agenda to do its work
            workingMemory.assertTuple( tuple );
            return true;
        }
        else {
            return false;
        }
    }

    /**
     * checks is EvalConditions isAllowed()
     * 
     * @param leapsRule
     * @param tuple
     * @param workingMemory
     * @return
     * @throws Exception
     */
    private final static boolean evaluateEvalConditions( final LeapsRule leapsRule,
                                                         final LeapsTuple tuple,
                                                         final LeapsWorkingMemory workingMemory ) {
        final EvalCondition[] evals = leapsRule.getEvalConditions( );
        for (int i = 0; i < evals.length; i++) {
            if (!evals[i].isAllowed( tuple, workingMemory )) {
                return false;
            }
        }
        return true;
    }

    /**
     * Check if any of the negative conditions are satisfied success when none
     * found
     * 
     * @param memory
     * @param token
     * @return success
     * @throws Exception
     */
    final static void evaluateNotConditions( final LeapsTuple tuple,
                                             final LeapsRule rule,
                                             final LeapsWorkingMemory workingMemory ) {
        final ColumnConstraints[] not = rule.getNotColumnConstraints( );
        for (int i = 0, length = not.length; i < length; i++) {
            final ColumnConstraints constraint = not[i];
            // scan table starting at start fact handle
            final TableIterator tableIterator = workingMemory.getFactTable( constraint.getClassType( ) )
                                                             .reverseOrderIterator( );
            // stops if exists
            boolean done = false;
            while (!done && tableIterator.hasNext( )) {
                final LeapsFactHandle factHandle = (LeapsFactHandle) tableIterator.next( );
                // check constraint conditions
                if (constraint.isAllowed( factHandle, tuple, workingMemory )) {
                    tuple.setBlockingNotFactHandle( factHandle, i );
                    factHandle.addNotTuple( tuple, i );
                    done = true;
                }
            }
        }
    }

    /**
     * To evaluate conditions above the water line that is supplied in the first
     * argument
     * 
     * @param startFactHandle
     * @param index
     * @param tuple
     * @param rule
     * @param workingMemory
     */
    final static void evaluateNotCondition( final LeapsFactHandle startFactHandle,
                                            final int index,
                                            final LeapsTuple tuple,
                                            final LeapsWorkingMemory workingMemory ) {
        final LeapsRule rule = tuple.getLeapsRule( );
        // scan table starting at start fact handle
        final ColumnConstraints constraint = rule.getNotColumnConstraints( )[index];
        final TableIterator tableIterator = workingMemory.getFactTable( constraint.getClassType( ) )
                                                         .iteratorFromPositionToTableEnd( startFactHandle );
        // stops if exists
        boolean done = false;
        while (!done && tableIterator.hasNext( )) {
            final LeapsFactHandle factHandle = (LeapsFactHandle) tableIterator.next( );
            // check constraint conditions
            if (constraint.isAllowed( factHandle, tuple, workingMemory )) {
                tuple.setBlockingNotFactHandle( factHandle, index );
                factHandle.addNotTuple( tuple, index );
                done = true;
            }
        }
    }

    /**
     * Check if any of the exists conditions are satisfied
     * 
     * @param tuple
     * @param memory
     * @throws Exception
     */
    private final static void evaluateExistsConditions( final LeapsTuple tuple,
                                                        final LeapsRule rule,
                                                        final LeapsWorkingMemory workingMemory ) {
        final ColumnConstraints[] exists = rule.getExistsColumnConstraints( );
        for (int i = 0, length = exists.length; i < length; i++) {
            final ColumnConstraints constraint = exists[i];
            // scan table starting at start fact handle
            final TableIterator tableIterator = workingMemory.getFactTable( constraint.getClassType( ) )
                                                             .reverseOrderIterator( );
            // stop if exists
            boolean done = false;
            while (!done && tableIterator.hasNext( )) {
                final LeapsFactHandle factHandle = (LeapsFactHandle) tableIterator.next( );
                // check constraint conditions
                if (constraint.isAllowed( factHandle,
                                           tuple,
                                           workingMemory ) ) {
                    tuple.setExistsFactHandle( factHandle,
                                               i );
                    factHandle.addExistsTuple( tuple,
                                               i );
                    done = true;
                }
            }
        }
    }

    /**
     * To evaluate conditions above the water line that is supplied in the first
     * argument
     * 
     * @param startFactHandle
     * @param index
     * @param tuple
     * @param rule
     * @param workingMemory
     */
    final static void evaluateExistsCondition( final LeapsFactHandle startFactHandle,
                                               final int index,
                                               final LeapsTuple tuple,
                                               final LeapsWorkingMemory workingMemory ) {
        final LeapsRule rule = tuple.getLeapsRule( );
        // scan table starting at start fact handle
        final ColumnConstraints constraint = rule.getExistsColumnConstraints( )[index];
        final TableIterator tableIterator = workingMemory.getFactTable( constraint.getClassType( ) )
                                                         .iteratorFromPositionToTableEnd( startFactHandle );
        // stop if exists
        boolean done = false;
        while (!done && tableIterator.hasNext( )) {
            final LeapsFactHandle factHandle = (LeapsFactHandle) tableIterator.next( );
            // check constraint conditions
            if (constraint.isAllowed( factHandle, tuple, workingMemory )) {
                tuple.setExistsFactHandle( factHandle, index );
                factHandle.addExistsTuple( tuple, index );
                done = true;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -