[rules-users] Equality vs Equality

H.C. canterburry at gmail.com
Mon Nov 1 17:41:14 EDT 2010


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-tp1824587p1824587.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list