Пример #1
0
 public static boolean valuesEqual(Value val1, Value val2) {
   if (val1 == null) {
     return val2 == null;
   }
   if (val2 == null) {
     return false;
   }
   if (val1 instanceof StringReference && val2 instanceof StringReference) {
     return ((StringReference) val1).value().equals(((StringReference) val2).value());
   }
   return val1.equals(val2);
 }
Пример #2
0
  /**
   * Run all this node's tests on two tokens. This routine assumes that the right token has only one
   * fact in it, which is true at this time!
   */
  boolean runTests(Token lt, Token rt, Token token) throws ReteException {
    int ntests = tests.length;

    ValueVector rf = rt.facts[0];

    for (int i = 0; i < ntests; i++) {

      if (tests[i] instanceof Test2) {
        Test2 t = (Test2) tests[i];
        ValueVector lf = lt.facts[t.token_idx];

        if (lf == null) continue;

        int lidx = t.left_idx;
        int ridx = t.right_idx;
        int lsubidx = t.left_sub_idx;
        int rsubidx = t.right_sub_idx;

        switch (t.test) {
          case Test2.NEQ:
          case Test2.EQ:
            {
              Value v1, v2;
              ValueVector slot;

              if (lsubidx != -1) // i.e., first variable is in a multislot
              v1 = lf.get(lidx).ListValue().get(lsubidx);
              else v1 = lf.get(lidx);

              if (rsubidx != -1) // i.e., first variable is in a multislot
              v2 = rf.get(ridx).ListValue().get(rsubidx);
              else v2 = rf.get(ridx);

              boolean retval = v1.equals(v2);
              if (t.test == Test2.EQ && !retval) return false;
              else if (t.test == Test2.NEQ && retval) return false;
            }
            break;

          default:
            throw new ReteException(
                "Node2::runTests", "Test2 type not supported", String.valueOf(t.test));
        }
      } else { // Test1
        // this is a function call! if it evals to Funcall.TRUE(),
        // the test passed; FALSE(), it failed.
        Test1 t = (Test1) tests[i];
        Value value = t.slot_value;
        switch (t.test) {
          case Test1.EQ:
            if (!Funcall.Execute(Eval(value, token), engine.global_context())
                .equals(Funcall.TRUE())) return false;
            break;
          case Test2.NEQ:
            if (Funcall.Execute(Eval(value, token), engine.global_context()).equals(Funcall.TRUE()))
              return false;
            break;
          default:
            throw new ReteException(
                "Node2::runTests", "Test2 type not supported", String.valueOf(t.test));
        }
      }
    }
    return true;
  }