Jess doesn't have any special support for collections as JavaBeans properties, and in fact, I'd go so far as to say it doesn't work very well. There's no way for Jess to be notified when your List is modified by code outside of Jess, for example, or, as you note, if the objects it contains are modified.

If (and only if) the objects in the list support proper equals() methods, then you could call Rete.updateObject() to tell Jess that something in the object has changed, and that should work out properly.

On Mar 18, 2010, at 4:07 PM, Skeptic . wrote:



Hi,
Let's say I have this class wich instances will be added to a Rete engine :

public class A {
    public int getI() {        return i;    }
public List<B> getBs() { return Collections.unmodifiableList(bs); }
    private int i;    private List<B> bs;
A(int i) { this.i = i; this.bs = new ArrayList<B>(bs); bs.add(1); bs.add(2); bs.add(3); }
    public void change(int p) {        bs.add(new B(p));    }
}
And the following .clp file :
(defclass A xxx.yyy.zzz.A)
(defrule rule1  (A (i ?i) (bs ?bs))=>  (printout t "i:" ?i crlf)  )
(reset)
and the following test code :

Rete r = new Rete(); try { r.batch(".../TestJess.clp"); A a = new A(5);
       r.add(a);       r.run();
       a.change();
r.updateObject(a); r.run(); } catch (JessException e) { e.printStackTrace(); } The rule will fire twice, once with i=5 and once with i=6. However, if I comment the line where i is modified in the changemethod, the rule will only fire once, because even if the list is "modified", the value of bs is unchanged.

If the desired behavior is to have the rule firing twice, is there a way to have it ? In fact, I know that I can add the list itself in the engine and match it in the LHS, but I would prefer to avoid that.

Thanks.



                                        
_________________________________________________________________
Accès direct à Messenger depuis votre téléphone
http://go.microsoft.com/?linkid=9712962

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected] .
--------------------------------------------------------------------

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------

Reply via email to