SubsetNew (UnicodeNamedArraylist function): Difference between revisions
m (1 revision) |
m (→See also) |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:UnicodeNamedArraylist:SubsetNew subtitle}} | {{Template:UnicodeNamedArraylist:SubsetNew subtitle}} | ||
<var>SubsetNew</var> searches the entire <var>UnicodeNamedArraylist</var> to find and return all items that match a specified criterion. The criterion is supplied by the <var>[[SelectionCriterion class|SelectionCriterion]]</var> object that is the required <var>SubsetNew</var> parameter. If no item satisfies the criterion, <var>SubsetNew</var> returns an empty <var>UnicodeNamedArraylist</var>. | |||
==Syntax== | ==Syntax== | ||
{{Template:UnicodeNamedArraylist:SubsetNew syntax}} | {{Template:UnicodeNamedArraylist:SubsetNew syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%outUniNal</th> | ||
<td>A UnicodeNamedArraylist variable of the same type as the method UnicodeNamedArraylist ( | <td>A <var>UnicodeNamedArraylist</var> variable of the same type as the method <var>UnicodeNamedArraylist</var> (<var class="term">uniNal</var>) to contain the items that are located by the search. If <var class="term">outUniNal</var> is not empty, its contents are discarded before it is populated by the items returned from <var>SubsetNew</var>. </td></tr> | ||
<tr><th> | <tr><th>uniNal</th> | ||
<td>A UnicodeNamedArraylist object. </td></tr> | <td>A <var>UnicodeNamedArraylist</var> object. </td></tr> | ||
<tr><th> | <tr><th>selectionCriterion</th> | ||
<td>A SelectionCriterion object, which is a relational expression that is applied to a | <td>A <var>[[SelectionCriterion class|SelectionCriterion]]</var> object, which is a relational expression that is applied to a <var class="term">uniNal</var> item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a <var class="product">User Language</var> intrinsic type (numeric, string, or Unicode) value. | ||
<p>For example, <code>LT(this, 91)</code> is the criterion <code>this < 91</code>, where <code>this</code> is an identity function that simply returns the item's value. The items that satisfy this expression populate the <var>UnicodeNamedArraylist</var> that <var>SubsetNew</var> returns. | |||
For example, < | </p> | ||
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 | <p>The function in the criterion is a method value (a method or class member name literal, or a [[Method variables|method variable]]) for a method that operates on items of the type specified on the <var class="term">uniNal</var> declaration and that returns an intrinsic value. This is described further in [[SelectionCriterion class#Specifying a SelectionCriterion's parameters|"Specifying a SelectionCriterion's parameters"]]. | ||
</p></td></tr> | |||
</table> | |||
==Examples== | ==Examples== | ||
In the following request, a <var>SubsetNew</var> call uses a selection criterion that first applies the intrinsic [[Length (String function)|Length]] function to the collection items: | |||
<p class="code">begin | |||
%k is unicodeNamedArraylist of longstring | |||
%kk is unicodeNamedArraylist of longstring | |||
%k = new | |||
%k('§Jan':u) = 'Orion' | |||
%k('§Apr':u) = 'Leo' | |||
%k('§Mar':u) = 'Cancer' | |||
%k('§Jun':u) = 'Ursa Minor' | |||
%k('§Nov':u) = 'Andromeda' | |||
%k('§Dec':u) = 'Aries' | |||
%k('§Feb':u) = 'Canis Major' | |||
%sel is object selectionCriterion for longstring | |||
%n is float | |||
%sel = GE(length, 9) | |||
%kk = %k:subsetNew(%sel) | |||
%kk:print | |||
end | |||
%kk = %k:subsetNew(%sel) | |||
%kk:print | |||
</p> | </p> | ||
The result is: | The result is: | ||
<p class="output">1: §.Feb: Canis Major | <p class="output">1: §.Feb: Canis Major | ||
Line 60: | Line 45: | ||
3: §.Nov: Andromeda | 3: §.Nov: Andromeda | ||
</p> | </p> | ||
==See also== | ==See also== | ||
<ul> | |||
<li><var>[[FindNextItem (UnicodeNamedArraylist function)|FindNextItem]]</var> is similar to <var>SubsetNew</var> except that it returns just the first matching item it encounters. | |||
<li>The <var>NamedArraylist</var> <var>[[SubsetNew (NamedArraylist function)|SubsetNew]]</var> and <var>FloatNamedArraylist</var> <var>[[SubsetNew (FloatNamedArraylist function)|SubsetNew]]</var> functions also perform the subsetting function — for their respective classes. The examples on those pages may provide for possible additional approaches for <var>SubsetNew</var>. | |||
</ul> | |||
{{Template:UnicodeNamedArraylist:SubsetNew footer}} | {{Template:UnicodeNamedArraylist:SubsetNew footer}} |
Latest revision as of 16:39, 3 August 2012
Create UnicodeNamedArraylist of items matching some selection criteria (UnicodeNamedArraylist class)
SubsetNew searches the entire UnicodeNamedArraylist 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 UnicodeNamedArraylist.
Syntax
%outUniNal = uniNal:SubsetNew( selectionCriterion)
Syntax terms
%outUniNal | A UnicodeNamedArraylist variable of the same type as the method UnicodeNamedArraylist (uniNal) to contain the items that are located by the search. If outUniNal is not empty, its contents are discarded before it is populated by the items returned from SubsetNew. |
---|---|
uniNal | A UnicodeNamedArraylist object. |
selectionCriterion | A SelectionCriterion object, which is a relational expression that is applied to a uniNal item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a User Language intrinsic type (numeric, string, or Unicode) value.
For example, 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 uniNal declaration and that returns an intrinsic value. This is described further in "Specifying a SelectionCriterion's parameters". |
Examples
In the following request, a SubsetNew call uses a selection criterion that first applies the intrinsic Length function to the collection items:
begin %k is unicodeNamedArraylist of longstring %kk is unicodeNamedArraylist of longstring %k = new %k('§Jan':u) = 'Orion' %k('§Apr':u) = 'Leo' %k('§Mar':u) = 'Cancer' %k('§Jun':u) = 'Ursa Minor' %k('§Nov':u) = 'Andromeda' %k('§Dec':u) = 'Aries' %k('§Feb':u) = 'Canis Major' %sel is object selectionCriterion for longstring %n is float %sel = GE(length, 9) %kk = %k:subsetNew(%sel) %kk:print end
The result is:
1: §.Feb: Canis Major 2: §.Jun: Ursa Minor 3: §.Nov: Andromeda
See also
- FindNextItem is similar to SubsetNew except that it returns just the first matching item it encounters.
- The NamedArraylist 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.