List (SortOrder function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(26 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>Create SortOrder object from input list of SortOrder objects</b></span>
{{Template:SortOrder:List subtitle}}
[[Category:SortOrder methods|List constructor]]
 
[[Category:System methods]]
This shared function is a [[Object variables#Virtual Constructor methods|virtual constructor]], or factory method, for <var>SortOrder</var> objects.
<!--DPL?? Category:SortOrder methods|List constructor: Create SortOrder object from input list of SortOrder objects-->
The <var>List</var>
<!--DPL?? Category:System methods|List (SortOrder constructor): Create SortOrder object from input list of SortOrder objects-->
method invokes the creation of a new <var>SortOrder</var> instance, then populates that
instance with items from an input list that are themselves <var>SortOrder</var> instances.
Designed for specifying multiple sort criteria, the <var>SortOrder</var> objects in the object that
<var>List</var> returns are applied consecutively by the sorting method
that uses the <var>SortOrder</var>.
 
==Syntax==
{{Template:SortOrder:List syntax}}
===Syntax terms===
<table class="syntaxTable">
<tr><th>%sortOrder</th>
<td>A <var>SortOrder</var> object variable to contain the new object instance. </td></tr>
<tr><th nowrap="true"><var>[%(SortOrder For </var>itemType<var>)]</var>
<td>This optional specification of the class in parentheses [[Notation conventions for methods#Shared methods|denotes a virtual constructor]]. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a <var>SortOrder</var> virtual constructor. </td></tr>
<tr><th>sortOrderItems</th>
<td>A comma-delimited set of <var>SortOrder</var> objects, which may be explicitly specified [[Ascending and Descending (SortOrder functions)|Ascending/Descending]] functions, <var>SortOrder</var> object variables, or another <var>SortOrder</var> <var>List</var> specification. These individual <var>SortOrder</var> objects are applied to the target collection items in the order they are specified in this argument.
<p>
<p>
List is a member of the [[SortOrder class]].
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. </p></td></tr>
</p>
</table>


This shared function is a virtual constructor, or factory method, for SortOrders.
==Usage notes==
The List
<ul>
method invokes the creation of a new SortOrder instance, then populates that
<li><var>List</var> is a virtual constructor and as such can be invoked with no method
instance with items from an input list that are themselves SortOrder instances.
object, with an explicit class specification, or with an object variable of the class,
Designed for specifying multiple sort criteria, the SortOrders in the object that
even if that object is <var>Null</var>:
List returns are applied consecutively by the sorting method
<p class="code">%sord = List(<i>sortOrderItems</i>)
that uses the SortOrder.
===Syntax===
  %sord = [%(sortorder for itemtype):] List(sordlist)
===Syntax terms===
<dl>
<dt><i>%sord</i>
<dd>A SortOrder object variable to contain the new object instance.
<dt><i>%(sortorder for itemtype)</i>
<dd>This optional specification of the class and collection item type
in parentheses indicates
that the method is shared and does not operate on a specific instance.
<dt><i>sordlist</i>
<dd>A comma-delimited set of SortOrder objects, which may be explicitly specified
[[Ascending and Descending (SortOrder constructors)|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
%sord = %(Sortorder for <i>itemType</i>):List(<i>sortOrderItems</i>)
maximum number of sort criteria a List call may produce is seven.


</dl>
%sord = %sord:List(<i>sortOrderItems</i>)
===Usage Notes===
</p>
<ul>
<p class="note">'''Note:'''
<li>For more information about factory methods, see [[??]] refid=vconst..
As shown in the second of these above, if you explicitly specify the
<li>List is a constructor and as such can be called with no method
class name, you must include the item datatype of the collection to be sorted, just as on a <var>SortOrder</var> object variable's [[SortOrder class#Declaring a SortOrder object variable|declaration]]. </p></li>
object, with an explicit class name, or with an object variable,
even if that object is null:
<pre>
    %sord = List(&'italic(sordlist))
    %sord = %(sortorder for float):List(&'italic(sordlist))
    %sord = %sord:List(&'italic(sordlist))
</pre>
</ul>
</ul>
===Examples===


The typical way to use SortOrder lists is in a Sort or SortNew
==Examples==
method invocation:
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:
<pre>
<p class="code">%orders:sort(%myorder)
    %orders:sort(%myorder)
</p>
</pre>


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


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

Latest revision as of 16:04, 6 April 2015

Create a composite SortOrder (SortOrder class)


This shared function is a virtual constructor, or factory method, for SortOrder objects. 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 SortOrder objects 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 denotes a virtual constructor. See "Usage notes", below, for more information about invoking a SortOrder virtual constructor.
sortOrderItems A comma-delimited set of SortOrder objects, which may be explicitly specified Ascending/Descending functions, SortOrder object variables, or another SortOrder List specification. These individual SortOrder objects 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

  • List is a virtual constructor and as such 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:

    %sord = List(sortOrderItems) %sord = %(Sortorder for itemType):List(sortOrderItems) %sord = %sord:List(sortOrderItems)

    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 sorted, just as on a SortOrder object variable's declaration.

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 SortOrder objects, 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