SubsetNew (NamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
Line 20: Line 20:


For example, <tt>GT(this, -11)</tt> is the criterion <tt>this</tt> <tt>></tt> <tt>-11</tt>, where <tt>this</tt> is an identity function that simply returns the item's value. The items that satisfy this expression populate the NamedArraylist that SubsetNew returns.
For example, <tt>GT(this, -11)</tt> is the criterion <tt>this</tt> <tt>></tt> <tt>-11</tt>, where <tt>this</tt> is an identity function that simply returns the item's value. The items that satisfy this expression populate the NamedArraylist that SubsetNew returns.
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 ''%namrayl'' declaration and that returns a numeric or string value. This is described further in "[[SelectionCriterion class#Specifying a SelectionCriterion's parameters|Specifying a SelectionCriterion's parameters]]".</td></tr>
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 ''%namrayl'' declaration and that returns a numeric or string value. This is described further in [[SelectionCriterion class#Specifying a SelectionCriterion's parameters|"Specifying a SelectionCriterion's parameters"]].</td></tr>


</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>[[FindNextItem (NamedArraylist function)|FindNextItem]]
<li><var>[[FindNextItem (NamedArraylist function)|FindNextItem]]</var>
is similar to SubsetNew except that it returns just the first matching item
is similar to <var>SubsetNew</var> except that it returns just the first matching item
it encounters.
it encounters.
</ul>
</ul>
Line 33: Line 33:
In the following fragment, a SubsetNew call is applied to a collection
In the following fragment, a SubsetNew call is applied to a collection
of objects of the <tt>staff</tt> class that is defined in the
of objects of the <tt>staff</tt> class that is defined in the
request in the "[[FindPreviousItem (NamedArrayArraylist function)#Examples|NamedArrayArraylist FindPreviousItem function example]]":
request in the <var>NamedArraylist</var> <var>FindNextItem</var> [[FindNextItem (GenericNamedArraylist function)#Examples|"Examples"]] section:
<p class="code">%old is namedArraylist of object staff
<p class="code">%old is namedArraylist of object staff
%old = new
%old = new

Revision as of 22:53, 2 March 2011

Create NamedArraylist of items matching some selection criteria (NamedArraylist class)


This function 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.

SubsetNew is available in Sirius Mods version 7.6 and later.

Syntax

%outNal = nal:SubsetNew( selectionCriterion)

Syntax terms

%namraylNew A NamedArraylist variable of the same type as the method NamedArraylist (%namrayl) to contain the items that are located by the search. If %namraylNew is not empty, its contents are discarded before it is populated by the return items from SubsetNew.
%namrayl A NamedArraylist object.
criterion A SelectionCriterion object, which is a relational expression that is applied to a %namrayl item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a numeric or string value.

For example, GT(this, -11) is the criterion this > -11, where this is an identity function that simply returns the item's value. The items that satisfy this expression populate the NamedArraylist that SubsetNew returns.

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 %namrayl declaration and that returns a numeric or string value. This is described further in "Specifying a SelectionCriterion's parameters".

Usage notes

  • FindNextItem is similar to SubsetNew except that it returns just the first matching item it encounters.

Examples

    In the following fragment, a SubsetNew call is applied to a collection of objects of the staff class 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

See also