KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > formula > UnaryOperator


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.biff.formula;
21
22 import java.util.Stack JavaDoc;
23 import jxl.biff.IntegerHelper;
24
25 /**
26  * A cell reference in a formula
27  */

28 abstract class UnaryOperator extends Operator implements ParsedThing
29 {
30   /**
31    * Constructor
32    */

33   public UnaryOperator()
34   {
35   }
36
37   /**
38    * Reads the ptg data from the array starting at the specified position
39    *
40    * @param data the RPN array
41    * @param pos the current position in the array, excluding the ptg identifier
42    * @return the number of bytes read
43    */

44   public int read(byte[] data, int pos)
45   {
46     return 0;
47   }
48
49   /**
50    * Gets the operands for this operator from the stack
51    */

52   public void getOperands(Stack JavaDoc s)
53   {
54     ParseItem o1 = (ParseItem) s.pop();
55
56     add(o1);
57   }
58
59   /**
60    * Gets the string
61    *
62    * @param buf
63    */

64   public void getString(StringBuffer JavaDoc buf)
65   {
66     ParseItem[] operands = getOperands();
67     buf.append(getSymbol());
68     operands[0].getString(buf);
69   }
70
71   /**
72    * Adjusts all the relative cell references in this formula by the
73    * amount specified. Used when copying formulas
74    *
75    * @param colAdjust the amount to add on to each relative cell reference
76    * @param rowAdjust the amount to add on to each relative row reference
77    */

78   public void adjustRelativeCellReferences(int colAdjust, int rowAdjust)
79   {
80     ParseItem[] operands = getOperands();
81     operands[0].adjustRelativeCellReferences(colAdjust, rowAdjust);
82   }
83
84   /**
85    * Called when a column is inserted on the specified sheet. Tells
86    * the formula parser to update all of its cell references beyond this
87    * column
88    *
89    * @param sheetIndex the sheet on which the column was inserted
90    * @param col the column number which was inserted
91    * @param currentSheet TRUE if this formula is on the sheet in which the
92    * column was inserted, FALSE otherwise
93    */

94   void columnInserted(int sheetIndex, int col, boolean currentSheet)
95   {
96     ParseItem[] operands = getOperands();
97     operands[0].columnInserted(sheetIndex, col, currentSheet);
98   }
99
100   /**
101    * Called when a column is inserted on the specified sheet. Tells
102    * the formula parser to update all of its cell references beyond this
103    * column
104    *
105    * @param sheetIndex the sheet on which the column was removed
106    * @param col the column number which was removed
107    * @param currentSheet TRUE if this formula is on the sheet in which the
108    * column was inserted, FALSE otherwise
109    */

110   void columnRemoved(int sheetIndex, int col, boolean currentSheet)
111   {
112     ParseItem[] operands = getOperands();
113     operands[0].columnRemoved(sheetIndex, col, currentSheet);
114   }
115
116   /**
117    * Called when a column is inserted on the specified sheet. Tells
118    * the formula parser to update all of its cell references beyond this
119    * column
120    *
121    * @param sheetIndex the sheet on which the row was inserted
122    * @param row the row number which was inserted
123    * @param currentSheet TRUE if this formula is on the sheet in which the
124    * column was inserted, FALSE otherwise
125    */

126   void rowInserted(int sheetIndex, int row, boolean currentSheet)
127   {
128     ParseItem[] operands = getOperands();
129     operands[0].rowInserted(sheetIndex, row, currentSheet);
130   }
131
132   /**
133    * Called when a column is inserted on the specified sheet. Tells
134    * the formula parser to update all of its cell references beyond this
135    * column
136    *
137    * @param sheetIndex the sheet on which the row was removed
138    * @param row the row number which was removed
139    * @param currentSheet TRUE if this formula is on the sheet in which the
140    * column was inserted, FALSE otherwise
141    */

142   void rowRemoved(int sheetIndex, int row, boolean currentSheet)
143   {
144     ParseItem[] operands = getOperands();
145     operands[0].rowRemoved(sheetIndex, row, currentSheet);
146   }
147
148  /**
149    * Gets the token representation of this item in RPN
150    *
151    * @return the bytes applicable to this formula
152    */

153   byte[] getBytes()
154   {
155     // Get the data for the operands
156
ParseItem[] operands = getOperands();
157     byte[] data = operands[0].getBytes();
158
159     // Add on the operator byte
160
byte[] newdata = new byte[data.length + 1];
161     System.arraycopy(data, 0, newdata, 0, data.length);
162     newdata[data.length] = getToken().getCode();
163
164     return newdata;
165   }
166
167   /**
168    * Abstract method which gets the binary operator string symbol
169    *
170    * @return the string symbol for this token
171    */

172   abstract String JavaDoc getSymbol();
173
174   /**
175    * Abstract method which gets the token for this operator
176    *
177    * @return the string symbol for this token
178    */

179   abstract Token getToken();
180
181 }
182
Popular Tags