Este contenido no está disponible en el idioma seleccionado.

13.21. Basic Conditional Elements


Expand
Table 13.4. Basic Conditional Elements
Name Description Example Additional options
and
The Conditional Element and is used to group other Conditional Elements into a logical conjunction. JBoss Rules supports both prefix and and infix and. It supports explicit grouping with parentheses. You can also use traditional infix and prefix and.
//infixAnd
Cheese( cheeseType : type ) and Person( favouriteCheese == cheeseType )
Copy to Clipboard Toggle word wrap
//infixAnd with grouping
( Cheese( cheeseType : type ) and
  ( Person( favouriteCheese == cheeseType ) or 
    Person( favouriteCheese == cheeseType ) )
Copy to Clipboard Toggle word wrap
Prefix and is also supported:
(and Cheese( cheeseType : type )
     Person( favouriteCheese == cheeseType ) )
Copy to Clipboard Toggle word wrap
The root element of the LHS is an implicit prefix and and doesn't need to be specified:
when
    Cheese( cheeseType : type )
    Person( favouriteCheese == cheeseType )
then
    ...
Copy to Clipboard Toggle word wrap
or
This is a shortcut for generating two or more similar rules. JBoss Rules supports both prefix or and infix or. You can use traditional infix, prefix and explicit grouping parentheses.
//infixOr
Cheese( cheeseType : type ) or Person( favouriteCheese == cheeseType )
Copy to Clipboard Toggle word wrap
//infixOr with grouping
( Cheese( cheeseType : type ) or
  ( Person( favouriteCheese == cheeseType ) and
    Person( favouriteCheese == cheeseType ) )
Copy to Clipboard Toggle word wrap
(or Person( sex == "f", age > 60 )
    Person( sex == "m", age > 65 )
Copy to Clipboard Toggle word wrap
Allows for optional pattern binding. Each pattern must be bound separately, using eponymous variables:
pensioner : ( Person( sex == "f", age > 60 ) or Person( sex == "m", age > 65 ) )
Copy to Clipboard Toggle word wrap
(or pensioner : Person( sex == "f", age > 60 ) 
    pensioner : Person( sex == "m", age > 65 ) )
Copy to Clipboard Toggle word wrap
not
This checks to ensure an object specified as absent is not included in the Working Memory. It may be followed by parentheses around the condition elements it applies to. (In a single pattern you can omit the parentheses.)
// Brackets are optional:
not Bus(color == "red")
// Brackets are optional:
not ( Bus(color == "red", number == 42) )
// "not" with nested infix and - two patterns,
// brackets are requires:
not ( Bus(color == "red") and
      Bus(color == "blue") )
Copy to Clipboard Toggle word wrap
exists
This checks the working memory to see if a specified item exists. The keyword exists must be followed by parentheses around the CEs that it applies to. (In a single pattern you can omit the parentheses.)
exists Bus(color == "red")
// brackets are optional:
exists ( Bus(color == "red", number == 42) )
// "exists" with nested infix and,
// brackets are required:
exists ( Bus(color == "red") and
         Bus(color == "blue") )
Copy to Clipboard Toggle word wrap

Note

The behavior of the Conditional Element or is different from the connective || for constraints and restrictions in field constraints. The engine cannot interpret the Conditional Element or. Instead, a rule with or is rewritten as a number of subrules. This process ultimately results in a rule that has a single or as the root node and one subrule for each of its CEs. Each subrule can activate and fire like any normal rule; there is no special behavior or interaction between these subrules.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat