[rules-users] Handling ArrayList objects in rule conditions

Steven Williams stevenw at objectconsulting.com.au
Mon Feb 19 17:41:06 EST 2007


Hi,

To check the length of a Box object use:

when
$box : Box(length == 10)
then
...

There are two ways to iterate over your list depending the version you are
using. Assuming BoxList has a property boxes returning a collection. In
3.0.5 you can use:

when
BoxList($b : boxes)
then
for(Iterator it = $b.iterator();it.hasNext();) {
assert( it.next());
}
end

On trunk you can use the from keyword to combine the iteration and the rule

when
$list : BoxList()
$box : Box(length == 10) from $list.getBoxes()
then
...

cheers
Steve

On 2/19/07, Diwakar <raja_diwakar at yahoo.co.in> wrote:
>
>
> I am a beginner.
> I have an ArrayList object - Say BoxList Object  containing 10 Box objects
> .
> I need to check if the length of the bos is 10cm on each box object.
>
>
> How do I write this as rule condition.
> Is there any way to write the rule for iterating the BoxList to check the
> length of each box
>
> Can you please help?
>
> --
> View this message in context:
> http://www.nabble.com/Handling-ArrayList-objects-in-rule-conditions-tf3251245.html#a9037969
> 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
>



-- 
Steven Williams

Supervising Consultant

Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
stevenw at objectconsulting.com.au
www.objectconsulting.com.au

consulting | development | training | support
our experience makes the difference
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070220/e1826c53/attachment.html 


More information about the rules-users mailing list