Iterating over Input Parameters
Daniel Selman 2700022VQ3 Visits (17022)
I spoke to two customers during IBM Impact, as well as helping an IBMer this week. They all had the same question: "How do I iterate over a collection accessible from an input parameter?" This question is fairly common for people with a procedural programming background as iteration is a mainstay of programming languages like Java/C etc. Business rules, BAL and rule engines in general strive to be more declarative hence it is not always obvious how to iterate over data. Often we try not to code explicit iterators as they make assumptions about how data is organized, rather we create "patterns" that "match" the data and then perform an action.
Let's take a look at some of the iteration idioms and their pros/cons in JRules. To explain the various scenarios I created a rule project with a PersonType that contains a collection of AddressTypes. Each AddressType has a country property and the rules should be applied to all US addresses.
There are 3 basic patterns for iteration in JRules:
I will explain each in a separate blog post. The rule project that illustrates these techniques is available here: iterating-rules.zip