KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > formula > BoolPtg


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.record.formula;
18
19 import org.apache.poi.util.LittleEndian;
20 import org.apache.poi.hssf.model.Workbook;
21
22 /**
23  * Boolean (boolean)
24  * Stores a (java) boolean value in a formula.
25  * @author Paul Krause (pkrause at soundbite dot com)
26  * @author Andrew C. Oliver (acoliver at apache dot org)
27  * @author Jason Height (jheight at chariot dot net dot au)
28  */

29
30 public class BoolPtg
31     extends Ptg
32 {
33     public final static int SIZE = 2;
34     public final static byte sid = 0x1d;
35     private boolean field_1_value;
36
37     private String JavaDoc val;
38
39     private BoolPtg() {
40       //Required for clone methods
41
}
42
43     public BoolPtg(byte [] data, int offset)
44     {
45         field_1_value = (data[offset + 1] == 1);
46     }
47
48
49     public BoolPtg(String JavaDoc formulaToken) {
50         field_1_value = (formulaToken.equals("TRUE"));
51     }
52
53     public void setValue(boolean value)
54     {
55         field_1_value = value;
56     }
57
58     public boolean getValue()
59     {
60         return field_1_value;
61     }
62
63     public void writeBytes(byte [] array, int offset)
64     {
65         array[ offset + 0 ] = sid;
66         array[ offset + 1 ] = (byte) (field_1_value ? 1 : 0);
67     }
68
69     public int getSize()
70     {
71         return SIZE;
72     }
73
74     public String JavaDoc toFormulaString(Workbook book)
75     {
76         return field_1_value ? "TRUE" : "FALSE";
77     }
78
79     public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
80
81     public Object JavaDoc clone() {
82         BoolPtg ptg = new BoolPtg();
83         ptg.field_1_value = field_1_value;
84         return ptg;
85     }
86 }
87
Popular Tags