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
22 * String [][]a={{"This","is","my","string"},{"and","I want to", "compare"," them"}};<br />
23 * ScilabString aMatrix = new ScilabString(a);
25 * @see org.scilab.modules.javasci.Scilab
27 public class ScilabString implements ScilabType {
29 private static final long serialVersionUID = 359802519980180085L;
31 private String[][] data;
36 public ScilabString() {
41 * Constructor with data.
43 * @param data the associated data.
45 public ScilabString(String[][] data) {
50 * Constructor with vector data.
52 * @param data the column vector data
54 public ScilabString(String[] data) {
55 if (data == null || data.length == 0) {
56 this.data = new String[1][1];
59 this.data = new String[1][data.length];
60 for (int i = 0; i < data.length; i++) {
61 this.data[0][i] = data[i];
67 * Constructor with a unique value
69 * @param string the value
71 public ScilabString(String string) {
73 throw new IllegalArgumentException("string == null");
75 this.data = new String[1][1];
76 this.data[0][0] = string;
82 * @param data the values
84 public void setData(String[][] data) {
89 * @return the associated values
91 public String[][] getData() {
96 * @return the height of the data matrix
97 * @see org.scilab.modules.types.ScilabType#getHeight()
99 public int getHeight() {
107 * @return the width of the data matrix
108 * @see org.scilab.modules.types.ScilabType#getWidth()
110 public int getWidth() {
114 return data[0].length;
118 * Check the emptiness of the associated data.
119 * @return true, if the associated data array is empty.
121 public boolean isEmpty() {
122 return (data == null);
126 * @see org.scilab.modules.types.ScilabType#equals(Object)
128 public boolean equals(Object obj) {
129 if (obj instanceof ScilabString) {
130 return Arrays.deepEquals(this.getData(), ((ScilabString)obj).getData());
137 * Display the representation in the Scilab language of the type<br />
138 * Note that the representation can be copied/pasted straight into Scilab
140 * @return a Scilab-like String representation of the data.
141 * @see java.lang.Object#toString()
143 public String toString() {
144 StringBuffer result = new StringBuffer();
147 return result.toString();
151 for (int i = 0; i < getHeight(); ++i) {
152 for (int j = 0; j < getWidth(); ++j) {
155 result.append(getData()[i][j]);
158 if (j != getWidth() - 1) {
162 if (i != getHeight() - 1) {
163 result.append(" ; ");
167 return result.toString();