SubsetNew (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
{{Template:Arraylist:SubsetNew subtitle}}
{{Template:Arraylist:SubsetNew subtitle}}
[[Category:Arraylist methods|SubsetNew function]]
[[Category:Arraylist methods|SubsetNew function]]
<!--DPL?? Category:Arraylist methods|SubsetNew function: Return all matching Arraylist items-->
<!--DPL?? Category:Arraylist methods|<var>SubsetNew</var> function: Return all matching Arraylist items-->
<p>
<p>
SubsetNew is a member of the [[Arraylist class]].
<var>SubsetNew</var> is a member of the [[Arraylist class]].
</p>
</p>


Line 9: Line 9:
all items that match a specified criterion.
all items that match a specified criterion.
The criterion is supplied by the [[SelectionCriterion class|SelectionCriterion]] object
The criterion is supplied by the [[SelectionCriterion class|SelectionCriterion]] object
that is the required SubsetNew parameter.
that is the required <var>SubsetNew</var> parameter.
If no item satisfies the criterion, SubsetNew returns an empty Arraylist.
If no item satisfies the criterion, <var>SubsetNew</var> returns an empty Arraylist.


SubsetNew is available in ''Sirius Mods'' version 7.6 and later.
<var>SubsetNew</var> is available in ''Sirius Mods'' version 7.6 and later.
==Syntax==
==Syntax==
{{Template:Arraylist:SubsetNew syntax}}
{{Template:Arraylist:SubsetNew syntax}}
Line 18: Line 18:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th><i>%arraylNew</i></th>
<tr><th><i>%arraylNew</i></th>
<td>An Arraylist variable of the same type as the method Arraylist (''%arrayl'') to contain the items that are located by the search. If ''%arraylNew'' is not empty, its contents are discarded before it is populated by the return items from SubsetNew. </td></tr>
<td>An Arraylist variable of the same type as the method Arraylist (''%arrayl'') to contain the items that are located by the search. If ''%arraylNew'' is not empty, its contents are discarded before it is populated by the return items from <var>SubsetNew</var>. </td></tr>
<tr><th><i>%arrayl</i></th>
<tr><th><i>%arrayl</i></th>
<td>An Arraylist object. </td></tr>
<td>An Arraylist object. </td></tr>
<tr><th><i>criterion</i></th>
<tr><th><i>criterion</i></th>
<td>A SelectionCriterion object, which is a relational expression that is applied to an ''%arrayl'' item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a numeric or string value.
<td>A SelectionCriterion object, which is a relational expression that is applied to an ''%arrayl'' 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, <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 Arraylist 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 Arraylist that <var>SubsetNew</var> 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 ''%arrayl'' 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 ''%arrayl'' 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>
Line 29: Line 29:
<ul>
<ul>
<li>[[FindNextItem (Arraylist function)|FindNextItem]] without the ''Start='' argument
<li>[[FindNextItem (Arraylist function)|FindNextItem]] without the ''Start='' argument
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>
==Examples==
==Examples==
<ul>
<ul>
<li>The following request contains two SubsetNew calls, one with a simple
<li>The following request contains two <var>SubsetNew</var> calls, one with a simple
selection criterion and one with a compound criterion:
selection criterion and one with a compound criterion:
<pre style="xmp">
<pre style="xmp">
Line 48: Line 48:
     %sel2 = AND(GE(this, 50), LT(this, 93))
     %sel2 = AND(GE(this, 50), LT(this, 93))


     %alnew = %al:SubsetNew(%sel1)
     %alnew = %al:<var>SubsetNew</var>(%sel1)
     Print 'The result of selection1 is:'
     Print 'The result of selection1 is:'
     %alnew:print
     %alnew:print
     %alnew = %al:SubsetNew(%sel2)
     %alnew = %al:<var>SubsetNew</var>(%sel2)
     Print 'The result of selection2 is:'
     Print 'The result of selection2 is:'
     %alnew:print
     %alnew:print

Revision as of 23:58, 19 January 2011

Return all matching Arraylist items (Arraylist class)

SubsetNew is a member of the Arraylist class.

This function searches the entire Arraylist 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 Arraylist.

SubsetNew is available in Sirius Mods version 7.6 and later.

Syntax

%newList = al:SubsetNew( selectionCriterion)

Syntax terms

%arraylNew An Arraylist variable of the same type as the method Arraylist (%arrayl) to contain the items that are located by the search. If %arraylNew is not empty, its contents are discarded before it is populated by the return items from SubsetNew.
%arrayl An Arraylist object.
criterion A SelectionCriterion object, which is a relational expression that is applied to an %arrayl 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 Arraylist 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 %arrayl declaration and that returns a numeric or string value. This is described further in "Specifying a SelectionCriterion's parameters".

Usage notes

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

Examples

  • The following request contains two SubsetNew calls, one with a simple selection criterion and one with a compound criterion:
        Begin
    
        %al is  arraylist of float
        %alnew is  arraylist of float
        %al = list(111, 29, 0, 93, 77, -345)
    
        %sel1 is object selectioncriterion for float
        %sel2 is object selectioncriterion for float
        %sel1 = GT(this, 0)
        %sel2 = AND(GE(this, 50), LT(this, 93))
    
        %alnew = %al:<var>SubsetNew</var>(%sel1)
        Print 'The result of selection1 is:'
        %alnew:print
        %alnew = %al:<var>SubsetNew</var>(%sel2)
        Print 'The result of selection2 is:'
        %alnew:print
    
        End
    

    The result is:

        The result of selection1 is:
        1: 111
        2: 29
        3: 93
        4. 77
        The result of selection2 is:
        1: 93
        2: 77