[rules-users] are for loops possible in drools

Edson Tirelli tirelli at post.com
Sat Jul 31 12:23:17 EDT 2010


    Try:

when
    TestClass( $list : listOfStrings )
    Number( $count : intValue ) from accumulate(
           String( this matches "^a.b.*$" ) from $list,
           count(1) )
then
    // $count has number of matching strings
end

    []s
    Edson


2010/7/31 ceemh3 <martin_henderson at hotmail.com>

>
>
> does anybody know if there is a way to do for loops in drools ?.
>
> I am trying to loop through a list of string to see if one of the strings
> matches a pattern e.g.
>
> def listOfStrings = ['a','a.b','a.b.c']
>
> for(String s:listOfStrings){
>  if(s matches "^a.b.*$"){
>  return true
>  }
> }
>
> I have written the following rule based on what documentation I could find,
> but I dont think the syntax is correct
>
> rule "Matcher"
>   when
>      TestClass : TestClass(($s matches "^a.b.*$") from listOfStrings,
> count($s))
>   then
>      TestClass.setResponse( "Condition is True !!" );
> end
>
> I am finding it hard to find good documentation on the drl language
>
> I would appreciate any help that anybody can give me
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/are-for-loops-possible-in-drools-tp1011729p1011729.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100731/237ea089/attachment.html 


More information about the rules-users mailing list