0

I gave pojos like

Customer{ List<String> groups; }

Master{
   List<String> groups;
}

I want to check conditions like

master1.groups.containsAny(customer1.groups);

and also

master1.groups.containsAll(customer1.groups);

How can i write drools condition for these two? Thanks in advance.

  • There is a List.containsAll method. For containsAny, you may have to write a static method or a DRL function. – laune Jan 08 '18 at 15:57

1 Answers1

0

Use below Drools functions

function boolean containsAny(List<String> sourceList, List<String> targetList){
    sourceList.retainAll(targetList);
    return sourceList.size() != 0;
}
function boolean containsAll(List<String> sourceList, List<String> targetList){
    int size = sourceList.size();
    sourceList.retainAll(targetList);
    return sourceList.size() == size;
}
jeet427
  • 538
  • 3
  • 16