List (SortOrder function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
Line 1: Line 1:
{{Template:SortOrder:List subtitle}}
{{Template:SortOrder:List subtitle}}


This shared function is a virtual constructor, or factory method, for SortOrders.
This shared function is a virtual constructor, or factory method, for <var>SortOrders</var>.
The List
The <var>List</var>
method invokes the creation of a new SortOrder instance, then populates that
method invokes the creation of a new <var>SortOrder</var> instance, then populates that
instance with items from an input list that are themselves SortOrder instances.
instance with items from an input list that are themselves <var>SortOrder</var> instances.
Designed for specifying multiple sort criteria, the SortOrders in the object that
Designed for specifying multiple sort criteria, the <var>SortOrders</var> in the object that
List returns are applied consecutively by the sorting method
<var>List</var> returns are applied consecutively by the sorting method
that uses the SortOrder.
that uses the <var>SortOrder</var>.
==Syntax==
==Syntax==
{{Template:SortOrder:List syntax}}
{{Template:SortOrder:List syntax}}
===Syntax terms===
===Syntax terms===
<dl>
<table class="syntaxTable">
<dt><i>%sord</i>
<tr><th>%sortOrder</th>
<dd>A SortOrder object variable to contain the new object instance.
<td>A <var>SortOrder</var> object variable to contain the new object instance. </td></tr>
<dt><i>%(sortorder for itemtype)</i>
<tr><th><var>%(SortOrder 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>%(SortOrder For <i>itemtype</i>):</code> </td></tr>
in parentheses indicates
<tr><th>sortOrderItems</th>
that the method is shared and does not operate on a specific instance.
<td>A comma-delimited set of <var>SortOrder</var> objects, which may be explicitly specified [[Ascending and Descending (SortOrder functions)|Ascending/Descending constructors]],
<dt><i>sordlist</i>
<var>SortOrder</var> object variables, or another <var>SortOrder</var> <var>List</var> specification.
<dd>A comma-delimited set of SortOrder objects, which may be explicitly specified
These individual <var>SortOrders</var> are applied to the target collection items
[[Ascending and Descending (SortOrder functions)|Ascending/Descending constructors]],
SortOrder object variables, or another SortOrder List specification.
These individual SortOrders are applied to the target collection items
in the order they are specified in this argument.
in the order they are specified in this argument.


If a sortorder like ascending(price) is a single sort criterion, then the
If a <var>SortOrder</var> like <code>ascending(price)</code> is a single sort criterion, then the maximum number of sort criteria a <var>List</var> call may produce is seven. </td></tr>
maximum number of sort criteria a List call may produce is seven.
</table>
 
</dl>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>For more information about factory methods, see [[??]] refid=vconst..
<li>For more information about factory methods, see [[Object variables#Virtual Constructor methods|Virtual Constructor methods"]].
<li>List is a constructor and as such can be called with no method
<li><var>List</var> is a constructor and as such can be called with no method
object, with an explicit class name, or with an object variable,
object, with an explicit class name, or with an object variable,
even if that object is null:
even if that object is <var>Null</var>:
<pre>
<p class="code">%sortOrder = List(<i>sortOrderItems</i>)
    %sord = List(&amp;'italic(sordlist))
%sortOrder = %(sortorder for float):List(<i>sortOrderItems</i>)
    %sord = %(sortorder for float):List(&amp;'italic(sordlist))
%sortOrder = %sortOrder:List(<i>sortOrderItems</i>)
    %sord = %sord:List(&amp;'italic(sordlist))
</p>
</pre>
</ul>
</ul>
==Examples==
==Examples==
The typical way to use <var>SortOrder</var> lists is in a [[Collections|collection]] class [[Collections#Sorting an Arraylist using one sort criterion|sorting method]] invocation:
<p class="code">%orders:sort(%myorder)
</p>


The typical way to use SortOrder lists is in a Sort or SortNew
Where, for example:
method invocation:
<p class="code">%myorder = list(ascending(quantity), descending(price))
<pre>
</p>
    %orders:sort(%myorder)
</pre>


Where, for example:
Since the arguments to the <var>SortOrder</var> <var>List</var> method are also <var>SortOrders</var>, you could
<pre>
also pass the <code>%myorder</code> variable in another <var>List</var> call.
    %myorder = list(ascending(quantity), descending(price))
The following <var>List</var> statement
</pre>
inserts the <code>%myorder</code> criteria into the middle of two other sort criteria:
<p class="code">%mynewOrder = list(ascending(length), %myorder, -
                        descending(reverse))
</p>


Since the arguments to the SortOrder List method are also SortOrders, you could
You can even pass a <var>List call</var> within a <var>List</var> call:
also pass the %myorder variable in another List call.
<p class="code">%myorder = list(ascending(change),     -
The following List statement
  list(ascending(quantity), descending (price)))
inserts the %myorder criteria into the middle of two other sort criteria:
</p>
<pre>
    %mynewOrder = list(ascending(length), %myorder, -
                            descending(reverse))
</pre>


You can even pass a List call within a List call:
<pre>
    %myorder = list(ascending(change),    -
      list(ascending(quantity), descending (price)))
</pre>
==See also==
==See also==
{{Template:SortOrder:List footer}}
{{Template:SortOrder:List footer}}

Revision as of 21:37, 29 June 2011

Create a composite SortOrder (SortOrder class)


This shared function is a virtual constructor, or factory method, for SortOrders. The List method invokes the creation of a new SortOrder instance, then populates that instance with items from an input list that are themselves SortOrder instances. Designed for specifying multiple sort criteria, the SortOrders in the object that List returns are applied consecutively by the sorting method that uses the SortOrder.

Syntax

%sortOrder = [%(SortOrder For itemType):]List( sortOrderItems)

Syntax terms

%sortOrder A SortOrder object variable to contain the new object instance.
%(SortOrder 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: %(SortOrder For itemtype):
sortOrderItems A comma-delimited set of SortOrder objects, which may be explicitly specified Ascending/Descending constructors,

SortOrder object variables, or another SortOrder List specification. These individual SortOrders are applied to the target collection items in the order they are specified in this argument.

If a SortOrder like ascending(price) is a single sort criterion, then the maximum number of sort criteria a List call may produce is seven.

Usage notes

  • For more information about factory methods, see Virtual Constructor methods".
  • List is a constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is Null:

    %sortOrder = List(sortOrderItems) %sortOrder = %(sortorder for float):List(sortOrderItems) %sortOrder = %sortOrder:List(sortOrderItems)

Examples

The typical way to use SortOrder lists is in a collection class sorting method invocation:

%orders:sort(%myorder)

Where, for example:

%myorder = list(ascending(quantity), descending(price))

Since the arguments to the SortOrder List method are also SortOrders, you could also pass the %myorder variable in another List call. The following List statement inserts the %myorder criteria into the middle of two other sort criteria:

%mynewOrder = list(ascending(length), %myorder, - descending(reverse))

You can even pass a List call within a List call:

%myorder = list(ascending(change), - list(ascending(quantity), descending (price)))

See also