True and False (SelectionCriterion functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
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...")
 
mNo edit summary
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 shared methods take no parameters and create a new <var>SelectionCriterion</var> object.
A TRUE criterion returns true for any collection item;
A <var>True</var> criterion returns true for any collection item;
a FALSE criterion returns false for any collection item.
a <var>False</var> criterion returns false for any collection item.


TRUE and FALSE thus provide the equivalent of an empty SelectionCriterion,
<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 ([[??]] refid=srchcol.)
The [[Collections#Searching a collection|collection searching method]]
that makes use of a selection criterion specifies:
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===
==Syntax==
{{Template:SelectionCriterion:True syntax}}
{{Template:SelectionCriterion:True syntax}}
{{Template:SelectionCriterion:False syntax}}
{{Template:SelectionCriterion:False syntax}}


===Syntax terms===
===Syntax terms===
<dl>
<table class="syntaxTable">
<dt><i>%selc</i>
<tr><th>%selectionCriterion</th>
<dd>A SelectionCriterion object variable to contain the new object instance.
<td>A <var>SelectionCriterion</var> object variable to contain the new object instance. </td></tr>
<dt><i>%(selectionCriterion for itemtype)</i>
<tr><th><var>%(SelectionCriterion For</var> itemtype)</th>
<dd>This optional specification of the class and collection item type
<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>
in parentheses indicates
</table>
that the method is shared and does not operate on a specific instance.


</dl>
==Usage Notes==
===Usage Notes===
<ul>
<ul>
<li>TRUE and FALSE exist to simplify dynamic SelectionCriterion
<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
[[OR and AND (SelectionCriterion constructors)|OR]] in conditions,
<var>[[And and Or (SelectionCriterion functions)|Or]]</var> in conditions,
it might be useful to start out with a FALSE SelectionCriterion:
it might be useful to start out with a <var>False</var> <var>SelectionCriterion</var>:
<pre>
<p class="code">%sel = False
    %sel = FALSE
if <somecondition1> then %sel = Or(%sel, Eq(foo, 'A'))
    if <somecondition1> then %sel = OR(%sel, EQ(foo, 'A'))
end if
    end if
if <somecondition2> then %sel = Or(%sel, Eq(foo, 'B'))
    if <somecondition2> then %sel = OR(%sel, EQ(foo, 'B'))
end if
    end if
if <somecondition3> then %sel = Or(%sel, Eq(foo, 'C'))
    if <somecondition3> then %sel = OR(%sel, EQ(foo, 'C'))
end if
    end if
</p>
</pre>


Similarly, if building a SelectionCriterion by using [[OR and AND (SelectionCriterion constructors)|AND]] in conditions,
Similarly, if building a <var>SelectionCriterion</var> by using [[And and Or (SelectionCriterion functions)|And]] in conditions,
it might be useful to start out with a TRUE SelectionCriterion.
it might be useful to start out with a <var>True</var> <var>SelectionCriterion</var>.
</ul>
</ul>


===Examples===
==Examples==


The following statements are equivalent:
The following statements are equivalent:
<pre>
<p class="code">%sel = and(ge(this, 22), true)
    %sel = and(ge(this, 22), true)


    %sel = ge(this, 22)
%sel = ge(this, 22)
</pre>
</p>


==See also==
{{Template:SelectionCriterion:True and False footer}}
{{Template:SelectionCriterion:True and False footer}}

Revision as of 19:36, 24 June 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)

See also