And and Or (SelectionCriterion functions): Difference between revisions
m (→Syntax terms) |
mNo edit summary |
||
Line 67: | Line 67: | ||
==See also== | ==See also== | ||
{{Template:SelectionCriterion:And and Or footer}} | {{Template:SelectionCriterion:And and Or footer}} | ||
[[Category:SelectionCriterion methods]] |
Revision as of 19:45, 24 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 that makes use of a SelectionCriterion 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)
Syntax terms
%selectionCriterion | A SelectionCriterion object variable to contain the new object instance. |
---|---|
%(SelectionCriterion For itemtype) | This optional specification of the class in parentheses indicates that the method is shared and does not operate on a specific instance. If you use this option, however, you must include the collection item type to which the selection expression will be applied, like this: %(selectionCriterion For itemtype): |
list | A comma-separated list of one or more SelectionCriterion objects. |
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
- The following criterion
matches numbers less than 70 and greater than or equal to 95:
%sel = OR(lt(this,70), ge(this,95))
- The following criterion matches numbers that are
less than or equal to 33 but not 30:
%sel = AND(le(this, 33), ne(this,30)))