[rules-users] Iterating string objects inside Arraylist

Esteban Aliverti esteban.aliverti at gmail.com
Wed Jul 17 03:17:36 EDT 2013


Hi,
Drools supports 'contains' and 'member of' operators. You can find more
information about them in the documentation.

Regards,



XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Blog @ http://ilesteban.wordpress.com


On Wed, Jul 17, 2013 at 7:49 AM, Ganesh R. <Ganesh_R04 at infosys.com> wrote:

>  I am a novice in Drools, sorry if this question is trivial and has
> already been discussed. I couldn’t find the direct method for implementing
> the below behavior. ****
>
> ** **
>
> I have a class like this. ****
>
> ** **
>
> public class Account { ****
>
>         public int balance; ****
>
>         public String id; ****
>
>         public List<String> types; ****
>
> // getter setters ****
>
> } ****
>
> ** **
>
> I am trying to check the following: ****
>
> Accounts having balance greater than $100 and types containing both
> Savings and Checking. ****
>
> ** **
>
> // Creating sample Facts in Java main ****
>
>         Account account = new Account(); ****
>
>         account.setBalance(100); ****
>
>         account.setId("A1"); ****
>
>         List<String> temp = new ArrayList<String>(); ****
>
>         temp.add("Savings"); ****
>
>         temp.add("Checking"); ****
>
>         account.setTypes(temp); ****
>
> ** **
>
> // Creating rules ****
>
> ** **
>
> rule "Sample" ****
>
> ** **
>
>     when     ****
>
>                 bat : Account(balance == 100) ****
>
>     then         ****
>
>        if (bat.getTypes().contains("Savings") &&
> bat.getTypes().contains("Checking")){ ****
>
>         System.out.println("I got this");     ****
>
>        } ****
>
> end ****
>
> ** **
>
> Is there more proficient ways to do this?? like checking the contents of
> the arraylist (types as per the above example) in rule i.e. in "when"
> instead of doing it in "then" ?? ****
>
> ** **
>
> Much appreciate your answers. ****
>
> Thank you! ****
>
> ** **
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
> for the use of the addressee(s). If you are not the intended recipient, please
> notify the sender by e-mail and delete the original message. Further, you are not
> to copy, disclose, or distribute this e-mail or its contents to any other person and
> any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
> every reasonable precaution to minimize this risk, but is not liable for any damage
> you may sustain as a result of any virus in this e-mail. You should carry out your
> own virus checks before opening the e-mail or attachment. Infosys reserves the
> right to monitor and review the content of all messages sent to or from this e-mail
> address. Messages sent to or from this e-mail address may be stored on the
> Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130717/e27d3afe/attachment-0001.html 


More information about the rules-users mailing list