If I understood it correctly and have not missed a comma or parenthesis:<br><br>rule &quot;level three&quot;<br>when<br>   $l0: Level0()<br>   $list1: List( size &gt; 0 ) <br>      from accumulate (Level1( $level1List: level1List) from $l0.level1List,<br>
        init( List l = new ArrayList(); )<br>        action( l.addAll($level1List); )<br>        return( l ) )<br>   $date: PartialDate()<br>      from accumulate (Level2((name in (&quot;name1&quot;, &quot;name2&quot;),$occurrence: occurrence) from $list1, <br>
          maxDate($occurence) )<br>then<br><br>-W<br><br><br>2011/10/5 Claes, Kenny [JRDBE - Non J&amp;J] &lt;<a href="mailto:kclaes@its.jnj.com">kclaes@its.jnj.com</a>&gt;<br>&gt;<br>&gt; I have a question regarding creating a list of items that are all in nested collections of my main object.<br>
&gt;<br>&gt; A high level overview of the model is like this:<br>&gt;<br>&gt;  <br>&gt;<br>&gt; public Level0 { <br>&gt;  private List&lt;Level1&gt; level1List; <br>&gt; } <br>&gt;<br>&gt;  <br>&gt;<br>&gt; public Level1 { <br>
&gt;  private List&lt;Level2&gt; level1List; <br>&gt; } <br>&gt;<br>&gt;  <br>&gt;<br>&gt; public Level2 { <br>&gt;  private Date occurence; <br>&gt; } <br>&gt;<br>&gt;  <br>&gt;<br>&gt; Now, I add objects of type 0 in the working memory and for each of those objects, I want to find the latest occurrence of a certain Level2, regardless of which level1 they belong to.<br>
&gt;<br>&gt;  <br>&gt;<br>&gt; If there’s only 2 levels and I want to find the latest occurrence of Level2’s with a certain name, I can write:<br>&gt;<br>&gt;  <br>&gt;<br>&gt; rule &quot;latest level 1&quot;<br>&gt;<br>&gt; when<br>
&gt;<br>&gt;     $l0: Level0()<br>&gt;<br>&gt;     $date: Date() from accumulate (Level1(name in (&quot;name1&quot;, &quot;name2&quot;), $occurence: occurence) from $l0.level1List, maxDate($occurence))<br>&gt;<br>&gt; then<br>
&gt;<br>&gt;       // register fact that latest occurrence of name1/name2 level1 was on $date<br>&gt;<br>&gt; end<br>&gt;<br>&gt;  <br>&gt;<br>&gt; Now, with 3 levels, since I obviously can’t replace $l0.level1List with $l0.level1List.level2List, is there a way to create an intermediate list that will contain all Level2 objects? No filtering needs to take place on Level1, but if there’s a way to do that too, that would be nice.<br>
&gt;<br>&gt;  <br>&gt;<br>&gt; What I currently have is this:<br>&gt;<br>&gt;  <br>&gt;<br>&gt; rule &quot;latest level 2&quot;<br>&gt;<br>&gt; when<br>&gt;<br>&gt; $l0: Level0()<br>&gt;<br>&gt; $l1: Level1() from $l1.level1List<br>
&gt;<br>&gt; $l2List: List(size &gt; 0) from collect( Level2(name in ((&quot;name1&quot;, &quot;name2&quot;)) from $l1.level2List )<br>&gt;<br>&gt;       $date: PartialDate() from accumulate (Level2( $occurence: occurence) from $l2List, maxDate($occurence))<br>
&gt;<br>&gt; then<br>&gt;<br>&gt;       // register fact that latest occurrence of name1/name2 level2 was on $date<br>&gt;<br>&gt; end<br>&gt;<br>&gt;  <br>&gt;<br>&gt; But this does not work as it treats each Level1 seperately: it creates a “latest occurrence” for all accumulated level2 facts within a level1, instead of one for the entire set of level 2’s ‘owned’ by the level0 object.<br>
&gt;<br>&gt;  <br>&gt;<br>&gt; Any suggestions?<br>&gt;<br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>&gt;<br><br>