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
73
74 public class NumberRecord
75 extends Record
76 implements CellValueRecordInterface, Comparable
77 {
78 public static final short sid = 0x203;
79
80 private int field_1_row;
81 private short field_2_col;
82 private short field_3_xf;
83 private double field_4_value;
84
85
86 public NumberRecord()
87 {
88 }
89
90
97
98 public NumberRecord(short id, short size, byte [] data)
99 {
100 super(id, size, data);
101 }
102
103
111
112 public NumberRecord(short id, short size, byte [] data, int offset)
113 {
114 super(id, size, data, offset);
115 }
116
117
124
125 protected void fillFields(byte [] data, short size, int offset)
126 {
127
128 field_1_row = LittleEndian.getUShort(data, 0 + offset);
129 field_2_col = LittleEndian.getShort(data, 2 + offset);
130 field_3_xf = LittleEndian.getShort(data, 4 + offset);
131 field_4_value = LittleEndian.getDouble(data, 6 + offset);
132 }
133
134
135 public void setRow(int row)
136 {
137 field_1_row = row;
138 }
139
140 public void setColumn(short col)
141 {
142 field_2_col = col;
143 }
144
145
150
151 public void setXFIndex(short xf)
152 {
153 field_3_xf = xf;
154 }
155
156
161
162 public void setValue(double value)
163 {
164 field_4_value = value;
165 }
166
167
168 public int getRow()
169 {
170 return field_1_row;
171 }
172
173 public short getColumn()
174 {
175 return field_2_col;
176 }
177
178
183
184 public short getXFIndex()
185 {
186 return field_3_xf;
187 }
188
189
194
195 public double getValue()
196 {
197 return field_4_value;
198 }
199
200 public String toString()
201 {
202 StringBuffer buffer = new StringBuffer();
203
204 buffer.append("[NUMBER]\n");
205 buffer.append(" .row = ")
206 .append(Integer.toHexString(getRow())).append("\n");
207 buffer.append(" .col = ")
208 .append(Integer.toHexString(getColumn())).append("\n");
209 buffer.append(" .xfindex = ")
210 .append(Integer.toHexString(getXFIndex())).append("\n");
211 buffer.append(" .value = ").append(getValue())
212 .append("\n");
213 buffer.append("[/NUMBER]\n");
214 return buffer.toString();
215 }
216
217
224
225 public int serialize(int offset, byte [] data)
226 {
227 LittleEndian.putShort(data, 0 + offset, sid);
228 LittleEndian.putShort(data, 2 + offset, ( short ) 14);
229
230 LittleEndian.putShort(data, 4 + offset, ( short ) getRow());
231 LittleEndian.putShort(data, 6 + offset, getColumn());
232 LittleEndian.putShort(data, 8 + offset, getXFIndex());
233 LittleEndian.putDouble(data, 10 + offset, getValue());
234 return getRecordSize();
235 }
236
237 public int getRecordSize()
238 {
239 return 18;
240 }
241
242
248
249 protected void validateSid(short id)
250 {
251 if (id != sid)
252 {
253 throw new RecordFormatException("NOT A Number RECORD");
254 }
255 }
256
257 public short getSid()
258 {
259 return this.sid;
260 }
261
262 public boolean isBefore(CellValueRecordInterface i)
263 {
264 if (this.getRow() > i.getRow())
265 {
266 return false;
267 }
268 if ((this.getRow() == i.getRow())
269 && (this.getColumn() > i.getColumn()))
270 {
271 return false;
272 }
273 if ((this.getRow() == i.getRow())
274 && (this.getColumn() == i.getColumn()))
275 {
276 return false;
277 }
278 return true;
279 }
280
281 public boolean isAfter(CellValueRecordInterface i)
282 {
283 if (this.getRow() < i.getRow())
284 {
285 return false;
286 }
287 if ((this.getRow() == i.getRow())
288 && (this.getColumn() < i.getColumn()))
289 {
290 return false;
291 }
292 if ((this.getRow() == i.getRow())
293 && (this.getColumn() == i.getColumn()))
294 {
295 return false;
296 }
297 return true;
298 }
299
300 public boolean isEqual(CellValueRecordInterface i)
301 {
302 return ((this.getRow() == i.getRow())
303 && (this.getColumn() == i.getColumn()));
304 }
305
306 public boolean isInValueSection()
307 {
308 return true;
309 }
310
311 public boolean isValue()
312 {
313 return true;
314 }
315
316 public int compareTo(Object obj)
317 {
318 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
319
320 if ((this.getRow() == loc.getRow())
321 && (this.getColumn() == loc.getColumn()))
322 {
323 return 0;
324 }
325 if (this.getRow() < loc.getRow())
326 {
327 return -1;
328 }
329 if (this.getRow() > loc.getRow())
330 {
331 return 1;
332 }
333 if (this.getColumn() < loc.getColumn())
334 {
335 return -1;
336 }
337 if (this.getColumn() > loc.getColumn())
338 {
339 return 1;
340 }
341 return -1;
342 }
343
344 public boolean equals(Object obj)
345 {
346 if (!(obj instanceof CellValueRecordInterface))
347 {
348 return false;
349 }
350 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
351
352 if ((this.getRow() == loc.getRow())
353 && (this.getColumn() == loc.getColumn()))
354 {
355 return true;
356 }
357 return false;
358 }
359
360 public Object clone() {
361 NumberRecord rec = new NumberRecord();
362 rec.field_1_row = field_1_row;
363 rec.field_2_col = field_2_col;
364 rec.field_3_xf = field_3_xf;
365 rec.field_4_value = field_4_value;
366 return rec;
367 }
368 }
369