<br> Markus,<br><br> Can you plz open a JIRA for this?<br><br> Thank you,<br> Edson<br><br><div><span class="gmail_quote">2007/8/13, Markus Reitz <<a href="mailto:marreitz@yahoo.de">marreitz@yahoo.de</a>>:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br><br>I have a problem with a rule which uses a "!=" field<br>constraint. The following code illustrates the
<br>problem.<br><br>import org.drools.*;<br>import org.drools.compiler.*;<br>import org.drools.rule.Package;<br><br>import java.io.*;<br><br>public class DroolsTest {<br> private RuleBase rules;<br> private StatefulSession memory;
<br><br> public DroolsTest(File file) throws Exception {<br> rules =RuleBaseFactory.newRuleBase();<br> memory=rules.newStatefulSession();<br><br> rules.addPackage(loadPackage(file));<br> }<br><br> protected Package loadPackage(File file) throws
<br>IOException {<br> FileInputStream stream=null;<br><br> try {<br> stream=new FileInputStream(file);<br><br> return(loadPackage(stream));<br> }<br> finally {<br> if (stream!=null)<br> stream.close
();<br> }<br> }<br><br> protected Package loadPackage(InputStream stream)<br>throws IOException {<br> try {<br> PackageBuilder builder=new PackageBuilder();<br><br> builder.addPackageFromDrl(new<br>InputStreamReader(stream));
<br><br> return(builder.getPackage());<br> }<br> catch(Exception ex) {<br> throw new IOException();<br> }<br> }<br><br> public StatefulSession getSession() {<br> return(memory);<br> }<br><br> public static void main(String ... args) {
<br> try {<br> DroolsTest test=new DroolsTest(new<br>File(args[0]));<br><br> SpecialString first42 =new SpecialString("42");<br> SpecialString second42=new SpecialString("42");<br><br>
test.getSession().insert(new<br>SpecialString("World"));<br> test.getSession().insert(first42);<br> test.getSession().insert(second42);<br><br> System.out.println("Fact handle:<br>"+test.getSession().getFactHandle(first42));
<br> System.out.println("Fact handle:<br>"+test.getSession().getFactHandle(second42));<br><br> System.out.println("Firing rules ...");<br><br> test.getSession().fireAllRules();<br> }<br>
catch (Exception ex) {<br> ex.printStackTrace();<br> }<br> }<br>}<br><br>I'm inserting three different objects in the working<br>memory of the Drools 4 Engine. Two of the three<br>objects have the same text - "42". When I'm using the
<br>following rule<br><br> package test<br><br> rule "A test"<br><br> when<br> x : SpecialString()<br> y : SpecialString(this!=x)<br><br> then<br> System.out.println(x+"/"+y);<br>
end<br><br>I get the output<br><br> Fact handle: [fid:2:2:42[SpecialString@fde8da]]<br> Fact handle: [fid:3:3:42[SpecialString@e4d6ef]]<br> Firing rules ...<br> 42[SpecialString@e4d6ef]/World[SpecialString@faa824]<br>
World[SpecialString@faa824]/42[SpecialString@e4d6ef]<br> 42[SpecialString@fde8da]/World[SpecialString@faa824]<br> World[SpecialString@faa824]/42[SpecialString@fde8da]<br><br>which is not what I expect. Why are combinations of x
<br>and y with the two "42"-instances not listed, i.e.<br><br>Why doesn't the output contain<br><br> 42[SpecialString@e4d6ef]/42[SpecialString@fde8da]<br> 42[SpecialString@fde8da]/42[SpecialString@e4d6ef]<br>
<br>The class SpecialString uses the standard equals(...)<br>and hashCode(...) implementation, so these should be<br>based on the object references, not the content:<br><br>public class SpecialString {<br> private String text;
<br><br> public SpecialString(String text) {<br> this.text=text;<br> }<br><br> public String getText() {<br> return(text);<br> }<br><br> @Override public String toString() {<br> return(getText()+"["+super.toString()+"]");
<br> }<br>}<br><br>Best regards<br><br>Markus<br><br><br> Wissenswertes für Bastler und Hobby Handwerker. BE A BETTER HEIMWERKER! <a href="http://www.yahoo.de/clever">www.yahoo.de/clever</a><br>_______________________________________________
<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @
<a href="http://www.jboss.com">www.jboss.com</a>