KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > read > biff > BooleanRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.read.biff;
21
22 import common.Assert;
23
24 import jxl.BooleanCell;
25 import jxl.CellType;
26 import jxl.biff.FormattingRecords;
27
28 /**
29  * A boolean cell last calculated value
30  */

31 class BooleanRecord extends CellValue implements BooleanCell
32 {
33   /**
34    * Indicates whether this cell contains an error or a boolean
35    */

36   private boolean error;
37
38   /**
39    * The boolean value of this cell. If this cell represents an error,
40    * this will be false
41    */

42   private boolean value;
43
44   /**
45    * Constructs this object from the raw data
46    *
47    * @param t the raw data
48    * @param fr the formatting records
49    * @param si the sheet
50    */

51   public BooleanRecord(Record t, FormattingRecords fr, SheetImpl si)
52   {
53     super(t, fr, si);
54     error = false;
55     value = false;
56
57     byte[] data = getRecord().getData();
58
59     error = (data[7] == 1);
60
61     if (!error)
62     {
63       value = data[6] == 1 ? true : false;
64     }
65   }
66
67   /**
68    * Interface method which queries whether this cell contains an error.
69    * Returns TRUE if it does, otherwise returns FALSE.
70    *
71    * @return TRUE if this cell is an error, FALSE otherwise
72    */

73   public boolean isError()
74   {
75     return error;
76   }
77
78   /**
79    * Interface method which Gets the boolean value stored in this cell. If
80    * this cell contains an error, then returns FALSE. Always query this cell
81    * type using the accessor method isError() prior to calling this method
82    *
83    * @return TRUE if this cell contains TRUE, FALSE if it contains FALSE or
84    * an error code
85    */

86   public boolean getValue()
87   {
88     return value;
89   }
90
91   /**
92    * Returns the numerical value as a string
93    *
94    * @return The numerical value of the formula as a string
95    */

96   public String JavaDoc getContents()
97   {
98     Assert.verify(!isError());
99
100     // return Boolean.toString(value) - only available in 1.4 or later
101
return (new Boolean JavaDoc(value)).toString();
102   }
103
104   /**
105    * Returns the cell type
106    *
107    * @return The cell type
108    */

109   public CellType getType()
110   {
111     return CellType.BOOLEAN;
112   }
113
114   /**
115    * A special case which overrides the method in the subclass to get
116    * hold of the raw data
117    *
118    * @return the record
119    */

120   public Record getRecord()
121   {
122     return super.getRecord();
123   }
124 }
125
126
127
128
129
130
131
Popular Tags