List (Arraylist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
<span style="font-size:120%; color:black"><b><section begin=dpl_desc/>Construct and populate a new Arraylist<section end=dpl_desc/></b></span>
{{Template:Arraylist:List subtitle}}
[[Category:Arraylist methods|List function]]
[[Category:Arraylist methods|List function]]
<!--DPL?? Category:Arraylist methods|List function: Construct and populate a new Arraylist-->
<!--DPL?? Category:Arraylist methods|List function: Construct and populate a new Arraylist-->
Line 13: Line 13:


List is available in ''Sirius Mods'' version 7.3 and later.
List is available in ''Sirius Mods'' version 7.3 and later.
===Syntax===
==Syntax==
  %arrayl = %(Arraylist):List(itemlist)
{{Template:Arraylist:List syntax}}
====Syntax Terms====
===Syntax terms===
<dl>
<dl>
<dt><i>%arrayl</i>
<dt><i>%arrayl</i>
Line 27: Line 27:


</dl>
</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 [[??]] refid=vconst..
Line 50: Line 50:
is a method parameter.
is a method parameter.
</ul>
</ul>
===Examples===
==Examples==
<ul>
<ul>
<li>The following List method call creates a new Arraylist instance
<li>The following List method call creates a new Arraylist instance

Revision as of 23:27, 19 January 2011

Construct and populate a new Arraylist (Arraylist class)

List is a member of the Arraylist class.

This shared function is a virtual constructor, or factory method, for Arraylists. 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.

List is available in Sirius Mods version 7.3 and later.

Syntax

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

Syntax terms

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

Usage notes

  • For more information about factory methods, see ?? refid=vconst..
  • 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:
        %arrayl = List(&'italic(itemlist))
        %arrayl = %(Arraylist):List(&'italic(itemlist))
        %arrayl = %arrayl: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:

        %arrayl  is collection Arraylist of longstring
        %arrayl  = %(Arraylist of longstring):List(&'italic(itemlist))
    
  • You can also use the List method in contexts where an Arraylist object is a method parameter.

Examples

  • 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)
    
  • 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))