Without any conditions and constraints, this is just a simple computation<br>you could code in Java and invoke in some appropriate place. But I<br>suspect you haven't told us the whole story...<br><br>You don't say where this "list" is; so I assume it's a field in some other fact.<br>
<br>This code is absolutely untested.<br><br>rule count<br>when<br> ListHolder( $list : list )<br> $map: Map from accumulate ( XXX( $id: id, $type: type ) from $list,<br> init( Map map = new HashMap(); ),<br>
action( Integer count = map.get( $type );<br> count = Integer.valueOf( count == null ? 1 : count+1 );<br> map.put( $type, count ); ),<br> result( map ) )<br>then<br>
// ... use $map<br>end<br><br>-W<br><br><br><div class="gmail_quote">2010/11/5 Yaniv Itzhaki <span dir="ltr"><<a href="mailto:iyaniv@gmail.com">iyaniv@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Hi All,<div><br></div><div>I need to go over a not distinct list and count distinct each element in the list.</div><div><br></div><div>for example:</div><div><br></div><div>Object XXX { </div><div> int id;</div>
<div> String type;</div><div>}</div><div><br></div><div>XXX:</div><div>id type</div><div>1 A</div><div>2 B</div><div>3 A</div><div>4 C</div><div>5 C</div><div><br></div><div>The rule should be activated per type and give as a result the count of each type:</div>
<div>A 2</div><div>B 1</div><div>C 2</div><div><br></div><div>Thanks</div></div>
<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>