KickJava   Java API By Example, From Geeks To Geeks.

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


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
18 package org.apache.poi.hssf.record.formula;
19 import org.apache.poi.util.LittleEndian;
20
21 /**
22  *
23  * @author Jason Height (jheight at chariot dot net dot au)
24  */

25 public class FuncVarPtg extends AbstractFunctionPtg{
26     
27     public final static byte sid = 0x22;
28     private final static int SIZE = 4;
29     
30     private FuncVarPtg() {
31       //Required for clone methods
32
}
33
34  /**Creates new function pointer from a byte array
35      * usually called while reading an excel file.
36      */

37     public FuncVarPtg(byte[] data, int offset) {
38         offset++;
39         field_1_num_args = data[ offset + 0 ];
40         field_2_fnc_index = LittleEndian.getShort(data,offset + 1 );
41     }
42     
43     /**
44      * Create a function ptg from a string tokenised by the parser
45      */

46     public FuncVarPtg(String JavaDoc pName, byte pNumOperands) {
47         field_1_num_args = pNumOperands;
48         field_2_fnc_index = lookupIndex(pName);
49         try{
50             returnClass = ( (Byte JavaDoc) functionData[field_2_fnc_index][0]).byteValue();
51             paramClass = (byte[]) functionData[field_2_fnc_index][1];
52         } catch (NullPointerException JavaDoc npe ) {
53             returnClass = Ptg.CLASS_VALUE;
54             paramClass = new byte[] {Ptg.CLASS_VALUE};
55         }
56     }
57     
58      public void writeBytes(byte[] array, int offset) {
59         array[offset+0]=(byte) (sid + ptgClass);
60         array[offset+1]=field_1_num_args;
61         LittleEndian.putShort(array,offset+2,field_2_fnc_index);
62     }
63     
64      public int getNumberOfOperands() {
65         return field_1_num_args;
66     }
67     
68     public Object JavaDoc clone() {
69       FuncVarPtg ptg = new FuncVarPtg();
70       ptg.field_1_num_args = field_1_num_args;
71       ptg.field_2_fnc_index = field_2_fnc_index;
72       ptg.setClass(ptgClass);
73       return ptg;
74     }
75     
76     public int getSize() {
77         return SIZE;
78     }
79     
80     public String JavaDoc toString() {
81         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
82         buffer
83         .append("<FunctionVarPtg>").append("\n")
84         .append(" field_1_num_args=").append(field_1_num_args).append("\n")
85         .append(" name =").append(lookupName(field_2_fnc_index)).append("\n")
86         .append(" field_2_fnc_index=").append(field_2_fnc_index).append("\n")
87         .append("</FunctionPtg>");
88         return buffer.toString();
89     }
90
91     
92 }
93
Popular Tags