SelectionCriterion class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__TOC__
__TOC__
Objects in the SelectionCriterion class are used primarily as input to the
Objects in the <var>SelectionCriterion</var> class are used primarily as input to the
collection class searching methods ([[??]] refid=srchcol.).
collection class [[Collections#Sorting an Arraylist using one sort criterion|searching methods]].
The searching methods take a SelectionCriterion object as a parameter which
The searching methods take a <var>SelectionCriterion</var> object as a parameter which
provides an item selection specification for the search.
provides an item selection specification for the search.
   
   
Line 8: Line 8:
that tests a collection item value to determine whether the item
that tests a collection item value to determine whether the item
(or its item number) is to be returned by the searching method.
(or its item number) is to be returned by the searching method.
The SelectionCriterion methods are named for the operation they provide:
The <var>SelectionCriterion</var> methods are named for the operation they provide:
<ul>
<ul>
<li>EQ (equal to), NE (not equal to), LT (less than), LE (less than or equal to),
<li>Comparisons: <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Eq]]</var> (equal to), <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Ne]]</var> (not equal to), <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Lt]]</var> (less than), <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Le]]</var> (less than or equal to),
GT (greater than), GE (greater than or equal to).
<var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Gt]]</var> (greater than), <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Ge]]</var> (greater than or equal to). The type of comparison performed is the same as the type of the first argument of the given comparison method: <var>String</var>, <var>Float</var>, or <var>Unicode</var>.
<li>The AND, OR, and NOT methods let you combine comparison operations in a single criterion.
 
<li>The TRUE and FALSE methods respectively match all or no items.
<li>The <var>[[And and Or (SelectionCriterion functions)|And]]</var>, <var>[[And and Or (SelectionCriterion functions)|Or]]</var>, and <var>[[Not (SelectionCriterion function)|Not]]</var> methods let you combine comparison operations in a single criterion.
<li>The IsNull and IsNotNull methods respectively match a collection object that is Null
 
or one that is not Null.
<li>The <var>[[True and False (SelectionCriterion functions)|True]]</var> and <var>[[True and False (SelectionCriterion functions)|False]]</var> methods respectively match all or no items.
 
<li>The <var>[[IsNull and IsNotNull (SelectionCriterion functions)|IsNull]]</var> and <var>[[IsNull and IsNotNull (SelectionCriterion functions)|IsNotNull]]</var> methods respectively match a collection object that is <var>Null</var>
or one that is not <var>Null</var>.
</ul>
</ul>
   
   
Most SelectionCriterion objects use two parameters to construct a single criterion
Most <var>SelectionCriterion</var> objects use two parameters to construct a single criterion
for selecting a collection item; some use two or more SelectionCriterion objects
for selecting a collection item; some use two or more <var>SelectionCriterion</var> objects
to construct a single criterion.
to construct a single criterion.
   
   
As an example specification,
As an example specification,
the selection criterion ''%sel'' in the following
the selection criterion <code>%sel</code> in the following
statement, instantiated by the LT constructor method, matches
statement, instantiated by the LT constructor method, matches
a number whose square root is less than 10:
a number whose square root is less than 10:
<pre>
<p class="code"><nowiki>%sel = lt(squareRoot, 10)
    %sel = lt(squareRoot, 10)
</nowiki></p>
</pre>
   
   
Where the left- and right-hand elements of the comparison operation are,
Where the left- and right-hand elements of the comparison operation are,
respectively, the LT parameter values:
respectively, the <var>Lt</var> parameter values:
<ul>
<ul>
<li>The [[SquareRoot (Float function)|<tt>squareRoot</tt>]] intrinsic Float function
<li>The <var>[[SquareRoot (Float function)|SquareRoot]]</var> intrinsic <var>Float</var> function
is applied to each item value before the comparison is made.
is applied to each item value before the comparison is made.
<li><tt>10</tt> might be any expression of any User Language intrinsic type.
<li><tt>10</tt> might be any expression of any <var class="product">User Language</var> intrinsic type.
</ul>
</ul>
   
   
This ''%sel'' criterion might be used as follows to locate the
This <code>%sel</code> criterion might be used as follows to locate the
next Arraylist item after item 3 whose square root is less than 10:
next <var>Arraylist</var> item after item 3 whose square root is less than 10:
<pre>
<p class="code"><nowiki>%itemnum = %balance:findNextItemNumber(%sel, start=3)
    %itemnum = %balance:findNextItemNumber(%sel, start=3)
</nowiki></p>
</pre>
   
   
The requirements for the SelectionCriterion parameter exemplified by the SquareRoot
The requirements for the <var>SelectionCriterion</var> parameter exemplified by the <var>SquareRoot</var>
method above are:
method above are:
<ul>
<ul>
Line 52: Line 53:
</ul>
</ul>
   
   
For more about the method in a SelectionCriterion, see "[[#Specifying a SelectionCriterion's parameters|Specifying a SelectionCriterion's parameters]]" below.
For more about the method in a <var>SelectionCriterion</var>, see "[[#Specifying a SelectionCriterion's parameters|Specifying a SelectionCriterion's parameters]]" below.
   
   
Additional notes:
Additional notes:
<ul>
<ul>
<li>Comparison values are evaluated at SelectionCriterion construction time,
<li>Comparison values are evaluated at <var>SelectionCriterion</var> construction time,
not when the search method is evaluated.
not when the search method is evaluated.
That is, the following sequence selects
That is, the following sequence selects
items with income greater than or equal to 50000, not 100000:
items with income greater than or equal to 50000, not 100000:
<pre>
<p class="code"><nowiki>%income = 50000
    %income = 50000
%sel = ge(income, %income)
    %sel = ge(income, %income)
%income = 100000
    %income = 100000
%foo2 = %foo:subsetNew(%sel)
    %foo2 = %foo:subsetNew(%sel)
</nowiki></p>
</pre>
<li><var>SelectionCriterion</var> have a size limit: the
<li>SelectionCriterion have a size limit: the
<var>SelectionCriterion</var>, including the values for <var>Eq</var>, <var>Ne</var>, <var>Lt</var>, <var>Le</var>, <var>Ge</var>, and <var>Gt</var> comparisons must take less than 252 bytes.
SelectionCriterion, including the values for EQ, NE, LT, LE, GE, and GT
comparisons must take less than 252 bytes.
   
   
ANDs and ORs take 4 bytes, and
<var>And</var>s and <var>Or</var>s take 4 bytes, and
comparison selectors have 12 bytes of overhead plus the length of the value
comparison selectors have 12 bytes of overhead plus the length of the value
rounded to a 4-byte multiple.
rounded to a 4-byte multiple.
So, for example, an And condition with
So, for example, an <var>And</var> condition with
seven 20-byte values would take 4+7*(20+12), or 228, bytes.
seven 20-byte values would take 4+7*(20+12), or 228, bytes.
   
   
Line 79: Line 78:
encapsulating some or all of the conditions in a local method, since a local
encapsulating some or all of the conditions in a local method, since a local
enhancement method can be the method parameter for a comparison
enhancement method can be the method parameter for a comparison
SelectionCriterion.
<var>SelectionCriterion</var>.
<li>The SelectionCriterion methods are constructors and as such they can be
<li>The <var>SelectionCriterion</var> methods are [[Object variables#Virtual Constructor methods|virtual constructors]] and as such they can be
called with no method object, with an explicit class name, or with an
called with no method object, with an explicit class name, or with an
object variable, even if that object is null:
object variable, even if that object is <var>Null</var>:
<pre>
<p class="code"><nowiki>%selc1 = NE(criterion1, criterion2)
    %selc1 = NE(criterion1, criterion2)
   
   
    %selc2 = %(selectionCriterion for float): -
%selc2 = %(selectionCriterion for float):AND(criterion1, criterion2)        
              AND(criterion1, criterion2)
   
   
    %selc3 = %selc3:OR(criterion1, criterion2)
%selc3 = %selc3:OR(criterion1, criterion2)
</pre>
</nowiki></p>
</ul>
</ul>
   
   
The SelectionCriterion class is new as of ''Sirius Mods'' version 7.6.
The <var>SelectionCriterion</var> class is new as of <var class="product">Sirius Mods</var> version 7.6.
===Declaring a SelectionCriterion object variable===
===Declaring a SelectionCriterion object variable===
The SelectionCriterion class operates on specific objects, so a variable of the
The <var>SelectionCriterion</var> class operates on specific objects, so a variable of the
SelectionCriterion class must be qualified with the object to which it applies:
<var>SelectionCriterion</var> class must be qualified with the object to which it applies:
For example:
For example:
<pre>
<p class="code"><nowiki>%sel1 is object selectionCriterion for object myClass
    %sel1 is selectionCriterion for object myClass
%sel2 is object selectionCriterion for object xmlNode
    %sel2 is selectionCriterion for object xmlNode
%sel3 is object selectionCriterion for longstring
    %sel3 is selectionCriterion for longstring
</nowiki></p>
</pre>
   
   
The declaration for ''%sel'' in the example in the preceding section
The declaration for <code>%sel</code> in the example in the preceding section might be:
might be:
<p class="code"><nowiki>%sel is object selectionCriterion for float
<pre>
</nowiki></p>
    %sel is selectionCriterion for float
</pre>
   
   
====SelectionCriterion object variable declaration syntax====
====SelectionCriterion object variable declaration syntax====
  <objvar> Is Object SelectionCriterion For <itemtype>
<p class="syntax"><span class="term">objvar</span> <span class="literal">Is Object SelectionCriterion For</span> <span class="term">itemtype</span>
</p>
   
   
Where:
Where:
<dl>
<table class="syntaxTable">
<dt><objvar>
<tr><th>objvar</th>
<dd>The name of the SelectionCriterion object variable.
<td>The name of the <var>SelectionCriterion</var> object variable.
<dt><itemtype>
</td></tr>
<dd>The datatype of the items in the collection to be searched.
<tr><th>itemtype</th>
</dl>
<td>The datatype of the items in the collection to be searched.
</td></tr></table>
 
===Specifying a SelectionCriterion's parameters===
===Specifying a SelectionCriterion's parameters===
As stated earlier, most of the SelectionCriterion methods
The comparison <var>SelectionCriterion</var> methods
accept two parameters, the first a &ldquo;method value&rdquo; and the second an
accept two parameters, the first a "method value" and the second an
intrinsic value.
intrinsic value.
Regarding the first, just as
Regarding the first, just as
a User Language &ldquo;numeric&rdquo; argument can be a numeric literal or a variable or even an
a <var class="product">User Language</var> "numeric" argument can be a numeric literal or a variable or even an
expression that results in a number, a method value argument can be a method
expression that results in a number, a method value argument can be a method
literal or a method variable or an expression that results in a method.
literal or a method variable or an expression that results in a method.
   
   
More specifically,
More specifically, a method value is a value assigned to a [[Method variables|method variable]].
a method value is a value assigned to a [[Method variables|method variable]].
And for a <var>SelectionCriterion</var>, the method variable's ''implicit'' declaration is:
And for a SelectionCriterion, the method variable's ''implicit''
<p class="syntax"><span class="literal">Is Function (</span><span class="term">itemtype</span><span class="literal">):</span><span class="term">methname</span> <span class="literal">Is</span> <span class="term">intrinEnum</span></p>
declaration is:
<pre>
    Is Function (<itemtype>):<methname> Is <intrinType>
</pre>
Where:
Where:
<dl>
<table class="syntaxTable">
<dt><itemtype>
<tr><th>itemtype</th>
<dd>The class of the items in the collection to be sorted.
<td>The class of the items in the collection to be searched.
<dt><methname>
</td></tr>
<dd>A method name, but merely a placeholder in an actual declaration.
<tr><th>methname</th>
Any method (system or user), class
<td>A method name, but merely a placeholder in an actual declaration. Any method (system or user), class variable, or method variable that fits the declaration can be used in the <var>SelectionCriterion</var>.
Variable or Property, local method, or method variable that fits the
</td></tr>
declaration can be used in the SelectionCriterion.
<tr><th>intrinEnum</th>
<dt><intrinType>
<td>A <var class="product">User Language</var> [[Intrinsic classes#intrins_classes|intrinsic class]] type or an [[Enumerations|enumeration]] value returned by the function. <p>
<dd>A User Language [[Intrinsic classes#intrins_classes|intrinsic class]] type returned by the function.
'''Note:''' Enumeration values are allowed as of <var class="product">Sirius Mods</var> 7.8, but only in the <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Eq]]</var> and <var>[[Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions)|Ne]]</var> methods.</p>
</dl>
</td></tr></table>
   
   
The method value argument must conform to the following rules:
The method value argument must conform to the following rules:
<ul>
<ul>
<li>It must return an intrinsic value.
<li>It must return an intrinsic or enumeration value.
<li>It cannot have any parameters other than the method object.
<li>It cannot have any parameters other than the method object.
</ul>
</ul>
   
   
The following examples show different method argument types
The following examples show different method argument types
as the first parameter in a SelectionCriterion.
as the first parameter in a <var>SelectionCriterion</var>.
In the examples below, the method values are respectively a class Variable,
In the examples below, the method values are respectively a class variable,
a local method, and a special method value, all of which
a local method, and the special method value <var>This</var>, all of which
satisfy the Function template described above.
satisfy the <var>Function</var> template described above.
<ol>
<ol>
<li><div id="xmpxsub"></div>The selectionCriterion in the following example uses a class Variable, <tt>Income</tt>, as the criterion method parameter. The collection method, <tt>SubsetNew</tt>, returns a NamedArraylist that contains all the items that satisfied the selection criterion.
<li><div id="xmpxsub"></div>The <var>SelectionCriterion</var> in the following example uses a class variable, <code>Income</code>, as the criterion method parameter. The collection method, <var>SubsetNew</var>, returns a <var>NamedArraylist</var> that contains all the items that satisfied the selection criterion.
<pre>
<p class="code"><nowiki>Begin
    Begin
class foo
    class foo
  public
      public
      variable name  is string len 20
          variable name  is string len 20
      variable status is string len 8
          variable status is string len 8
      variable income is float
          variable income is float
      constructor newf(%a is string len 10, -
          constructor newf(%a is string len 10, -
              %b string len 8, %c is float)
                  %b string len 8, %c is float)
      function myprint is longstring
          function myprint is longstring
  end public
      end public
   
   
      constructor newf(%a is string len 10,    -
  constructor newf(%a is string len 10,    -
                  %b string len 8, %c is float)
              %b string len 8, %c is float)
          %this:name  = %a
      %this:name  = %a
          %this:status = %b
      %this:status = %b
          %this:income = %c
      %this:income = %c
      end constructor
  end constructor
   
   
      function myprint is longstring
  function myprint is longstring
        return %this:name with ' ' with -
    return %this:name with ' ' with -
          %this:status with ' ' with -
      %this:status with ' ' with -
          '(income: ' with %this:income with ')'
      '(income: ' with %this:income with ')'
      end function
  end function
    end class
end class
   
   
    %fool  is namedArraylist of object foo
%i is float
    %fool = new
%fool  is namedArraylist of object foo
    %fool('Jim') = newf('Red', 'employed', 45000)
%fool = new
    %fool('Jed') = newf('Black', 'retired', 30000)
%fool('Jim') = newf('Red', 'employed', 45000)
    %fool('Jan') = newf('Green', 'employed', 55000)
%fool('Jed') = newf('Black', 'retired', 30000)
    %fool('Jud') = newf('Brown', 'expired', 0)
%fool('Jan') = newf('Green', 'employed', 55000)
    %fool('Jon') = newf('White', 'tired', 70000)
%fool('Jud') = newf('Brown', 'expired', 0)
%fool('Jon') = newf('White', 'tired', 70000)
   
   
    %fool = %fool:subsetNew(gt(income, 0))
%fool = %fool:subsetNew(gt(income, 0))
   
   
    for %i from 1 to %fool:count
for %i from 1 to %fool:count
      print %fool:namebynumber(%i) And -
  print %fool:namebynumber(%i) And -
            %fool:itembyNumber(%i):myprint
        %fool:itembyNumber(%i):myprint
    end for
end for
   
   
    End
End
</pre>
</nowiki></p>
   
   
The result is:
The result is:
<pre>
<p class="code"><nowiki>Jan Green employed (income: 55000)
    Jan Green employed (income: 55000)
Jed Black retired (income: 30000)
    Jed Black retired (income: 30000)
Jim Red employed (income: 45000)
    Jim Red employed (income: 45000)
Jon White tired (income: 70000)
    Jon White tired (income: 70000)
</nowiki></p>
</pre>
 
<li>The second parameter in most <var>SelectionCriterion</var> methods is a User Language
<li>In most cases, the second parameter in most <var>SelectionCriterion</var> methods is a <var class="product">User Language</var>
intrinsic-type value, often a string or numeric literal.
intrinsic-type value, often a string or numeric literal.
Consequently, you cannot specify a criterion that compares two method
Consequently, you cannot specify a criterion that compares two method
values.
values.
For example, for a <tt>Cust</tt> class (similar to the class in the previous
For example, for a <code>Cust</code> class (similar to the class in the previous
example) with variables <tt>Expenses</tt>
example) with variables <code>Expenses</code>
and <tt>Income</tt>, you might want to find all the customers with expenses
and <code>Income</code>, you might want to find all the customers with expenses
greater than income &mdash; but the following <b><i>is not allowed</i></b>:
greater than income &mdash; but the following <b><i>is not allowed</i></b>:
<pre>
<p class="code"><nowiki>%custDebtors = %custs:subsetNew(gt(expenses, income))
    %custDebtors = %custs:subsetNew(gt(expenses, income))
</nowiki></p>
</pre>
   
   
However, you can create a [[Local and Common entities#Defining and invoking a local method|local method]]
However, you can create a [[Local and Common entities#Defining and invoking a local method|local method]]
with which you can achieve the same result:
with which you can achieve the same result:
<pre>
<p class="code"><nowiki>local function (cust):netIncome is float
    local function (cust):netIncome is float
  return %this:income - %this:expenses
      return %this:income - %this:expenses
end function
    end function
%custDebtors = %custs:subsetNew(lt(netIncome, 0))
    %custDebtors = %custs:subsetNew(lt(netIncome, 0))
</nowiki></p>
</pre>
<li><div id="xmpthis"></div>The <var>SelectionCriterion</var> in the following request uses the special method value <var>This</var> as the method parameter, and the <var>And</var> constructor combines two criteria to create one criterion. Valid only for intrinsic classes, <var>This</var> simply returns the value of the method object.
<li><div id="xmpthis"></div>The <var>SelectionCriterion</var> in the following request uses the special method value <var>This</var> as the method parameter, and the <var>And</var> constructor combines two criteria to create one criterion. Valid only for intrinsic classes, <var>This</var> simply returns the value of the method object.
<pre>
<p class="code"><nowiki>Begin
    Begin
%fooflt is  arraylist of float
    %fooflt is  arraylist of float
%fooflt = list(111, 29, 93, 77, -345)
    %fooflt = list(111, 29, 93, 77, -345)
   
   
    %sel is object selectioncriterion for float
%sel is object selectioncriterion for float
    %sel = and(gt(this, 50), le(this, 93))
%sel = and(gt(this, 50), le(this, 93))
    %fooflt = %fooflt:subsetnew(%sel)
%fooflt = %fooflt:subsetnew(%sel)
   
   
    %fooflt:print
%fooflt:print
    End
End
</pre>
</nowiki></p>
   
   
The result is:
The result is:
<pre>
<p class="code"><nowiki>1: 93
    1: 93
2: 77
    2: 77
</nowiki></p>
</pre>
</ol>
</ol>
==List of SelectionCriterion methods==
The [[List of SelectionCriterion methods|"List of SelectionCriterion methods"]] shows all the class methods.
[[Category:System classes]]
[[Category:System classes]]

Latest revision as of 20:11, 13 August 2012

Objects in the SelectionCriterion class are used primarily as input to the collection class searching methods. The searching methods take a SelectionCriterion object as a parameter which provides an item selection specification for the search.

A selection specification, or criterion, is a relational expression that tests a collection item value to determine whether the item (or its item number) is to be returned by the searching method. The SelectionCriterion methods are named for the operation they provide:

  • Comparisons: Eq (equal to), Ne (not equal to), Lt (less than), Le (less than or equal to), Gt (greater than), Ge (greater than or equal to). The type of comparison performed is the same as the type of the first argument of the given comparison method: String, Float, or Unicode.
  • The And, Or, and Not methods let you combine comparison operations in a single criterion.
  • The True and False methods respectively match all or no items.
  • The IsNull and IsNotNull methods respectively match a collection object that is Null or one that is not Null.

Most SelectionCriterion objects use two parameters to construct a single criterion for selecting a collection item; some use two or more SelectionCriterion objects to construct a single criterion.

As an example specification, the selection criterion %sel in the following statement, instantiated by the LT constructor method, matches a number whose square root is less than 10:

%sel = lt(squareRoot, 10)

Where the left- and right-hand elements of the comparison operation are, respectively, the Lt parameter values:

  • The SquareRoot intrinsic Float function is applied to each item value before the comparison is made.
  • 10 might be any expression of any User Language intrinsic type.

This %sel criterion might be used as follows to locate the next Arraylist item after item 3 whose square root is less than 10:

%itemnum = %balance:findNextItemNumber(%sel, start=3)

The requirements for the SelectionCriterion parameter exemplified by the SquareRoot method above are:

  • It must be a method or method variable defined to operate on the type of the items in the collection being searched.
  • It must return an intrinsic (number, string, unicode) value.

For more about the method in a SelectionCriterion, see "Specifying a SelectionCriterion's parameters" below.

Additional notes:

  • Comparison values are evaluated at SelectionCriterion construction time, not when the search method is evaluated. That is, the following sequence selects items with income greater than or equal to 50000, not 100000:

    %income = 50000 %sel = ge(income, %income) %income = 100000 %foo2 = %foo:subsetNew(%sel)

  • SelectionCriterion have a size limit: the SelectionCriterion, including the values for Eq, Ne, Lt, Le, Ge, and Gt comparisons must take less than 252 bytes. Ands and Ors take 4 bytes, and comparison selectors have 12 bytes of overhead plus the length of the value rounded to a 4-byte multiple. So, for example, an And condition with seven 20-byte values would take 4+7*(20+12), or 228, bytes. You can work around a criterion that exceeds 252 bytes by encapsulating some or all of the conditions in a local method, since a local enhancement method can be the method parameter for a comparison SelectionCriterion.
  • The SelectionCriterion methods are virtual constructors and as such they can be called with no method object, with an explicit class name, or with an object variable, even if that object is Null:

    %selc1 = NE(criterion1, criterion2) %selc2 = %(selectionCriterion for float):AND(criterion1, criterion2) %selc3 = %selc3:OR(criterion1, criterion2)

The SelectionCriterion class is new as of Sirius Mods version 7.6.

Declaring a SelectionCriterion object variable

The SelectionCriterion class operates on specific objects, so a variable of the SelectionCriterion class must be qualified with the object to which it applies: For example:

%sel1 is object selectionCriterion for object myClass %sel2 is object selectionCriterion for object xmlNode %sel3 is object selectionCriterion for longstring

The declaration for %sel in the example in the preceding section might be:

%sel is object selectionCriterion for float

SelectionCriterion object variable declaration syntax

objvar Is Object SelectionCriterion For itemtype

Where:

objvar The name of the SelectionCriterion object variable.
itemtype The datatype of the items in the collection to be searched.

Specifying a SelectionCriterion's parameters

The comparison SelectionCriterion methods accept two parameters, the first a "method value" and the second an intrinsic value. Regarding the first, just as a User Language "numeric" argument can be a numeric literal or a variable or even an expression that results in a number, a method value argument can be a method literal or a method variable or an expression that results in a method.

More specifically, a method value is a value assigned to a method variable. And for a SelectionCriterion, the method variable's implicit declaration is:

Is Function (itemtype):methname Is intrinEnum

Where:

itemtype The class of the items in the collection to be searched.
methname A method name, but merely a placeholder in an actual declaration. Any method (system or user), class variable, or method variable that fits the declaration can be used in the SelectionCriterion.
intrinEnum A User Language intrinsic class type or an enumeration value returned by the function.

Note: Enumeration values are allowed as of Sirius Mods 7.8, but only in the Eq and Ne methods.

The method value argument must conform to the following rules:

  • It must return an intrinsic or enumeration value.
  • It cannot have any parameters other than the method object.

The following examples show different method argument types as the first parameter in a SelectionCriterion. In the examples below, the method values are respectively a class variable, a local method, and the special method value This, all of which satisfy the Function template described above.

  1. The SelectionCriterion in the following example uses a class variable, Income, as the criterion method parameter. The collection method, SubsetNew, returns a NamedArraylist that contains all the items that satisfied the selection criterion.

    Begin class foo public variable name is string len 20 variable status is string len 8 variable income is float constructor newf(%a is string len 10, - %b string len 8, %c is float) function myprint is longstring end public constructor newf(%a is string len 10, - %b string len 8, %c is float) %this:name = %a %this:status = %b %this:income = %c end constructor function myprint is longstring return %this:name with ' ' with - %this:status with ' ' with - '(income: ' with %this:income with ')' end function end class %i is float %fool is namedArraylist of object foo %fool = new %fool('Jim') = newf('Red', 'employed', 45000) %fool('Jed') = newf('Black', 'retired', 30000) %fool('Jan') = newf('Green', 'employed', 55000) %fool('Jud') = newf('Brown', 'expired', 0) %fool('Jon') = newf('White', 'tired', 70000) %fool = %fool:subsetNew(gt(income, 0)) for %i from 1 to %fool:count print %fool:namebynumber(%i) And - %fool:itembyNumber(%i):myprint end for End

    The result is:

    Jan Green employed (income: 55000) Jed Black retired (income: 30000) Jim Red employed (income: 45000) Jon White tired (income: 70000)

  2. In most cases, the second parameter in most SelectionCriterion methods is a User Language intrinsic-type value, often a string or numeric literal. Consequently, you cannot specify a criterion that compares two method values. For example, for a Cust class (similar to the class in the previous example) with variables Expenses and Income, you might want to find all the customers with expenses greater than income — but the following is not allowed:

    %custDebtors = %custs:subsetNew(gt(expenses, income))

    However, you can create a local method with which you can achieve the same result:

    local function (cust):netIncome is float return %this:income - %this:expenses end function %custDebtors = %custs:subsetNew(lt(netIncome, 0))

  3. The SelectionCriterion in the following request uses the special method value This as the method parameter, and the And constructor combines two criteria to create one criterion. Valid only for intrinsic classes, This simply returns the value of the method object.

    Begin %fooflt is arraylist of float %fooflt = list(111, 29, 93, 77, -345) %sel is object selectioncriterion for float %sel = and(gt(this, 50), le(this, 93)) %fooflt = %fooflt:subsetnew(%sel) %fooflt:print End

    The result is:

    1: 93 2: 77

List of SelectionCriterion methods

The "List of SelectionCriterion methods" shows all the class methods.