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;
33 private ScilabTypeEnum type = ScilabTypeEnum.sci_strings;
37 public ScilabString() {
42 * Constructor with data.
44 * @param data the associated data.
46 public ScilabString(String[][] data) {
51 * Constructor with vector data.
53 * @param data the column vector data
55 public ScilabString(String[] data) {
56 if (data == null || data.length == 0) {
57 this.data = new String[1][1];
60 this.data = new String[1][data.length];
61 for (int i = 0; i < data.length; i++) {
62 this.data[0][i] = data[i];
68 * Constructor with a unique value
70 * @param string the value
72 public ScilabString(String string) {
74 throw new IllegalArgumentException("string == null");
76 this.data = new String[1][1];
77 this.data[0][0] = string;
83 * @param data the values
85 public void setData(String[][] data) {
90 * Return the type of Scilab
91 * @return the type of Scilab
94 public ScilabTypeEnum getType() {
99 * @return the associated values
101 public String[][] getData() {
106 * @return the height of the data matrix
107 * @see org.scilab.modules.types.ScilabType#getHeight()
109 public int getHeight() {
117 * @return the width of the data matrix
118 * @see org.scilab.modules.types.ScilabType#getWidth()
120 public int getWidth() {
124 return data[0].length;
128 * Check the emptiness of the associated data.
129 * @return true, if the associated data array is empty.
131 public boolean isEmpty() {
132 return (data == null);
136 * @see org.scilab.modules.types.ScilabType#equals(Object)
138 public boolean equals(Object obj) {
139 if (obj instanceof ScilabString) {
140 return Arrays.deepEquals(this.getData(), ((ScilabString)obj).getData());
147 * Display the representation in the Scilab language of the type<br />
148 * Note that the representation can be copied/pasted straight into Scilab
150 * @return a Scilab-like String representation of the data.
151 * @see java.lang.Object#toString()
153 public String toString() {
154 StringBuffer result = new StringBuffer();
157 return result.toString();
161 for (int i = 0; i < getHeight(); ++i) {
162 for (int j = 0; j < getWidth(); ++j) {
165 result.append(getData()[i][j]);
168 if (j != getWidth() - 1) {
172 if (i != getHeight() - 1) {
173 result.append(" ; ");
177 return result.toString();