<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">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.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a class like this. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">public class Account { <o:p></o:p></p>
<p class="MsoNormal"> public int balance; <o:p></o:p></p>
<p class="MsoNormal"> public String id; <o:p></o:p></p>
<p class="MsoNormal"> public List<String> types; <o:p></o:p></p>
<p class="MsoNormal">// getter setters <o:p></o:p></p>
<p class="MsoNormal">} <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am trying to check the following: <o:p></o:p></p>
<p class="MsoNormal">Accounts having balance greater than $100 and types containing both Savings and Checking.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">// Creating sample Facts in Java main <o:p></o:p></p>
<p class="MsoNormal"> Account account = new Account(); <o:p></o:p></p>
<p class="MsoNormal"> account.setBalance(100); <o:p></o:p></p>
<p class="MsoNormal"> account.setId("A1"); <o:p></o:p></p>
<p class="MsoNormal"> List<String> temp = new ArrayList<String>(); <o:p></o:p></p>
<p class="MsoNormal"> temp.add("Savings"); <o:p></o:p></p>
<p class="MsoNormal"> temp.add("Checking"); <o:p></o:p></p>
<p class="MsoNormal"> account.setTypes(temp); <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">// Creating rules <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">rule "Sample" <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> when <o:p></o:p></p>
<p class="MsoNormal"> bat : Account(balance == 100) <o:p></o:p></p>
<p class="MsoNormal"> then <o:p></o:p></p>
<p class="MsoNormal"> if (bat.getTypes().contains("Savings") && bat.getTypes().contains("Checking")){
<o:p></o:p></p>
<p class="MsoNormal"> System.out.println("I got this"); <o:p></o:p></p>
<p class="MsoNormal"> } <o:p></o:p></p>
<p class="MsoNormal">end <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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" ??
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Much appreciate your answers. <o:p></o:p></p>
<p class="MsoNormal">Thank you! <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>
<table><tr><td bgcolor=#ffffff><font color=#000000><pre>**************** 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***</pre></font></td></tr></table>