Search code examples
drools

How to check for null value in accumulate Drools


Iam first time user of Drools. In accumulate function I have a scenario to check for the (!= null) feature of java. But in Drools I find that != doesn't work .

when

      $addr : String(length > 0) from accumulate(
                  $person : Person(),
                   action(
                         $addresses : $person.getAddresses();
                         // i want to check whether $addresses is not 
                             null.
                         if($addresses !=null) is what i want to achieve

)

Any help is really appreciated.


Solution

  • Edit the rule as Below :

    Person(adresses !=null) && $addr : String(length > 0) from accumulate(
                  $person : Person(),
                   action(
                         $addresses : $person.getAddresses();
                         )