List - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : Java Application Programming Interface : List Class : OpenMaple/Java/List

List

OpenMaple representation of a list

 

Description

Method Summary

Examples

Description

• 

The com.maplesoft.openmaple.List class represents a Maple list.

• 

To create a List containing arbitrary data, call newList to create an empty List of the specified length.  The elements of the expression sequences are then assigned by calling assign.

• 

The List class implements the java.util.List interface on type Algebraic.

Method Summary

• 

The following methods are defined on List objects.

• 

Note that List publicly inherits from Indexable; therefore, it provides all the member functions from the Indexable and Algebraic classes in addition to those listed here.

void assign( int i, Algebraic val ) throws MapleException

• 

assign sets element i of the list to val.

int indexByRange( int a, int b ) throws MapleException

• 

indexByRange returns the sublist from position a to b inclusive.

int length( ) throws MapleException

• 

length returns the length of the list. This is a synonym for numElements.

Algebraic searchFirst( Algebraic expr ) throws MapleException

• 

searchFirst returns the one-based leftmost index of expr in the list.

Algebraic searchFirst( Algebraic expr ) throws MapleException

• 

searchLast returns the one-based rightmost index of expr in the list.

Algebraic select( int i ) throws MapleException

• 

select returns the element at index i of the list.

• 

The List class also includes the following methods which implement the java.util.List interface:

boolean contains( Object value )

• 

contains returns true if value is an Algebraic and the List contains a value identical to value.

  

This is similar to member except that it accepts an arbitrary Object and does not throw a MapleException.

boolean containsAll( Collection<?> o )

• 

containsAll returns true if every member of the collection o is an Algebraic which is equal to some element of the List.

Algebraic get( int index )

• 

get returns the element at zero-based position index in the List.

int indexOf( Object o )

• 

indexOf returns the zero-based leftmost index of object o in the List, or -1 if o is not an element.

java.util.Iterator<Algebraic> iterator( )

• 

iterator returns an Iterator object which can be used to iterate over the elements of the List.

int lastIndexOf( Object o )

• 

lastIndexOf returns the zero-based rightmost index of object o in the List, or -1 if o is not an element.

java.util.ListIterator<Algebraic> listIterator( )

• 

listIterator returns an ListIterator object which can be used to iterate either forwards or backwards over the elements of the List.

java.util.ListIterator<Algebraic> listIterator( int index )

• 

listIterator with an integer argument returns an ListIterator object which can be used to iterate either forwards or backwards over the elements of the List, starting at zero-based position index.

java.util.List subList( int fromIndex, int toIndex )

• 

subList returns a java.util.List view of the List between the specified fromIndex, inclusive, and toIndex, exclusive. Note these indices are zero-based.

Object[] toArray( )

• 

toArray returns an array of objects corresponding to the elements of the List.

public <T> T[] toArray( T[] a )

• 

toArray with an array argument returns an Array populated with the elements of the List. The runtime type of this array matches that of the input array a.

Examples

import com.maplesoft.openmaple.*;

import com.maplesoft.externalcall.MapleException;

class Example

{

    public static void main( String notused[] ) throws MapleException

    {

        String[] mapleArgs = { "java" };

        Engine engine = new Engine( mapleArgs, new EngineCallBacksDefault(), null, null );

        List l = (List)engine.evaluate( "[1,3,7]:" );

        System.out.println("Length of list: " + l.numElements());

        for (Algebraic elem : l) {

            System.out.println("Element: " + elem);

        }

    }

}

Executing this code produces the following output.

Length of list: 3

Element: 1

Element: 3

Element: 7

See Also

list

OpenMaple

OpenMaple/Java/Algebraic

OpenMaple/Java/API

OpenMaple/Java/Examples

OpenMaple/Java/Expseq

OpenMaple/Java/Indexable

OpenMaple/Java/List

OpenMaple/Java/Table