KickJava   Java API By Example, From Geeks To Geeks.

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


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

17
18
19 /*
20  * IntPtg.java
21  *
22  * Created on October 29, 2001, 7:37 PM
23  */

24 package org.apache.poi.hssf.record.formula;
25
26 import org.apache.poi.util.LittleEndian;
27 import org.apache.poi.hssf.model.Workbook;
28
29 /**
30  * Integer (short intger)
31  * Stores a (java) short value in a formula
32  * @author Andrew C. Oliver (acoliver at apache dot org)
33  * @author Jason Height (jheight at chariot dot net dot au)
34  */

35
36 public class IntPtg
37     extends Ptg
38 {
39     public final static int SIZE = 3;
40     public final static byte sid = 0x1e;
41     private short field_1_value;
42
43     private String JavaDoc val;
44     private int strlen = 0;
45   
46     private IntPtg() {
47       //Required for clone methods
48
}
49
50     public IntPtg(byte [] data, int offset)
51     {
52         setValue(LittleEndian.getShort(data, offset + 1));
53     }
54     
55     
56     // IntPtg should be able to create itself, shouldnt have to call setValue
57
public IntPtg(String JavaDoc formulaToken) {
58         setValue(Short.parseShort(formulaToken));
59     }
60
61     public void setValue(short value)
62     {
63         field_1_value = value;
64     }
65
66     public short getValue()
67     {
68         return field_1_value;
69     }
70
71     public void writeBytes(byte [] array, int offset)
72     {
73         array[ offset + 0 ] = sid;
74         LittleEndian.putShort(array, offset + 1, getValue());
75     }
76
77     public int getSize()
78     {
79         return SIZE;
80     }
81
82     public String JavaDoc toFormulaString(Workbook book)
83     {
84         return "" + getValue();
85     }
86  public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
87
88    public Object JavaDoc clone() {
89      IntPtg ptg = new IntPtg();
90      ptg.field_1_value = field_1_value;
91      return ptg;
92    }
93 }
94
Popular Tags