And and Or (SelectionCriterion functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>Create selection expression based on logical operat</b></span>
{{Template:SelectionCriterion:And and Or subtitle}}
[[Category:SelectionCriterion methods|OR and AND constructors]]
<!--DPL?? Category:SelectionCriterion methods|OR and AND constructors: Create selection expression based on logical operat-->
<!--DPL?? Category:System methods|OR and AND (SelectionCriterion constructors): Create selection expression based on logical operat-->
<p>
OR and AND are members of the [[SelectionCriterion class]].
</p>


These shared methods each create a new SelectionCriterion object
These shared methods each create a new SelectionCriterion object
Line 26: Line 20:
<li>Where in the collection to begin searching.
<li>Where in the collection to begin searching.
</ul>
</ul>
==OR syntax (same for AND)==
==Syntax==
{{Template:SelectionCriterion:And syntax}}
{{Template:SelectionCriterion:Or syntax}}
   %selc = [%(selectionCriterion for itemtype):]  -
   %selc = [%(selectionCriterion for itemtype):]  -
             OR(criterion1 [,&nbsp;criterion2] ... [,&nbsp;criterionN])
             OR(criterion1 [,&nbsp;criterion2] ... [,&nbsp;criterionN])
Line 72: Line 68:
</pre>
</pre>
</ol>
</ol>
==See also==
{{Template:SelectionCriterion:And and Or footer}}

Revision as of 02:28, 23 June 2011

Create selection expression based on logical operator (SelectionCriterion class)


These shared methods each create a new SelectionCriterion object that is an expression used to select the items in a collection. Each constructor uses a different logical operator to form an expression that combines one or more SelectionCriterion objects.

An OR criterion returns true for a collection item if any of the component SelectionCriterion expressions are true for the item; otherwise it returns false. An AND criterion returns true if all of the component SelectionCriterion expressions are true for the item; otherwise it returns false.

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.

Syntax

%selectionCriterion = [%(SelectionCriterion For itemType):]And( list)

%selectionCriterion = [%(SelectionCriterion For itemType):]Or( list)

  %selc = [%(selectionCriterion for itemtype):]  -
           OR(criterion1 [, criterion2] ... [, criterionN])

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.
criterion
A SelectionCriterion object.

Usage notes

  • All OR and AND SelectionCriterion conditions are short-circuiting conditions. That is, if any of the conditions in an OR return True, the subsequent conditions are not evaluated and the OR returns True. Similarly, if any of the conditions in an AND return False, the subsequent conditions are not evaluated, and the AND returns a False. Therefore, it is wise to put the most likely conditions first in an OR, and it is wise to put the least likely first in an AND. For a mix of conditions where some are simply variable references and others require method evaluation, it probably is best to put the variable references first, as these are probably much cheaper to evaluate.

Examples

  1. The following criterion matches numbers less than 70 and greater than or equal to 95:
        %sel = OR(lt(this,70), ge(this,95))
    
  2. The following criterion matches numbers that are less than or equal to 33 but not 30:
        %sel = AND(le(this, 33), ne(this,30)))
    

See also