CountSubset (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Template:Arraylist:CountSubset subtitle}}
{{Template:Arraylist:CountSubset subtitle}}


This page is [[under construction]].


==Syntax==
==Syntax==
Line 11: Line 8:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%count</th>
<tr><th>%count</th>
<td>number</td></tr>
<td>A numeric variable to contain the count of matching items.</td></tr>


<tr><th>al</th>
<tr><th>al</th>
<td>Arraylist object</td></tr>
<td>An <var>Arraylist</var> object.</td></tr>


<tr><th>selectionCriterion</th>
<tr><th>selectionCriterion</th>
<td><var>SelectionCriterion</var> object</td></tr>
<td>A <var>[[SelectionCriterion class|SelectionCriterion]]</var> object, which is a relational expression that is applied to an <var class="term">al</var> item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a numeric or string value.
<p>
For example, <code>GT(this, -11)</code> is the criterion <code>this > -11</code>, where <var>this</var> is an identity function value that simply returns the item's value. The items that satisfy this expression populate the subset whose count <var>CountSubset</var> returns.</p>
<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 <var class="term">al</var> <var>Arraylist</var> 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"]].</p></td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>A <var>CountSubset</var> call with a particular selection criterion is equivalent to a count of the items in the subset returned by the <var>[[SubsetNew (Arraylist function)|SubsetNew]]</var> method.  
<li>A <var>CountSubset</var> call with a particular selection criterion is equivalent to a count of the items in the subset returned by the <var>[[SubsetNew (Arraylist function)|SubsetNew]]</var> method with that criterion.  
</ul>
</ul>


==Examples==
==Examples==
The following request shows a <var>CountSubset</var> call with a simple selection criterion:
<p class="code">begin
  %al is  arraylist of float
  %al = list(111, 29, 0, 93, 77, -345)
  %sel is object selectioncriterion for float
  %sel = GT(this, 0)
  printText {~} = {%al:countSubset(%sel)}
end
</p>
The result is:
<p class="output">%al:countSubset(%sel) = 4
</p>


==See also==
==See also==
{{Template:Arraylist:CountSubset footer}}
{{Template:Arraylist:CountSubset footer}}

Latest revision as of 20:02, 17 July 2012

Number of items matching a criterion (Arraylist class)

[Introduced in Sirius Mods 7.8]


Syntax

%count = al:CountSubset( selectionCriterion)

Syntax terms

%count A numeric variable to contain the count of matching items.
al An Arraylist object.
selectionCriterion A SelectionCriterion object, which is a relational expression that is applied to an al 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 value that simply returns the item's value. The items that satisfy this expression populate the subset whose count CountSubset 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 al Arraylist declaration and that returns a numeric or string value. This is described further in "Specifying a SelectionCriterion's parameters".

Usage notes

  • A CountSubset call with a particular selection criterion is equivalent to a count of the items in the subset returned by the SubsetNew method with that criterion.

Examples

The following request shows a CountSubset call with a simple selection criterion:

begin %al is arraylist of float %al = list(111, 29, 0, 93, 77, -345) %sel is object selectioncriterion for float %sel = GT(this, 0) printText {~} = {%al:countSubset(%sel)} end

The result is:

%al:countSubset(%sel) = 4

See also