コード例 #1
0
  /**
   * This method is used to pass an algorithm decorator factory that is used for tracing (for
   * example). See {@link #checkedRules(Object, Object[], IRuntimeEnv)} for full documentation
   *
   * @param target target object
   * @param params parameters of a test
   * @param env environment
   * @param decoratorFactory a decorator factory that will decorate an objects that are used to
   *     calculate a rule
   * @return iterator over <b>rule indexes</b> - integer iterator.
   * @see #checkedRules(Object, Object[], IRuntimeEnv)
   */
  protected final IIntIterator checkedRules(
      Object target,
      Object[] params,
      IRuntimeEnv env,
      DefaultAlgorithmDecoratorFactory decoratorFactory) {

    // Select rules set using indexed mode
    //
    //        ICondition[] conditions = table.getConditionRows();

    IIntIterator iterator = null;
    int conditionNumber = info.fromCondition;

    if (indexRoot == null) {
      iterator = info.makeRuleIterator();
    } else {

      ARuleIndex index = indexRoot;

      for (; conditionNumber <= info.toCondition; conditionNumber++) {
        index = decoratorFactory.create(index, table.getCondition(conditionNumber));

        Object testValue =
            evaluateTestValue(table.getCondition(conditionNumber), target, params, env);

        DecisionTableRuleNode node = index.findNode(testValue);

        if (!node.hasIndex()) {
          iterator = node.getRulesIterator();
          conditionNumber += 1;
          break;
        }

        index = node.getNextIndex();
      }
    }

    for (; conditionNumber <= info.toCondition; conditionNumber++) {

      ICondition condition = table.getCondition(conditionNumber);
      IConditionEvaluator evaluator = evaluators[conditionNumber];

      IIntSelector sel = evaluator.getSelector(condition, target, params, env);
      sel = decoratorFactory.create(sel, condition);

      iterator = iterator.select(sel);
    }

    return iterator;
  }
コード例 #2
0
  int[] collectRules() {
    if (nextIndex == null)
      throw new RuntimeException("Internal Error: nextIndex is null when rules is null");

    return nextIndex.collectRules();
  }