OCLOperators indexOf
(Replacing message template with parser tag)
No edit summary
Line 10: Line 10:
|}
|}
The zero-based index of an object in the collection is possibly -1 if nonexistent.
The zero-based index of an object in the collection is possibly -1 if nonexistent.
(note that probably the specification says that this should be 1-based and not 0-based as it is. This makes it a confusing to use the at(int)-operator that IS 1 based.
We have introduced a IndexOf0:int that explicitly is zero based to better sit with the explicit zero based at0(int))
We recommend you use [[Documentation:OCLOperators indexOf0|IndexOf0]] and [[Documentation:OCLOperators at0|at0]] operators over IndexOf and at
[[Category:OCL Collection Operators]]
[[Category:OCL Collection Operators]]
{{Edited|July|12|2024}}
{{Edited|July|12|2024}}

Revision as of 09:50, 2 October 2024

This page was created by Alexandra on 2017-08-13. Last edited by Edgar on 2025-01-20.

indexOf ( object : T ) : Integer

Returns the position of object in sequence self.

Expression Result
Sequence{'a', 'b'}->indexOf('a') 0

The zero-based index of an object in the collection is possibly -1 if nonexistent.

(note that probably the specification says that this should be 1-based and not 0-based as it is. This makes it a confusing to use the at(int)-operator that IS 1 based.

We have introduced a IndexOf0:int that explicitly is zero based to better sit with the explicit zero based at0(int))

We recommend you use IndexOf0 and at0 operators over IndexOf and at