>    By default, drools uses identity checks when
> asserting/modifying/retracting objects into/from working memory.

I just experienced otherwise :/ It does rely on equals/hashcode of the facts: When I overwrite Match with custom equals/hashcode methods, I get a NullPointerException:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.drools.reteoo.ReteooWorkingMemory.modifyObject(ReteooWorkingMemory.java:90) at org.drools.common.AbstractWorkingMemory.modifyObject(AbstractWorkingMemory.java:710) at net.sf.taseree.samples.travelingtournament.taseree.DayChangeMove.doMove(DayChangeMove.java:40)

on code like this:
        FactHandle matchHandle = workingMemory.getFactHandle(match);
        match.setDay(toDay);
        workingMemory.modifyObject(matchHandle, match);


When I leave it out the equals/hashcode method on Match,
it works perfectly.
Problem is I need a different equals/hashcode method on my Match objects, for the hashmaps I use myself.

Unlike Comparable and Comperator, there is no Equalitor class that I can give as an argument to my hashmap.


With kind regards,
Geoffrey De Smet


Edson Tirelli wrote:

   Geoffrey,

By default, drools uses identity checks when asserting/modifying/retracting objects into/from working memory.

   []s
   Edson

Geoffrey De Smet wrote:

Hi,

How does drools 3 use equals() (and hashCode()) ?


Here's my use case and why I am worrying about that:

A Match has a Long id, which identifies it (for database etc).
A number of Matches are asserted into the working memory.

A Match can be cloned, after which its properties
will differ from its clone,
but the id remains the same.
The clone is used for history
- a state in which the Match has been previously -
but isn't asserted into the working memory.
When the original Match is modified, the working memory is notified.


Outside of drools, I need to know when 2 matches with the same id are in the same state, which I of course want to do with a simple HashMap. So I want to override equals() (and hashCode()) so I can put them in that HashMap, and basically do something like this:
 if (id is the same || rest of state is also the same) {they are equal}

But I fear that that will mess up drools. I am right?





---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to