Technical rule conditions

Conditions are expressed using the class of object being tested followed by an operator. Actions are only executed if all the tests are satisfied.

The condition part of a technical rule is composed of a set of tests on Java™ objects. Tests are applied to each object provided to the rule engine for execution, and an object is said to match the condition when it passes all the tests in the condition.

Syntax of conditions

A condition starts with the name of the class concerned by the condition, such as Film. This class name is followed by tests, enclosed in parentheses, that express constraints on the attribute values for objects of this class.

For example, suppose that you want the rule to apply only to films showing after 8 in the evening. This condition is expressed as follows:

Film(showTime > 20.00);

This condition matches objects of the Film class whose showTime attribute is greater than 20.00. Suppose that you then require the location of the film to be in Paris. This compound condition is expressed as follows:

Film(showTime > 20.00; location == Paris );

Operators

Each test starts by naming the attribute, followed by one of the operators in the following table.

Table 1. Condition operators  
Operator Description
== equals
!= does not equal
< is less than
> is greater than
<= is less than or equal to
>= is greater than or equal to
in is in
!in is not in
a method call method invocation

The test ends with an expression whose value is compared with that of the attribute.

A condition can contain several tests involving the same object attribute. For example, the following condition tests for films whose show times are between 8 and 10 in the evening:

Film(showTime > 20.00; showTime < 22.00);

Combination sign: &

The ampersand sign & is used as a combination sign, to associate several tests with the same object attribute involved in a condition. Therefore, to test for films whose show times are between 8 and 10 in the evening, you can express the condition as follows:

Film(showTime > 20.00 & < 22.00);

Here are two equivalent conditions, the second of which uses the & sign:

Film(produced > 1980; produced < 1990; showTime > 20.00; showTime < 22.00);
Film(produced > 1980 & < 1990; showTime > 20.00 & < 22.00);

Conjunction

Implicit AND relationships exist between all the tests in a rule. In other words, all the tests in the condition part of a rule must be satisfied before actions can be executed.

For example, consider the following conditions: “a film whose spoken language is English” and “a cinema whose location is Paris.” These conditions might be written in the following way:

Film(language == English);
Cinema(location == Paris);

These two conditions are matched by pairs of Film and Cinema objects for which the language of the film object is equal to English AND the location of the cinema object is equal to Paris.