Maximum (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
{{Template:Arraylist:Maximum subtitle}}
{{Template:Arraylist:Maximum subtitle}}
[[Category:Arraylist methods|Maximum function]]
[[Category:Arraylist methods|Maximum function]]
<!--DPL?? Category:Arraylist methods|Maximum function: Get item that has maximum value-->
<!--DPL?? Category:Arraylist methods|<var>Maximum</var> function: Get item that has maximum value-->
<p>
<p>
Maximum is a member of the [[Arraylist class]].
<var>Maximum</var> is a member of the [[Arraylist class]].
</p>
</p>


Line 9: Line 9:
numeric value after the application of a specified function to each item.
numeric value after the application of a specified function to each item.
The function that gets applied to each Arraylist item, which
The function that gets applied to each Arraylist item, which
you identify in the argument to Maximum, must be a method
you identify in the argument to <var>Maximum</var>, must be a method
that operates on the item type and returns a User Language intrinsic
that operates on the item type and returns a User Language intrinsic
datatype (Float, String, Longstring, or Unicode) value.
datatype (Float, String, Longstring, or Unicode) value.
Line 16: Line 16:
Local methods are discussed in [[??]] refid=localm..
Local methods are discussed in [[??]] refid=localm..


Maximum is available in ''Sirius Mods'' version 7.3 and later.
<var>Maximum</var> is available in ''Sirius Mods'' version 7.3 and later.
==Syntax==
==Syntax==
{{Template:Arraylist:Maximum syntax}}
{{Template:Arraylist:Maximum syntax}}
Line 27: Line 27:
<tr><th><i>function</i></th>
<tr><th><i>function</i></th>
<td>A method value (a method name literal, a method variable, or even a method that returns a method value) for a method that operates on items of the type specified on the ''%arrayl'' declaration and that returns a numeric or string value.
<td>A method value (a method name literal, a method variable, or even a method that returns a method value) for a method that operates on items of the type specified on the ''%arrayl'' declaration and that returns a numeric or string value.
  As of ''Sirius Mods'' version 7.6, the special identity function, <tt>This</tt>, is the default ''function'' value for the Maximum and Minimum methods. See "[[Collections#Using the This function as the Maximum parameter|Using the This function as the Maximum parameter]]".</td></tr>
  As of ''Sirius Mods'' version 7.6, the special identity function, <tt>This</tt>, is the default ''function'' value for the <var>Maximum</var> and Minimum methods. See "[[Collections#Using the This function as the Maximum parameter|Using the This function as the Maximum parameter]]".</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the function applied by Maximum returns string values, Maximum
<li>If the function applied by <var>Maximum</var> returns string values, <var>Maximum</var>
uses the decimal-equivalent value of the character bytes and determines
uses the decimal-equivalent value of the character bytes and determines
the number of the item that has the greatest value.
the number of the item that has the greatest value.
Line 41: Line 41:
and all letters rank lower than any number.
and all letters rank lower than any number.
<li>If two or more Arraylist items have equal, maximum, values,
<li>If two or more Arraylist items have equal, maximum, values,
Maximum returns the position of the item that appears closest to the beginning
<var>Maximum</var> returns the position of the item that appears closest to the beginning
of the Arraylist.
of the Arraylist.
<li>The parameter for Maximum is a method value, not a User Language expression.
<li>The parameter for <var>Maximum</var> is a method value, not a User Language expression.
That is, you cannot provide a function that itself has an argument
That is, you cannot provide a function that itself has an argument
(say, <tt>ToIntegerPower(2)</tt>) as the Maximum parameter.
(say, <tt>ToIntegerPower(2)</tt>) as the <var>Maximum</var> parameter.
The example of "[[Maximum (Arraylist function)#Maximum/Minimum with local method|Maximum/Minimum with local method]]" shows a way to apply ToIntegerPower
The example of "[[Maximum (Arraylist function)#Maximum/Minimum with local method|Maximum/Minimum with local method]]" shows a way to apply ToIntegerPower
with Maximum.
with <var>Maximum</var>.
<li>The [[Minimum (Arraylist function)|Minimum]] function is the opposite of the Maximum function.
<li>The [[Minimum (Arraylist function)|Minimum]] function is the opposite of the <var>Maximum</var> function.
</ul>
</ul>
==Examples==
==Examples==
===Maximum and Minimum using Count function===
===<var>Maximum</var> and Minimum using Count function===
In the following example, the Maximum and Minimum methods first
In the following example, the <var>Maximum</var> and Minimum methods first
apply the Stringlist [[Count (Stringlist function)|Count]] function, then
apply the Stringlist [[Count (Stringlist function)|Count]] function, then
return the position of the Arraylist item
return the position of the Arraylist item
Line 80: Line 80:
     %arrayl:minimum(count) is 1
     %arrayl:minimum(count) is 1
</pre>
</pre>
===Maximum/Minimum with local method===
===<var>Maximum</var>/Minimum with local method===
The local method used with Maximum in the following request
The local method used with <var>Maximum</var> in the following request
applies the
applies the
ToIntegerPower method, which (because it requires its own argument)
ToIntegerPower method, which (because it requires its own argument)
the syntax of Maximum does not allow as a parameter.
the syntax of <var>Maximum</var> does not allow as a parameter.
<pre style="xmp">
<pre style="xmp">
     b
     b
Line 107: Line 107:


Although applying the local method above to item 2 and item 4 produces the same
Although applying the local method above to item 2 and item 4 produces the same
value, Maximum returns the item that is closer to the beginning of the arraylist.
value, <var>Maximum</var> returns the item that is closer to the beginning of the arraylist.
</ol>
</ol>

Revision as of 23:58, 19 January 2011

Get number of maximum item (Arraylist class)

Maximum is a member of the Arraylist class.

This function returns the number of the Arraylist item that has the maximum numeric value after the application of a specified function to each item. The function that gets applied to each Arraylist item, which you identify in the argument to Maximum, must be a method that operates on the item type and returns a User Language intrinsic datatype (Float, String, Longstring, or Unicode) value.

The system intrinsic classes are discussed in "Intrinsic classes". Local methods are discussed in ?? refid=localm..

Maximum is available in Sirius Mods version 7.3 and later.

Syntax

%number = al:Maximum[( [itemFunction])]

Syntax terms

%num A numeric variable to contain the item number of the item in the indicated Arraylist that has the maximum value after the argument function is applied.
%arrayl An Arraylist object.
function A method value (a method name literal, a method variable, or even a method that returns a method value) for a method that operates on items of the type specified on the %arrayl declaration and that returns a numeric or string value. As of Sirius Mods version 7.6, the special identity function, This, is the default function value for the Maximum and Minimum methods. See "Using the This function as the Maximum parameter".

Usage notes

  • If the function applied by Maximum returns string values, Maximum uses the decimal-equivalent value of the character bytes and determines the number of the item that has the greatest value. Therefore, lowercase letters are ranked alphabetically and the maximum lowercase letter is "z"; the uppercase letters are ranked alphabetically and the maximum uppercase letter is "Z"; "z" ranks lower than all the uppercase letters; and all letters rank lower than any number.
  • If two or more Arraylist items have equal, maximum, values, Maximum returns the position of the item that appears closest to the beginning of the Arraylist.
  • The parameter for Maximum is a method value, not a User Language expression. That is, you cannot provide a function that itself has an argument (say, ToIntegerPower(2)) as the Maximum parameter. The example of "Maximum/Minimum with local method" shows a way to apply ToIntegerPower with Maximum.
  • The Minimum function is the opposite of the Maximum function.

Examples

Maximum and Minimum using Count function

In the following example, the Maximum and Minimum methods first apply the Stringlist Count function, then return the position of the Arraylist item Stringlist that has the most items and the one that has the fewest. The Stringlist List function simplifies the construction of the lists.

    b
    %list1 is object stringlist
    %list2 is object stringlist
    %list3 is object stringlist

    %list1 = List('the', 'quick', 'brown')
    %list2 = List('fox', 'jumped', 'over', 'the')
    %list3 = List('lazy', 'dog', 'yesterday', 'two', 'times')

    %arrayl is collection arraylist of object stringlist
    %arrayl = List(%list1, %list2, %list3)

    PrintText {~} is {%arrayl:maximum(count)}
    PrintText {~} is {%arrayl:minimum(count)}
    end

The result is:

    %arrayl:maximum(count) is 3
    %arrayl:minimum(count) is 1

Maximum/Minimum with local method

The local method used with Maximum in the following request applies the ToIntegerPower method, which (because it requires its own argument) the syntax of Maximum does not allow as a parameter.

    b
    %alist is collection arraylist of float
    %alist = List(10, -11, 0, 11)

    local function (float):Squared is float
       return %this:toIntegerPower(2)
    end function

    PrintText {~} is {%alist:maximum(Squared)}
    PrintText {~} is {%alist:minimum(Squared)}

    end

The result is:

    %arrayl:maximum(Squared) is 2
    %arrayl:minimum(Squared) is 3

Although applying the local method above to item 2 and item 4 produces the same value, Maximum returns the item that is closer to the beginning of the arraylist.