SubsetNew (UnicodeNamedArraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 50: Line 50:
that first applies the intrinsic [[Length (String function)|Length]] function
that first applies the intrinsic [[Length (String function)|Length]] function
to the collection items:
to the collection items:
<pre style="xmp">
<p class="code">Begin
    Begin


    %k  is unicodeNamedArraylist of longstring
%k  is unicodeNamedArraylist of longstring
    %kk  is unicodeNamedArraylist of longstring
%kk  is unicodeNamedArraylist of longstring
    %k = new
%k = new
    %k('&sect;Jan':u) = 'Orion'
%k('&sect;Jan':u) = 'Orion'
    %k('&sect;Apr':u) = 'Leo'
%k('&sect;Apr':u) = 'Leo'
    %k('&sect;Mar':u) = 'Cancer'
%k('&sect;Mar':u) = 'Cancer'
    %k('&sect;Jun':u) = 'Ursa Minor'
%k('&sect;Jun':u) = 'Ursa Minor'
    %k('&sect;Nov':u) = 'Andromeda'
%k('&sect;Nov':u) = 'Andromeda'
    %k('&sect;Dec':u) = 'Aries'
%k('&sect;Dec':u) = 'Aries'
    %k('&sect;Feb':u) = 'Canis Major'
%k('&sect;Feb':u) = 'Canis Major'


    %sel is object selectionCriterion for longstring
%sel is object selectionCriterion for longstring
    %n is float
%n is float
    %sel = GE(length, 9)
%sel = GE(length, 9)


    %kk = %k:subsetNew(%sel)
%kk = %k:subsetNew(%sel)
    %kk:print
%kk:print


    End
End
</pre>
</p>


The result is:
The result is:
<pre style="xmp">
<p class="output">1: &sect.Feb: Canis Major
    1: &sect.Feb: Canis Major
2: &sect.Jun: Ursa Minor
    2: &sect.Jun: Ursa Minor
3: &sect.Nov: Andromeda
    3: &sect.Nov: Andromeda
</p>
</pre>
==See also==
==See also==
{{Template:UnicodeNamedArraylist:SubsetNew footer}}
{{Template:UnicodeNamedArraylist:SubsetNew footer}}

Revision as of 20:54, 28 January 2011

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


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

%unamraylNew
A UnicodeNamedArraylist variable of the same type as the method UnicodeNamedArraylist (%unamrayl) to contain the items that are located by the search. If %unamraylNew is not empty, its contents are discarded before it is populated by the return items from SubsetNew.
%unamrayl
A UnicodeNamedArraylist object.
criterion
A SelectionCriterion object, which is a relational expression that is applied to a %unamrayl 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, LT(this, 91) is the criterion this < 91, where this is an identity function that simply returns the item's value. The items that satisfy this expression populate the UnicodeNamedArraylist 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 %unamrayl declaration and that returns an intrinsic 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 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: &sect.Feb: Canis Major 2: &sect.Jun: Ursa Minor 3: &sect.Nov: Andromeda

See also