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;
36 * Create an empty object
38 public ScilabBoolean() {
43 * Create an object from an array of array of boolean
45 * @param data the array of boolean
47 public ScilabBoolean(boolean[][] data) {
52 * Create a scalar boolean from a boolean
54 * @param value the boolean
56 public ScilabBoolean(boolean value) {
57 this.data = new boolean[1][1];
58 this.data[0][0] = value;
62 * Change the value with the provided data
64 * @param data array of boolean
66 public void setData(boolean[][] data) {
73 * @return the array of array of boolean
75 public boolean[][] getData() {
80 * Return the height (number of element) of the stored data
84 public int getHeight() {
92 * Return the width (number of element) of the stored data
96 public int getWidth() {
100 return data[0].length;
104 * If it is empty / uninitialized
106 * @return true if empty
108 public boolean isEmpty() {
109 return (data == null);
114 * @see org.scilab.modules.types.ScilabType#equals(Object)
116 public boolean equals(Object obj) {
117 if (obj instanceof ScilabBoolean) {
118 return Arrays.deepEquals(this.getData(), ((ScilabBoolean)obj).getData());
125 * Display the representation in the Scilab language of the type<br />
126 * Note that the representation can be copied/pasted straight into Scilab
128 * @return the pretty print
130 public String toString() {
131 StringBuilder result = new StringBuilder();
135 return result.toString();
139 for (int i = 0; i < getHeight(); ++i) {
140 for (int j = 0; j < getWidth(); ++j) {
141 if (getData()[i][j]) {
146 if (j != getWidth() - 1) {
150 if (i != getHeight() - 1) {
151 result.append(" ; ");
155 return result.toString();