1 /
55
56
61 package org.apache.poi.hssf.record;
62
63 import org.apache.poi.util.LittleEndian;
64 import org.apache.poi.hssf.record.Record;
65
66
72
73 public class NumberRecord
74 extends Record
75 implements CellValueRecordInterface, Comparable
76 {
77 public static final short sid = 0x203;
78 private short field_1_row;
79 private short field_2_col;
80 private short field_3_xf;
81 private double field_4_value;
82
83
84 public NumberRecord()
85 {
86 }
87
88
95
96 public NumberRecord(short id, short size, byte [] data)
97 {
98 super(id, size, data);
99 }
100
101
109
110 public NumberRecord(short id, short size, byte [] data, int offset)
111 {
112 super(id, size, data, offset);
113 }
114
115
122
123 protected void fillFields(byte [] data, short size, int offset)
124 {
125 field_1_row = LittleEndian.getShort(data, 0 + offset);
126 field_2_col = LittleEndian.getShort(data, 2 + offset);
127 field_3_xf = LittleEndian.getShort(data, 4 + offset);
128 field_4_value = LittleEndian.getDouble(data, 6 + offset);
129 }
130
131 public void setRow(short row)
132 {
133 field_1_row = row;
134 }
135
136 public void setColumn(short col)
137 {
138 field_2_col = col;
139 }
140
141
146
147 public void setXFIndex(short xf)
148 {
149 field_3_xf = xf;
150 }
151
152
157
158 public void setValue(double value)
159 {
160 field_4_value = value;
161 }
162
163 public short getRow()
164 {
165 return field_1_row;
166 }
167
168 public short getColumn()
169 {
170 return field_2_col;
171 }
172
173
178
179 public short getXFIndex()
180 {
181 return field_3_xf;
182 }
183
184
189
190 public double getValue()
191 {
192 return field_4_value;
193 }
194
195 public String toString()
196 {
197 StringBuffer buffer = new StringBuffer();
198
199 buffer.append("[NUMBER]\n");
200 buffer.append(" .row = ")
201 .append(Integer.toHexString(getRow())).append("\n");
202 buffer.append(" .col = ")
203 .append(Integer.toHexString(getColumn())).append("\n");
204 buffer.append(" .xfindex = ")
205 .append(Integer.toHexString(getXFIndex())).append("\n");
206 buffer.append(" .value = ").append(getValue())
207 .append("\n");
208 buffer.append("[/NUMBER]\n");
209 return buffer.toString();
210 }
211
212
219
220 public int serialize(int offset, byte [] data)
221 {
222 LittleEndian.putShort(data, 0 + offset, sid);
223 LittleEndian.putShort(data, 2 + offset, ( short ) 14);
224 LittleEndian.putShort(data, 4 + offset, getRow());
225 LittleEndian.putShort(data, 6 + offset, getColumn());
226 LittleEndian.putShort(data, 8 + offset, getXFIndex());
227 LittleEndian.putDouble(data, 10 + offset, getValue());
228 return getRecordSize();
229 }
230
231 public int getRecordSize()
232 {
233 return 18;
234 }
235
236
242
243 protected void validateSid(short id)
244 {
245 if (id != sid)
246 {
247 throw new RecordFormatException("NOT A Number RECORD");
248 }
249 }
250
251 public short getSid()
252 {
253 return this.sid;
254 }
255
256 public boolean isBefore(CellValueRecordInterface i)
257 {
258 if (this.getRow() > i.getRow())
259 {
260 return false;
261 }
262 if ((this.getRow() == i.getRow())
263 && (this.getColumn() > i.getColumn()))
264 {
265 return false;
266 }
267 if ((this.getRow() == i.getRow())
268 && (this.getColumn() == i.getColumn()))
269 {
270 return false;
271 }
272 return true;
273 }
274
275 public boolean isAfter(CellValueRecordInterface i)
276 {
277 if (this.getRow() < i.getRow())
278 {
279 return false;
280 }
281 if ((this.getRow() == i.getRow())
282 && (this.getColumn() < i.getColumn()))
283 {
284 return false;
285 }
286 if ((this.getRow() == i.getRow())
287 && (this.getColumn() == i.getColumn()))
288 {
289 return false;
290 }
291 return true;
292 }
293
294 public boolean isEqual(CellValueRecordInterface i)
295 {
296 return ((this.getRow() == i.getRow())
297 && (this.getColumn() == i.getColumn()));
298 }
299
300 public boolean isInValueSection()
301 {
302 return true;
303 }
304
305 public boolean isValue()
306 {
307 return true;
308 }
309
310 public int compareTo(Object obj)
311 {
312 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
313
314 if ((this.getRow() == loc.getRow())
315 && (this.getColumn() == loc.getColumn()))
316 {
317 return 0;
318 }
319 if (this.getRow() < loc.getRow())
320 {
321 return -1;
322 }
323 if (this.getRow() > loc.getRow())
324 {
325 return 1;
326 }
327 if (this.getColumn() < loc.getColumn())
328 {
329 return -1;
330 }
331 if (this.getColumn() > loc.getColumn())
332 {
333 return 1;
334 }
335 return -1;
336 }
337
338 public boolean equals(Object obj)
339 {
340 if (!(obj instanceof CellValueRecordInterface))
341 {
342 return false;
343 }
344 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
345
346 if ((this.getRow() == loc.getRow())
347 && (this.getColumn() == loc.getColumn()))
348 {
349 return true;
350 }
351 return false;
352 }
353 }
354