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!