2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009-2009 - DIGITEO - Bruno JOFRET
4 * Copyright (C) 2010-2010 - DIGITEO - Clément DAVID
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 package org.scilab.modules.types;
16 import java.util.Arrays;
19 * This class provides a representation on the Scilab boolean datatype<br />
23 * boolean [][]a={{true,false,true}, {true,true,true}};<br />
24 * ScilabBoolean aMatrix = new ScilabBoolean(a);
26 * @see org.scilab.modules.javasci.Scilab
28 public class ScilabBoolean implements ScilabType {
30 private static final long serialVersionUID = 6511497080095473901L;
32 /* the boolean data */
33 private boolean[][] data;
35 private ScilabTypeEnum type = ScilabTypeEnum.sci_boolean;
38 * Create an empty object
40 public ScilabBoolean() {
45 * Create an object from an array of array of boolean
47 * @param data the array of boolean
49 public ScilabBoolean(boolean[][] data) {
54 * Create a scalar boolean from a boolean
56 * @param value the boolean
58 public ScilabBoolean(boolean value) {
59 this.data = new boolean[1][1];
60 this.data[0][0] = value;
64 * Change the value with the provided data
66 * @param data array of boolean
68 public void setData(boolean[][] data) {
75 * @return the array of array of boolean
77 public boolean[][] getData() {
82 * Return the type of Scilab
83 * @return the type of Scilab
86 public ScilabTypeEnum getType() {
91 * Return the height (number of element) of the stored data
95 public int getHeight() {
103 * Return the width (number of element) of the stored data
107 public int getWidth() {
111 return data[0].length;
115 * If it is empty / uninitialized
117 * @return true if empty
119 public boolean isEmpty() {
120 return (data == null);
125 * @see org.scilab.modules.types.ScilabType#equals(Object)
127 public boolean equals(Object obj) {
128 if (obj instanceof ScilabBoolean) {
129 return Arrays.deepEquals(this.getData(), ((ScilabBoolean)obj).getData());
136 * Display the representation in the Scilab language of the type<br />
137 * Note that the representation can be copied/pasted straight into Scilab
139 * @return the pretty print
141 public String toString() {
142 StringBuilder result = new StringBuilder();
146 return result.toString();
150 for (int i = 0; i < getHeight(); ++i) {
151 for (int j = 0; j < getWidth(); ++j) {
152 if (getData()[i][j]) {
157 if (j != getWidth() - 1) {
161 if (i != getHeight() - 1) {
162 result.append(" ; ");
166 return result.toString();