1. eval( $config1 != $config2 ) compares the memory reference
2. this == $config1 is the same thing as eval( $config2.equals($config1) )
The above is correct, except that:
this == $config1
Uses indexing and
eval( $config2.equals($config1) )
Does not. So if you change your object and does not tell the
engine (using modify or update), whenever the engine decides to
"re-evaluate" the condition, the indexed condition will not "see" the
change, while the eval() will see the change (as it is java code
executing, not the engine). That is why you should always notify the
engine when changing object properties.
From the top of my mind, that is the only difference.
Now, if you don't want duplicate objects in your session, can't
you simply configure the engine to use AssertBehavior.EQUALITY instead
of the default AssertBehavior.IDENTITY?
KnowledgeBaseConfiguration conf = ....
conf.setOption( AssertBehaviorOption.EQUALITY );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( conf );
Edson
2010/11/1 H.C. <canterburry(a)gmail.com>:
>
> We have the potential for duplicate data and so we have some rules we wrote
> to de-dupe things. We are attempting the check if we have two different
> objects in memory but they equal each other by equals(). We have overridden
> equal() and hashCode() in all our classes.
>
> I came a cross two variations of the same de-duping rule that yields
> different results but to me seems logically equivalent. How do these two
> rules apply equality differently?
>
> v1:
> <code>rule "Ensure no ConfigurationEntities are duplicates of
others"
> when
> $config1 : ConfigurationEntity( )
> $config2 : ConfigurationEntity( eval( $config1 != $config2 )
&& this ==
> $config1 )
> then
> errorList.add( new ConfigError(
ConfigErrorCodes.DUPLICATE_CONFIGURATION,
> $config1 ));
> end</code>
>
> v2:
> <code>rule "Ensure no ConfigurationEntities are duplicates of
others"
> when
> $config1 : ConfigurationEntity( )
> $config2 : ConfigurationEntity( )
> eval( $config1 != $config2 && $config2.equals($config1) )
> then
> errorList.add( new ConfigError(
ConfigErrorCodes.DUPLICATE_CONFIGURATION,
> $config1 ));
> end</code>
>
> Our understanding is that:
1. eval( $config1 != $config2 ) compares the memory reference
2. this == $config1 is the same thing as eval( $config2.equals($config1) )
>
> Given our disparate results, our assumptions must be wrong somewhere. Would
> very much appreciate some insight.
> --
> View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Equality-vs-Equality-...
> Sent from the Drools - User mailing list archive at
Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @
www.jboss.com