Operators are symbols that cause a particular action, for example, comparison of values, summing up, assignment, etc.
To assign a value to use the assignment operator :=
:
Arithmetic operators are used on Integer and Decimal values similarly to their use in algebra.
Operator | Description | Example | Result | Note |
---|---|---|---|---|
+ | addition | 2 + 2 | 4 | |
- | subtraction | 3 - 1 | 2 | |
++ | increment by 1 | intVar++ or ++intVar | postfix: returns value; then increments by one and assigns it to the referenced object (2++ ); prefix: increments value by 1 and reassigns it to the referenced object | |
-- | decrements by 1 | intVar++ or ++intVar | postfix: returns value; then decrements by one and assigns it to the referenced object (2++ ); prefix: decrements value by 1 and reassigns it to the referenced object | |
* | multiplication | 3 * 3 | 9 | |
/ | division | 9 / 3 | 3 | |
% | modulo | 10 % 3 | 1 | |
** | exponentiation | 3 ** 3 | 27 | Since expressions are evaluated primarily in the left-to-right manner unless precedence or association rules take over, the expression 2**3**4 is evaluated as 2^3^4^^; the exponent follows the ** operator |
You can use the following compound-assignment operators:
Operator | Description | Example | Equivalent |
---|---|---|---|
+= | assigns the result of the addition | x += y | x := x + y |
-= | assigns the result of the subtraction | x -= y | x := x - y |
*= | assigns the result of the multiplication | x *= y | x := x * y |
/= | assigns the result of the division | x /= y | x := x / y |
%= | assigns the remainder of the division | x %= y | x := x % y |
Logical operators are used to combine multiple expressions that each return a boolean value. Combination of expressions with logical operators return a single boolean value.
Operators and their return values
and
, &&
(conjunction) true if both operands are true; otherwise false
or
, ||
(inclusive disjunction) true when at least one of the operands is true; otherwise false
xor
, exclusive disjunction true when the operands value is not identical, that is one operand is true and the other operand is false; otherwise false
not
or !
(negation) Truth Table
Operand A | Operand B | A and B | A or B | A xor B | not A |
---|---|---|---|---|---|
true | true | true | true | false | false |
true | false | false | true | true | false |
false | true | false | true | true | true |
false | false | false | false | false | true |
Since logical expressions are evaluated from left to right, the short-circuit evaluation is applied on and
and or
expressions:
and
expressions:<false> and <not_evaluated>
evaluates to false
or
expression <true> or <not_evaluated>
evaluates to false
Comparison operators serve to compare two values. Comparing returns a boolean value.
To compare two values, you can use the following operators:
==
(equal) and !=
(not equal, alternatively noted as <>
) check if the values of any data type are equal. Note: When comparing records, it is the object identity that is compared, not the record value. Analogously, on shared records, the record IDs are compared. However, on non-shared records, you can define fields or relationships so that the values of these are used when comparing records (refer to the Record Fields in the GO-BPMN Modeling Language Guide).
instanceof
checks if the object is of a particular type. false
. Note: The
core::isInstance()
returnstrue
for null arguments.
<
(lesser), >
(greater), <=
(lesser or equal), and >=
(greater or equal) check if values of decimals, integers, and strings are lesser, lesser or equal, greater, or greater or equal and returns true
or false
.
When comparing Strings, they are compared lexicographically as per Java lexicographic ordering of strings, for example, "Čapek" > "Hemingway"
and "Čapek" > "Asimov"
are true.
like
searches for an occurrence of a pattern in a string
The operator supports the wildcards ?
for one character and *
for one or multiple characters
"matching exactly THIS word" like "* ??????? THIS *"
<=>
(the spaceship operator): checks if values are lesser, equal, or greater and returns -1
if the left operand is lesser than the right operand, 0
if the left operand and right operand are equal, and 1
if the left operand is greater than the right operand.
Applicable to the String, Decimal, Integers, and Date types (Date is a complex data type defined in the Standard Library)
To concatenate two Strings, use the +
concatenation operator.
The String concatenation operator + can concatenate also a String and any subtype of the Object type: the Object type is converted to the appropriate String value and concatenated with the String; for example, a Date value is converted to a human readable date representation when concatenated with a string. Note that the String object must come first in such expressions.
String concatenation example If the first operands of the + operator is a string, the + operator is considered automatically the operand of concatenation and the non-string operand is automatically converted to a string.
Resulting string:
Note: If you want to keep a non-string operand before the string operand in concatenation, start your expression with the empty String literal
""
, for example,"" + author.surname + ", " + author.firstname
.
The reference operator &
returns Reference to a variable or a property path from a variable in the context of the variable. The dereference operator *
takes a Reference value and returns the value currently stored in the referenced variable or property.
//instantiates record c1 with c1.name "Walter White": def Partner c1 := new Partner(name -> "Walter White"); //reference variable ref with reference c1.name (current value "Walter White"): def Reference<String> ref := &c1.name; //variable x assigned dereferenced ref, that is "Walter White": def String x := *ref; //c1 assigned a new record instance with the name "Jesse Pinkman": c1 := new Partner(name -> "Jesse Pinkman"); //new variable y assigned the dereferenced ref value (that resolves to "Jesse Pinkman"): def String y := *ref; //note that the value held by x remains "Walter White"
In the example, the variable part is c1
and the property part is .name
. To acquire the value of a reference, use the dereference operator *
.
References hold the referenced expression and the associated context. In our example the referenced expression is c1.name
.
The inclusion operator in
checks if an element is in a set or list.
The check returns the String "1 is in mySet" if 1 is in mySet.
The module namespace operator (::
) is used to refer to elements of other module namespaces.
Consider ModuleA with a variable var imported into ModuleB. You can access var from ModuleB as follows:
The mechanism of module import is described in the GO-BPMN Modeling Language Specification.
To access items in collections or maps, use the selector operator []
to specify the element to be returned:
on sets
on lists
Note that the first element of a List is on position zero. For example, [10,20,30][1]
returns 20.
on maps
The ternary conditional operator ?:
enables you to define a condition and two expressions. If the condition evaluates to true
the first expression is returned. If the condition evaluates to false
, the second expression is returned.
With the operator you can write the expression
as
The null-coalescing operator ??
is a more effective version of if <expression_1> != null then <expression_2>
with <expression_1>
evaluated only once.
<expression_1> ?? <expression_2>; //is equivalent to: if <expression_1> != null then <expression_1> else <expression_2> end
Example:
The dot operator .
serves to access fields of a Record, possibly via relationships, and a record's methods. Example:
For example:
Example:
For example:
Note that the dot operator .
fails with an exception if the <EXPRESSION>
with the access operator is null
. When accessing fields, you can use the safe-dot operator to prevent the exception.
To prevent the system from raising an exception when it attempts to access a record field of a record which is null
, use the safe-dot operator ?.
.
Similarly to the dot operator, the ?.
operator serves to access Record Fields, possibly of related Records. Unlike the dot operator, no exception is raised when the record is null
. The expression simply returns null
.
Example:
def Person person := null; //returns null without an error: person?.email; //chaining the access requests: person?.contact?.operator?.operatorCallCode //accessing reference: &person?.name
To cast the value of an object to another type, use the as
operator:
For further information, refer to Casting.
The order of expression evaluation at runtime is generally from left to right, that is, first the left-hand operand is evaluated and only then the right-hand operand is evaluated.
The evaluation order can be influenced by the operator precedence. Mathematical operators, logical, and relational operators follow their natural operator precedence:
Parentheses override operator precedence and the expression in parenthesis is evaluated as a whole.
Operator precedence order
::
(scope operator)[]
(selector), ()
(function/closure call), .
(dot operator), ?.
(safe dot operator)+
, -
, &
(reference), *
(dereference)??
(ifnull)*
(multiplication), /
(division), %
(modulo), **
(exponentiation)+
(addition), -
(subtraction)<
, >
, <=
, >=
, <=>
instanceof
==
(equal), !=
(not equal), <>
, like
, in
(inclusion)cast
, as
not
and !
(negation)and
and &&
(conjunction)or
and ||
, xor
(disjunctions)?:
(ternary if):=
(assignment);
(chaining operator)