<div dir="ltr"><br>&nbsp;&nbsp; Hi all, sorry for the long absence. I&#39;m back, but I know no one noticed, anyway... ;)<br><br>&nbsp;&nbsp; Allen, not really. Collections usually are not asserted as standalone facts because they lack semantic meaning. They are abstractions, if you know what I mean.<br>
<br>&nbsp;&nbsp; So, in your case, you can write patterns like this:<br><br>Foo( names contains &quot;abc&quot; )<br>Foo( names not contains &quot;abc&quot; )<br><br>&nbsp;&nbsp;&nbsp; Now, a regexp will act over Strings, not collections. So if you want to write a rule that acts on each name that matches a regexp, you must &quot;iterate&quot; over your collections elements using the &quot;from&quot; CE:<br>
<br>Foo( $names : names )<br>String( this matches &quot;error.*&quot; ) from $names<br><br>&nbsp;&nbsp;&nbsp; Now, if you want the rule to re-create a new list containing only the names matching a pattern, THEN you may use the collect CE to create a collection:<br>
<br><font face="Arial, sans-serif" size="3"><font face="Courier New, monospace" size="2">$foo : </font></font>Foo( $names : names )<br>
<font face="Arial, sans-serif" size="3"><font face="Courier New, monospace" size="2">$foundThese : </font></font>ArrayList( ) from collect( String( this matches &quot;error.*&quot; ) from $names )<br><br>&nbsp;&nbsp; You may also filter your resulting collection to only fire the rule when there are actual elements. Just for the sake of examples, since you are already binding $foo, you don&#39;t need to bind $names too:<br>
<br><font face="Arial, sans-serif" size="3"><font face="Courier New, monospace" size="2">$foo : </font></font>Foo( )<br>

<font face="Arial, sans-serif" size="3"><font face="Courier New, monospace" size="2">$foundThese : </font></font>ArrayList( size &gt; 0 ) from collect( String( this matches &quot;error.*&quot; ) from $foo.names )<br>
<br>&nbsp;&nbsp;&nbsp;
Happy drooling,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br><br><div class="gmail_quote">2008/7/15 Bagwell, Allen F &lt;<a href="mailto:afbagwe@sandia.gov">afbagwe@sandia.gov</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">







<div>
<font face="Arial, sans-serif" size="3">
<div>&nbsp;</div>
<div><font size="2">I&#39;m going through the Drools documentation regarding the use of lists and other collections. I want to make sure my understanding is correct.</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">So if I have a class:</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font face="Courier New, monospace" size="2">public class Foo {</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; private int x;</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; private int y;</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; private List&lt;String&gt; names = ArrayList&lt;String&gt;();</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; public List&lt;String&gt; getNames() {return names;}</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; // appropriate getters/setters for the int fields ...</font></div>
<div><font face="Courier New, monospace" size="2">}</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;</font></div>
<div><font size="2">With this I can insert a Foo object into working memory. I can even make the int fields dynamic facts with the appropriate addition of &quot;bean-ifying&quot; code.</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">For the List, however, I need to insert it separately into working memory in order to make use of Drools&#39; rule language (&#39;contains&#39; ,etc.)? I&#39;m assuming that doesn&#39;t come free because I have to insert my own custom class objects if they
are included via composition in a larger fact!</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">Also, I&#39;m guessing the Collection type classes cannot be dynamic facts? Meaning if I modify my List with add, remove,&nbsp; clear, etc., I must explicitly call update in my code on the List fact in order to alert Drools to a change in the List,
correct? </font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">So then the question also comes up as to how I would write a rule that looks for all instances of Strings in the List that match against a given regex expression. I&#39;ve not been successful at figuring this out...</font></div>

<div><font size="2">&nbsp;</font></div>
<div><font face="Courier New, monospace" size="2">Rule &quot;when a Foo List is modified, get all Strings in it that start with &#39;error&#39;&quot;</font></div>
<div><font face="Courier New, monospace" size="2">when</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; $foo : Foo($names : names)</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; $foundThese : ArrayList() from collect(??? matches &quot;error.*&quot; from $names)</font></div>
<div><font face="Courier New, monospace" size="2">then</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;&nbsp; // act on $foo and $foundThese</font></div>
<div><font face="Courier New, monospace" size="2">&nbsp;</font></div>
<div><font size="2">I know that rule is NOT correct, but I&#39;m not sure how I&#39;m supposed to access an immutable object inside a collection. The examples in the documentation show how to get at mutable class objects.</font></div>

<div><font size="2">&nbsp;</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">Thanks!</font></div>
<div><font size="2">-Allen</font></div>
<div style="margin-top: 5pt; margin-bottom: 5pt;"><font size="2">&nbsp;</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">&nbsp;</font></div>
</font>
</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><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>
</div>