True and False (SelectionCriterion functions): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 24: | Line 24: | ||
<td>A <var>SelectionCriterion</var> object variable to contain the new object instance. </td></tr> | <td>A <var>SelectionCriterion</var> object variable to contain the new object instance. </td></tr> | ||
<tr><th><var>%(SelectionCriterion For</var> itemtype)</th> | <tr><th><var>%(SelectionCriterion For</var> itemtype)</th> | ||
<td>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: <code>%(selectionCriterion For <i>itemtype</i>):</code> </td></tr> | <td>This optional specification of the class in parentheses indicates that the method is [[Notation conventions for methods#Shared methods|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: <code>%(selectionCriterion For <i>itemtype</i>):</code> </td></tr> | ||
</table> | </table> | ||
Revision as of 20:39, 28 July 2011
Create selection expression that returns any item or no items (SelectionCriterion class)
These shared methods take no parameters and create a new SelectionCriterion object.
A True criterion returns true for any collection item;
a False criterion returns false for any collection item.
True and False thus provide the equivalent of an empty SelectionCriterion, and they substitute for a New constructor in the SelectionCiterion class.
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):]True
%selectionCriterion = [%(SelectionCriterion For itemType):]False
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): |
Usage Notes
- True and False exist to simplify dynamic SelectionCriterion
applications.
If you are dynamically generating a
SelectionCriterion, under some conditions you may want the criterion to select all
objects or to select no objects.
In addition, if you are building a SelectionCriterion by using
Or in conditions,
it might be useful to start out with a False SelectionCriterion:
%sel = False if <somecondition1> then %sel = Or(%sel, Eq(foo, 'A')) end if if <somecondition2> then %sel = Or(%sel, Eq(foo, 'B')) end if if <somecondition3> then %sel = Or(%sel, Eq(foo, 'C')) end if
Similarly, if building a SelectionCriterion by using And in conditions, it might be useful to start out with a True SelectionCriterion.
Examples
The following statements are equivalent:
%sel = and(ge(this, 22), true) %sel = ge(this, 22)