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.Arrays;
18 * This class provides a representation on the Scilab String datatype<br>
20 * This class is {@link java.io.Serializable} and any modification could
21 * impact load and store of data (Xcos files, Javasci saved data, etc...).<br>
25 * String [][]a={{"This","is","my","string"},{"and","I want to", "compare"," them"}};<br />
26 * ScilabString aMatrix = new ScilabString(a);
28 * @see org.scilab.modules.javasci.Scilab
30 public class ScilabString implements ScilabType {
32 private static final long serialVersionUID = 359802519980180085L;
33 private static final ScilabTypeEnum type = ScilabTypeEnum.sci_strings;
35 private String[][] data;
40 public ScilabString() {
45 * Constructor with data.
47 * @param data the associated data.
49 public ScilabString(String[][] data) {
54 * Constructor with vector data.
56 * @param data the column vector data
58 public ScilabString(String[] data) {
59 if (data == null || data.length == 0) {
60 this.data = new String[1][1];
63 this.data = new String[1][data.length];
64 for (int i = 0; i < data.length; i++) {
65 this.data[0][i] = data[i];
71 * Constructor with a unique value
73 * @param string the value
75 public ScilabString(String string) {
77 throw new IllegalArgumentException("string == null");
79 this.data = new String[1][1];
80 this.data[0][0] = string;
86 * @param data the values
88 public void setData(String[][] data) {
93 * Return the type of Scilab
94 * @return the type of Scilab
98 public ScilabTypeEnum getType() {
103 * @return the associated values
105 public String[][] getData() {
110 * @return the height of the data matrix
111 * @see org.scilab.modules.types.ScilabType#getHeight()
114 public int getHeight() {
122 * @return the width of the data matrix
123 * @see org.scilab.modules.types.ScilabType#getWidth()
126 public int getWidth() {
130 return data[0].length;
134 * Check the emptiness of the associated data.
135 * @return true, if the associated data array is empty.
138 public boolean isEmpty() {
139 return (data == null);
143 * @see org.scilab.modules.types.ScilabType#equals(Object)
146 public boolean equals(Object obj) {
147 if (obj instanceof ScilabString) {
148 return Arrays.deepEquals(this.getData(), ((ScilabString)obj).getData());
155 * Display the representation in the Scilab language of the type<br />
156 * Note that the representation can be copied/pasted straight into Scilab
158 * @return a Scilab-like String representation of the data.
159 * @see java.lang.Object#toString()
162 public String toString() {
163 StringBuffer result = new StringBuffer();
166 return result.toString();
170 for (int i = 0; i < getHeight(); ++i) {
171 for (int j = 0; j < getWidth(); ++j) {
174 result.append(getData()[i][j]);
177 if (j != getWidth() - 1) {
181 if (i != getHeight() - 1) {
182 result.append(" ; ");
186 return result.toString();