List (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (match syntax diagram to template and fix tags)
Line 1: Line 1:
{{Template:Arraylist:List subtitle}}
{{Template:Arraylist:List subtitle}}


This shared function is a virtual constructor,
This shared function is a virtual constructor, or factory method, for <var>Arraylistd</var>. The <var>List</var> method invokes the creation of a new <var>Arraylist</var> instance, then populates that instance with items that are, respectively, the values of the method arguments.
or factory method, for <var>Arraylist</var>s.
The <var>List</var> method invokes the creation of a new <var>Arraylist</var>
instance, then populates that instance with items that are, respectively,
the values of the method arguments.


<var>List</var> is available in ''Sirius Mods'' version 7.3 and later.
==Syntax==
==Syntax==
{{Template:Arraylist:List syntax}}
{{Template:Arraylist:List syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th><i><var class="term">al</var></i></th>
<tr><th><i>%newlist</i></th>
<td>A declared or existing <var>Arraylist</var> object. </td></tr>
<td>A declared or existing <var>Arraylist</var> object. </td></tr>
<tr><th><i>itemlist</i></th>
<tr><th><i>list</i></th>
<td>A comma-delimited set of values or variables of the same type as specified on the ''<var class="term">al</var>'' declaration. Each of these, from left to right, becomes an item in the resultant new <var>Arraylist</var>, ''<var class="term">al</var>''.</td></tr>
<td>A comma-delimited set of values or variables of the same type as specified on the <var class="term">al</var> declaration. Each of these, from left to right, becomes an item in the resultant new <var>Arraylist</var>, <var class="term">al</var>.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul><li>For more information about factory methods, see <var>[[Object variables#Virtual Constructor methods|Virtual Constructor methods]]</var>.
<li>For more information about factory methods, see [[??]] refid=vconst..
<li>The maximum number of <var class="term">itemlist</var> values is 62.
<li>The maximum number of ''itemlist'' values is 62.
<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, even if that object is null:
<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,
even if that object is null:
<p class="code"><var class="term">al</var> = <var>List</var>(&'italic(itemlist))
<p class="code"><var class="term">al</var> = <var>List</var>(&'italic(itemlist))
<var class="term">al</var> = %(<var>Arraylist</var>):<var>List</var>(&'italic(itemlist))
<var class="term">al</var> = %(<var>Arraylist</var>):<var>List</var>(&'italic(itemlist))
Line 29: Line 22:
</p>
</p>
:note
:note
If using the second of these syntax options, which explicitly indicates the
If using the second of these syntax options, which explicitly indicates the class, both the collection and item datatypes must be specified exactly as they are on the collection variable's declaration:
class, both the collection and item datatypes must be
specified exactly as they are on the collection variable's declaration:
<p class="code"><var class="term">al</var>  is collection <var>Arraylist</var> of longstring
<p class="code"><var class="term">al</var>  is collection <var>Arraylist</var> of longstring
<var class="term">al</var>  = %(<var>Arraylist</var> of longstring):<var>List</var>(&'italic(itemlist))
<var class="term">al</var>  = %(<var>Arraylist</var> of longstring):<var>List</var>(&'italic(itemlist))
</p>
</p>
<li>You can also use the <var>List</var> method in contexts where an <var>Arraylist</var> object
<li>You can also use the <var>List</var> method in contexts where an <var>Arraylist</var> object is a method parameter.
is a method parameter.
<li><var>List</var> is available in <var class="product">Sirius Mods</var> version 7.3 and later.
</ul>
</ul>
==Examples==
==Examples==
<ul>
<ol><li>The following <var>List</var> method call creates a new <var>Arraylist</var> instance of 11 integer items that begins with 1 and whose subsequent items are, respectively, the sum of the preceding two integers:
<li>The following <var>List</var> method call creates a new <var>Arraylist</var> instance
of 11 integer items that begins with 1 and whose subsequent items are,
respectively, the sum of the preceding two integers:
<p class="code">%fib    is collection arraylist of float
<p class="code">%fib    is collection arraylist of float
%fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89)
%fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89)
</p>
</p>
<li>The following <var>List</var> call creates a new <var>Arraylist</var> instance whose
<li>The following <var>List</var> call creates a new <var>Arraylist</var> instance whose items are objects of user class Freight:
items are objects of user class Freight:
<p class="code">class freight
<p class="code">class freight
   public
   public
Line 61: Line 49:
             newf(-7, 1234))
             newf(-7, 1234))
</p>
</p>
</ul>
</ol>
 
==See also==
==See also==
{{Template:Arraylist:List footer}}
{{Template:Arraylist:List footer}}

Revision as of 05:13, 30 January 2011

Construct and populate a new Arraylist (Arraylist class)


This shared function is a virtual constructor, or factory method, for Arraylistd. The List method invokes the creation of a new Arraylist instance, then populates that instance with items that are, respectively, the values of the method arguments.

Syntax

%newList = [%(Arraylist Of itemType):]List( itemList)

Syntax terms

%newlist A declared or existing Arraylist object.
list A comma-delimited set of values or variables of the same type as specified on the al declaration. Each of these, from left to right, becomes an item in the resultant new Arraylist, al.

Usage notes

  • For more information about factory methods, see Virtual Constructor methods.
  • The maximum number of itemlist values is 62.
  • 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:

    al = List(&'italic(itemlist)) al = %(Arraylist):List(&'italic(itemlist)) al = al:List(&'italic(itemlist))

    note

    If using the second of these syntax options, which explicitly indicates the class, both the collection and item datatypes must be specified exactly as they are on the collection variable's declaration:

    al is collection Arraylist of longstring al = %(Arraylist of longstring):List(&'italic(itemlist))

  • You can also use the List method in contexts where an Arraylist object is a method parameter.
  • List is available in Sirius Mods version 7.3 and later.

Examples

  1. The following List method call creates a new Arraylist instance of 11 integer items that begins with 1 and whose subsequent items are, respectively, the sum of the preceding two integers:

    %fib is collection arraylist of float %fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89)

  2. The following List call creates a new Arraylist instance whose items are objects of user class Freight:

    class freight public variable a is float variable b is float constructor newf(%a is float, %b is float) end public ... end class ... %ark is arraylist of object freight %ark = list(newf(11, 14), newf(4, 6), newf(9, 77), - newf(-7, 1234))

See also