This version is out of date, covering development from v5.0.0 to v5.12.2. It is maintained here only for inbound reference links from elsewhere.

Jump to the current version of aTbRef.

Tinderbox Icon

== (equality)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Operator   [other Operator type actions]

 Query   [operators of similar scope]

 Query Boolean   [other Query Boolean operators]

 Already in v5.0.0

 


The operator to test equality (i.e. 'is the same as') is '==', two equals signs. Note that this replaces older syntax where a single equals sign was used contextually for both assignment and equality tests.

This operator is used either in agent queries or in the conditional part of an if(condition){action} code. It is the functional opposite of the '!=' inequality test.

This test cannot be meaningfully applied to Set or List type attribute data, as the entire attribute value is matched, rather than individual values as might otherwise be assumed. For these data types use the .contains() or .icontains() operators instead, noting the scope for ambiguous matching due to stemming of words ("car" with match "car", "cars" and "carrot").

Equality testing can be negated, i.e. tested for a non-match, or combined with greater/less than for a range of tests as further explored in Basic Comparison Codes.

For a case-insensitive lexical equality test, use a lowercase on-the-fly transform:

"Absquatulate".lowercase == "absquatulate" 

If we set $MyString to "Absquatulate", then:

$MyString.lowercase == "absquatulate" 

If $MyOtherString(Some note) has the value "absquatulate", then:

$MyString.lowercase == $MyOtherString(Some note) 

Note the stored left-side value isn't altered, but its transformed version is used in the test giving a case-insensitive comparison. This method only works for upper/lower case comparisons; accented characters are lexically different characters regardless of case.

Equality and List/Sets

Using == (and !+) with Lists & Sets means you're checking the entire literal contents, i.e. a string like "ant;bee;cow" rather than by individual sub-value: "ant" and "bee" and "cow". Thus the equality test can't be used to check if the attribute contains a discrete value - use .contains() instead. This shows up a difference between lists and sets. Although the literal value of a set may hold values in any order, when tested in code, they are being tested after sorting into (some**) order. Incidentally, this is why you can't set a sort order as you can with a list as internally your given sort order is ignored. Consider $MySetA and $MyListA both with the values "ant;bee;cow". $MySetB and $MyListB both have the value "bee;ant". Now:

$MySetA == $MySetB gives FALSE

$MyListA == $MyListB gives FALSE

both are expected. Now make both the B attributes value "bee;ant;cow"

$MySetA == $MySetB gives TRUE

$MyListA == $MyListB gives FALSE

This is because the Set compares the literal result of sorted values, whereas the list

doesn't. But

$MyListA == $MyListB.sort gives TRUE

This is in effect what's happening with the sets, as in:

$MyListA.sort == $MyListB.sort 

whereas in our last example above, $MyListA was already in default sort order so no applied sort was required.


Possible relevant notes (via "Similar Notes" feature):


A Tinderbox Reference File : Actions & Rules : Operators : Action Operator Types : Query Boolean operators : == (equality)