<div dir="ltr"><b>Hello,<br><br>I tried this but it still loops:<br><br><br>&nbsp;&nbsp;&nbsp; public boolean equals(Object o) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(o instanceof OutputObject) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; OutputObject other = (OutputObject)o;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (this.type != other.type) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (this.type == OutputObject.Type.LEVEL) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (this.getStringPropertyValue(OutputObject.SEGMENTNAME) != other.getStringPropertyValue(OutputObject.SEGMENTNAME)) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return true;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>
</b><b>&nbsp;&nbsp;&nbsp; public int hashCode() {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int hash = 37;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hash ^= type.hashCode();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return hash;<br>&nbsp;&nbsp;&nbsp; }<br><br></b><b>If I understand it right I have to overwrite check the equality of
all fields which must be identical to for two objects which are seen
equal. Fields which can have different values for equal objects don&#39;t
have to be checked in the equals()-method. In my rule there is an
update of the OutputObject:<br><br></b><b>rule &quot;Assess Level&quot;<br>&nbsp; dialect &quot;java&quot;<br>&nbsp; no-loop<br>&nbsp;&nbsp;&nbsp; when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; io: InputObject(type == InputObject.Type.OBSERVATION)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ewhsMap: HashMap() from io.getMapParameters()<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ewhs: HashMap() from ewhsMap.get(&quot;EWHS&quot;)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; segment: String() from ewhs.keySet()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; oo: OutputObject (type == OutputObject.Type.LEVEL, stringParameters[&quot;SEGMENTNAME&quot;] == segment)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ewh: Number() from ewhs.get(segment)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eval(ewh.doubleValue() &gt;= 0.5 &amp;&amp; ewh.doubleValue() &lt; 3.0)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; oo.setIntPropertyValue(OutputObject.SEGMENTLEVEL, &quot;WARNING&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; update(oo);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( &quot;Warning Segment &quot; + segment + &quot; has warning level WARNING&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>end<br><br>Thomas<br><br></b><b>Greg Barton</b> 
    <a href="mailto:rules-users%40lists.jboss.org?Subject=%5Brules-users%5D%20Problems%20with%20looping&amp;In-Reply-To=d8ac9d7f0808010810x45d911d7x98f70b7cd7ab9b6%40mail.gmail.com" title="[rules-users] Problems with looping">greg_barton at yahoo.com
       </a><br>
    <i>Fri Aug  1 12:03:55 EDT 2008<br><br></i>Did you implement equals() and hashCode()?<br><br>Implementing them isn&#39;t hard.&nbsp; Implementing them well<br>can be tricky, but for these purposes a simple<br>implementation will do.&nbsp; Basically, with equals() you<br>
want to compare the stuff contained in the objects. <br>With hashCode() you want to produce an integer that<br>can be used in HashMaps.&nbsp; The only restriction is<br>that, if o1.equals(o2) == true, then o1.hashCode() ==<br>
o2.hashCode().&nbsp; (The reverse is not necessarily true.)<br><br>The easiest way to implement these is to just compare<br>the fields that define the state of your object:<br><br>public class Foo {<br><br>&nbsp; int bar;<br>&nbsp; String bas;<br>
<br>&nbsp; public boolean equals(Object o) {<br>&nbsp;&nbsp;&nbsp; if(o instanceof Foo) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Foo other = (Foo)o;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return bar == other.bar &amp;&amp; bas != null &amp;&amp;<br>bas.equals(other.bas);<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br>
&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; public int hashCode() {<br>&nbsp;&nbsp;&nbsp; int hash = 37;<br>&nbsp;&nbsp;&nbsp; hash ^= bar;<br>&nbsp;&nbsp;&nbsp; if(bas != null) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hash ^= bas.hashCode();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; return hash;<br>&nbsp; }<br>}<br><br>One good way to make this easier is to use the jakarta<br>
commons EqualsBuilder and HashCodeBuilder classes. <br>They also help you implement them &quot;well,&quot; especially<br>hashCode.<br><br>GreG<br></div>