Eq, Ne, Ge, Gt, Le and Lt (SelectionCriterion functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{DISPLAYTITLE:EQ, NE, GE, GT, LE, and LT (SelectionCriterion_functions)}}
{{DISPLAYTITLE:EQ, NE, GE, GT, LE, and LT (SelectionCriterion?functions)}}
<span style="font-size:120%; color:black"><b>Create selection expression based on</b></span>
<span style="font-size:120%; color:black"><b>Create selection expression based on</b></span>
[[Category:SelectionCriterion methods|EQ, NE, GE, GT, LE, and LT constructors]]
[[Category:SelectionCriterion methods|EQ, NE, GE, GT, LE, and LT constructors]]

Revision as of 20:42, 22 February 2011

Create selection expression based on

EQ, NE, GE, GT, LE, and LT are members of the SelectionCriterion class.

These shared methods each create a new SelectionCriterion object that is a relational expression used to select items from a collection. Each of these constructors provides a different comparison operator. The EQ method, for example, constructs an equality expression that selects a collection item if the expression is true for that item. The other methods construct, respectively, not-equal-to, greater-than-or-equal-to, greater-than, less-than-or-equal-to, or less-than expressions.

The collection searching method (?? refid=srchcol.) that makes use of a selection criterion specifies:

  • Whether to return the first item or item number or all items that satisfy the selection criterion.
  • Where in the collection to begin searching.

The first of the two parameters in a selection criterion specifies a function that is applied to a collection item. The function result is the “left-side” operand in the criterion's expression. The second selection criterion parameter is a string or numeric that is the “right-side” operand in the expression. EQ(name, 'Ortiz') specifies the expression name='Ortiz'.

The function parameter of one of these constructors might simply be an identity function that returns the item value. Or, for example, it might be a function that returns the value of a class member for an item that is an object. This function must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, Longstring, or Unicode) value.

EQ syntax (same for NE, GE, GT, LE, and LT)

  %selc = [%(selectionCriterion for itemtype):]  -
           EQ(function, value)

Syntax terms

%selc
A SelectionCriterion object variable to contain the new object instance.
%(selectionCriterion for itemtype)
This optional specification of the class and collection item type in parentheses indicates that the method is shared and does not operate on a specific instance.
function
A method value (a method name literal, a method variable, a class Variable, or even a method that returns a method value) for a method that operates on objects of the type specified on the declaration of the collection being searched, and that returns a User Language intrinsic (numeric, string, or Unicode) value.
value
An intrinsic value or expression. For a string value comparison, character case does not matter.

Usage notes

  • For more information about the function parameter, see "Specifying a SelectionCriterion's parameters".
  • The function parameter is a method value, not a User Language expression, and you may not specify a function that itself has an argument. The SelectionCriterion syntax does not provide for specifying a parameter for the function parameter. If necessary, the workaround for this restriction is to define a local method that accepts an argument, then use that method as the function parameter.
  • The function may be This, an identity method that is valid for User Language intrinsic method objects only. The This method returns the value of the item to which it is applied. See the example using This.

Examples

  1. The following criterion matches a number greater than 10:
        %sel = gt(this, 10)
    

    The following matches a number with an absolute value less than or equal to 100:

        %sel = le(absolute, 100)
    

    The following matches numbers less than 70 and greater than or equal to 95:

        %sel = or(lt(this,70), ge(this,95))
    
  2. The following request fragment selects two items from the %fool NamedArraylist in the SubsetNew example:
         ...
        %sel is object selectionCriterion for object foo
        %sel = EQ(status, 'Employed')
        %fool = %fool:subsetNew(%sel)
    
        for %i from 1 to %fool:count
           print %fool:namebynumber(%i) And -
                 %fool:itembyNumber(%i):myprint
        end for
         ...
    

    The result is:

        Jan Green employed (income: 55000)
        Jim Red employed (income: 45000)