Functions and Methods on List

This page provides an extract of frequently used functions using list.

Function Input Types Return Type Description
$TAIL(list1) List List Returns the list without the first element.
$FIRST(list1) List Element Returns the first element of list1 list.
$LAST(list1) List Element Returns the last element of list1 list.
$REV(list1) List List Returns the inverse of list1 list.
$AT(list1, index1) List, Integer Element Returns the element at index1 index in list1 list.

Example: $AT("The" $+ "black" $+ "cat", 2) returns "black".

$ATPUT(list1, index, elt) List, Integer, Element List Replaces the element of index position in list1 by elt.
$SUB(list1, startIndex, endIndex) List, Integer, Integer List Returns a list beginning at startIndex index and ending at endIndex index.
$INDEX(list1, elt) List, Element Integer Returns the index of the first occurrence of elt element within list1 list.
$SOME(list1) List Boolean Returns TRUE if list1 is not empty.
$NO(list1) List Boolean Returns TRUE if list1 is empty.
$CNT(list1) List Integer Returns the number of elements in list1 list.
expression.SORTBY(sortCriterion)
  • expression is a List
  • sortCriterion is a String, Integer, or Real
List Returns a list expression sorted by a criterion sortCriterion.

Examples

Prerequisite: reqSpec is an element of Requirement Specification class and req is of Requirement class.

  • To test if the number of requirements is bigger or equal to 2.

    $CNT(reqSpec.getAllRequirements) >= 2

  • To test if some requirements are named Criticality.

    $SOME(reqSpec.getAllRequirements[req.name="Criticality"])