SubsetNew (NamedArraylist function)
Create NamedArraylist of items matching some selection criteria (NamedArraylist class)
SubsetNew searches the entire NamedArraylist to find and return all items that match a specified criterion. The criterion is supplied by the SelectionCriterion object that is the required SubsetNew parameter. If no item satisfies the criterion, SubsetNew returns an empty NamedArraylist.
%outNal = nal:SubsetNew( selectionCriterion)
|%outNal||A NamedArraylist variable of the same type as the method NamedArraylist (nal) to contain the items that are located by the search. If outNal is not empty, its contents are discarded before it is populated by the items returned from SubsetNew.|
|nal||A NamedArraylist object.|
|selectionCriterion||A SelectionCriterion object, which is a relational expression that is applied to a nal item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a numeric or string value.
The function in the criterion is a method value (a method or class member name literal, or a method variable) for a method that operates on items of the type specified on the nal declaration and that returns a numeric or string value. This is described further in "Specifying a SelectionCriterion's parameters".
- SubsetNew is available in Sirius Mods Version 7.6 and later.
- In the following fragment, a SubsetNew call is applied to a collection of objects of the
staffclass that is defined in the request in the NamedArraylist FindNextItem "Examples" section:
%old is namedArraylist of object staff %old = new %old('Jim') = newf('Red', 'employed') %old('Jed') = newf('Black', 'retired') %old('Jan') = newf('Green', 'employed') %old('Jud') = newf('Brown', 'retired') %old('Jon') = newf('White', 'retired') %sel is object selectioncriterion for object staff %sel = AND(LT(name, 'Mud'), EQ(status, 'retired')) %fnd is namedArraylist of object staff %fnd = %old:SubsetNew(%sel) %fnd:Print(name, separator=' ')
The result is:
1 Jed Black 2 Jud Brown
- In the following fragment, two nearly identical SubsetNew calls are used. The first uses a SelectionCriterion whose first argument (
this) is a String valued function, and so EBCDIC comparisons are used. The second uses a SelectionCriterion whose first argument (
this) is a Unicode valued function, and so Unicode comparisons are used.
%hit is namedArraylist of string len 30 %hit = new %hit('Clapton') = 'Layla' %hit('Davies') = 'All Day and All of the Night' %hit('Simon') = '50 Ways to Leave Your Lover' %Hit = %Hit:subsetNew(LE(this, '51')) %Hit:print %unicHit is namedArraylist of unicode %unicHit = new %unicHit('Clapton') = 'Layla' %unicHit('Davies') = 'All Day and All of the Night' %unicHit('Simon') = '50 Ways to Leave Your Lover' %unicHit = %unicHit:subsetNew(LE(this, '51')) %unicHit:print
The result is:
1: Clapton: Layla 2: Davies: All Day and All of the Night 3: Simon: 50 Ways to Leave Your Lover 1: Simon: 50 Ways to Leave Your Lover
In an EBCDIC comparison, letters (here,
A) are less then numeric digits (here,
5); in a Unicode comparison, (Latin) letters are greater than numeric digits.
- FindNextItem is similar to SubsetNew except that it returns just the first matching item it encounters.
- The UnicodeNamedArraylist SubsetNew and FloatNamedArraylist SubsetNew functions also perform the subsetting function — for their respective classes. The examples on those pages may provide for possible additional approaches for SubsetNew.