2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 package org.scilab.modules.types;
15 import java.util.ArrayList;
16 import java.util.Collection;
19 * This class provides a representation on the Scilab MList datatype
23 * ScilabMList data = new ScilabMList();<br />
24 * data.add(new ScilabString("hello"));<br />
25 * data.add(new ScilabDouble(2));<br />
27 * @see org.scilab.modules.javasci.Scilab
29 public class ScilabMList extends ArrayList<ScilabType> implements ScilabType {
31 private static final long serialVersionUID = 3224510024213901841L;
32 private ScilabTypeEnum type = ScilabTypeEnum.sci_mlist;
35 * Construct an empty mlist.
37 * Note that the first element of this collection is the header used by
38 * Scilab to find each field name.
40 public ScilabMList() {
45 * Construct an mlist with a specified header.
47 * @param types field names used by the accessors.
49 public ScilabMList(String []types) {
51 String [][] typesData = new String[1][types.length];
53 add(new ScilabString(typesData));
57 * Construct a tlist containing the elements of the specified collection, in
58 * the order that they are returned by the specified collection's iterator.
61 * field names, used by the accessors.
63 * the collection whose elements are to be placed into this
66 public ScilabMList(String[] names, Collection< ? extends ScilabType> c) {
69 String[][] namesData = new String[1][names.length];
71 add(new ScilabString(namesData));
77 * @return 1 when there is data on the list, 0 otherwise.
78 * @see org.scilab.modules.types.ScilabType#getHeight()
81 public int getHeight() {
89 * Return the type of Scilab
90 * @return the type of Scilab
93 public ScilabTypeEnum getType() {
98 * @return 1 when there is data on the list, 0 otherwise.
99 * @see org.scilab.modules.types.ScilabType#getWidth()
102 public int getWidth() {
110 * Display the representation in the Scilab language of the type<br />
111 * Note that the representation can be copied/pasted straight into Scilab
113 * @return the pretty-printed data
114 * @see java.util.AbstractCollection#toString()
117 public String toString() {
119 StringBuffer result = new StringBuffer();
121 result.append("mlist()");
122 return result.toString();
125 result.append("mlist(");
126 for (int i = 0; i < size(); i++) {
127 result.append(get(i));
128 if (i != size() - 1) {
135 return result.toString();