True and False (SelectionCriterion functions): Difference between revisions
m (Created page with "{{Template:SelectionCriterion:True and False subtitle}} These shared methods take no parameters and create a new SelectionCriterion object. A TRUE criterion returns true for any...") |
m (→Syntax terms) |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:SelectionCriterion:True and False subtitle}} | {{Template:SelectionCriterion:True and False subtitle}} | ||
These shared methods take no parameters and create a new SelectionCriterion object. | These [[Notation conventions for methods#Shared members|shared methods]] take no parameters and create a new <var>SelectionCriterion</var> object. | ||
A | A <var>True</var> criterion returns true for any collection item; | ||
a | a <var>False</var> criterion returns false for any collection item. | ||
<var>True</var> and <var>False</var> thus provide the equivalent of an empty <var>SelectionCriterion</var>, | |||
and they substitute for a New constructor in the SelectionCiterion class. | and they substitute for a <var>New</var> constructor in the <var>SelectionCiterion</var> class. | ||
The collection searching method | The [[Collections#Searching a collection|collection searching method]] | ||
that makes use of a | that makes use of a <var>SelectionCriterion</var> specifies: | ||
<ul> | <ul> | ||
<li>Whether to return the first item or item number or all items that satisfy the | <li>Whether to return the first item or item number or all items that satisfy the | ||
Line 15: | Line 15: | ||
<li>Where in the collection to begin searching. | <li>Where in the collection to begin searching. | ||
</ul> | </ul> | ||
==Syntax== | |||
{{Template:SelectionCriterion:True syntax}} | {{Template:SelectionCriterion:True syntax}} | ||
{{Template:SelectionCriterion:False syntax}} | {{Template:SelectionCriterion:False syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
< | <table class="syntaxTable"> | ||
< | <tr><th>%selectionCriterion</th> | ||
< | <td>A <var>SelectionCriterion</var> object variable to contain the new object instance. </td></tr> | ||
< | <tr><th nowrap="true"><var>[%(SelectionCriterion For </var>itemType<var>):]</var> | ||
< | <td>This optional specification of the class in parentheses denotes a [[Notation conventions for methods#Constructors|virtual constructor]]. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a <var>SelectionCriterion</var> virtual constructor. </td></tr> | ||
in parentheses | </table> | ||
==Usage Notes== | |||
<ul> | <ul> | ||
<li> | As described in [[Object variables#Virtual Constructor methods|"Virtual Constructor methods"]], <var>True</var> and <var>False</var> can be invoked with | ||
no method object, with an explicit class specification, or with an object variable of the class, | |||
even if that object is <var>Null</var>: | |||
<p class="code">%selCrit = True | |||
%selCrit = %(SelectionCriterion for float):False | |||
%selCrit = %selCrit:True | |||
</p> | |||
'''Note:''' | |||
As shown in the second of these above, if you explicitly specify the | |||
class name, you must include the item datatype of the collection to be searched, just as on a <var>SelectionCriterion</var> object variable's [[SelectionCriterion class#Declaring a SelectionCriterion object variable|declaration]]. | |||
<li><var>True</var> and <var>False</var> exist to simplify dynamic <var>SelectionCriterion</var> | |||
applications. | applications. | ||
If you are dynamically generating a | If you are dynamically generating a | ||
SelectionCriterion, under some conditions you may want the criterion to select all | <var>SelectionCriterion</var>, under some conditions you may want the criterion to select all | ||
objects or to select no objects. | objects or to select no objects. | ||
In addition, if you are building a SelectionCriterion by using | In addition, if you are building a <var>SelectionCriterion</var> by using | ||
[[ | <var>[[And and Or (SelectionCriterion functions)|Or]]</var> in conditions, | ||
it might be useful to start out with a | it might be useful to start out with a <var>False</var> <var>SelectionCriterion</var>: | ||
< | <p class="code">%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 | |||
</p> | |||
</ | |||
Similarly, if building a SelectionCriterion by using [[ | Similarly, if building a <var>SelectionCriterion</var> by using <var>[[And and Or (SelectionCriterion functions)|And]]</var> in conditions, | ||
it might be useful to start out with a | it might be useful to start out with a <var>True</var> <var>SelectionCriterion</var>. | ||
</ul> | </ul> | ||
==Examples== | |||
The following statements are equivalent: | The following statements are equivalent: | ||
< | <p class="code">%sel = and(ge(this, 22), true) | ||
%sel = ge(this, 22) | |||
</ | </p> | ||
==See also== | |||
{{Template:SelectionCriterion:True and False footer}} | {{Template:SelectionCriterion:True and False footer}} |
Latest revision as of 21:12, 30 November 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 denotes a virtual constructor. See "Usage notes", below, for more information about invoking a SelectionCriterion virtual constructor. |
Usage Notes
-
As described in "Virtual Constructor methods", True and False can be invoked with
no method object, with an explicit class specification, or with an object variable of the class,
even if that object is Null:
- 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.
%selCrit = True %selCrit = %(SelectionCriterion for float):False %selCrit = %selCrit:True
Note: As shown in the second of these above, if you explicitly specify the class name, you must include the item datatype of the collection to be searched, just as on a SelectionCriterion object variable's declaration.
Examples
The following statements are equivalent:
%sel = and(ge(this, 22), true) %sel = ge(this, 22)