Appendix B. Custom Operator

We've already seen various operators that can be used within rule conditions. These include, for example, ==, !=, relational operators such as >, <, >= , temporal operators such as after, during, finishes, or others such as matches, which perform regular expression matching. In this section, we'll define our own custom operator.

The == operator uses Object.equals/hashCode methods for comparing objects. However, sometimes we need to test if two objects are actually referring to the same instance. This is slightly faster than Object.equals/hashCode comparison (only slightly faster because the hash code is calculated once for object and then it is cached).

Imagine that we have a rule which matches on an Account

Get Drools JBoss Rules 5.0 Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.