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 TList datatype<br>
21 * This class is {@link java.io.Serializable} and any modification could
22 * impact load and store of data (Xcos files, Javasci saved data, etc...).<br>
26 * ScilabTList data = new ScilabTList();<br />
27 * data.add(new ScilabString("hello"));<br />
28 * data.add(new ScilabDouble(2));<br />
30 * @see org.scilab.modules.javasci.Scilab
32 public class ScilabTList extends ArrayList<ScilabType> implements ScilabType {
34 private static final long serialVersionUID = 8080160982092586620L;
35 private static final ScilabTypeEnum type = ScilabTypeEnum.sci_tlist;
38 * Construct an empty tlist.
40 * Note that the first element of this collection is the header used by
41 * Scilab to find each field type.
43 public ScilabTList() {
48 * Construct a tlist with a specified header.
50 * @param types type names of the fields.
52 public ScilabTList(String []types) {
54 String [][] typesData = new String[1][types.length];
56 add(new ScilabString(typesData));
60 * Construct a tlist containing the elements of the specified collection, in
61 * the order that they are returned by the specified collection's iterator.
64 * type names of the fields.
66 * the collection whose elements are to be placed into this
69 public ScilabTList(String[] types, Collection< ? extends ScilabType> c) {
72 String[][] typesData = new String[1][types.length];
74 add(new ScilabString(typesData));
80 * Return the type of Scilab
81 * @return the type of Scilab
85 public ScilabTypeEnum getType() {
90 * @return 1 when there is data on the list, 0 otherwise.
91 * @see org.scilab.modules.types.ScilabType#getHeight()
94 public int getHeight() {
102 * @return 1 when there is data on the list, 0 otherwise.
103 * @see org.scilab.modules.types.ScilabType#getWidth()
106 public int getWidth() {
114 * Display the representation in the Scilab language of the type<br />
115 * Note that the representation can be copied/pasted straight into Scilab
117 * @return the pretty-printed data
118 * @see java.util.AbstractCollection#toString()
121 public String toString() {
123 StringBuffer result = new StringBuffer();
125 result.append("tlist()");
126 return result.toString();
129 result.append("tlist(");
130 for (int i = 0; i < size(); i++) {
131 result.append(get(i));
132 if (i != size() - 1) {
139 return result.toString();