1 /
55
56 package org.apache.poi.hssf.record;
57
58 import org.apache.poi.util.LittleEndian;
59
60
69
70 public class LabelSSTRecord
71 extends Record
72 implements CellValueRecordInterface, Comparable
73 {
74 public final static short sid = 0xfd;
75
76 private int field_1_row;
77 private short field_2_column;
78 private short field_3_xf_index;
79 private int field_4_sst_index;
80
81 public LabelSSTRecord()
82 {
83 }
84
85
92
93 public LabelSSTRecord(short id, short size, byte [] data)
94 {
95 super(id, size, data);
96 }
97
98
106
107 public LabelSSTRecord(short id, short size, byte [] data, int offset)
108 {
109 super(id, size, data, offset);
110 }
111
112 protected void validateSid(short id)
113 {
114 if (id != sid)
115 {
116 throw new RecordFormatException("NOT A valid LabelSST RECORD");
117 }
118 }
119
120 protected void fillFields(byte [] data, short size, int offset)
121 {
122
123 field_1_row = LittleEndian.getUShort(data, 0 + offset);
124 field_2_column = LittleEndian.getShort(data, 2 + offset);
125 field_3_xf_index = LittleEndian.getShort(data, 4 + offset);
126 field_4_sst_index = LittleEndian.getInt(data, 6 + offset);
127 }
128
129
130 public void setRow(int row)
131 {
132 field_1_row = row;
133 }
134
135 public void setColumn(short col)
136 {
137 field_2_column = col;
138 }
139
140
146
147 public void setXFIndex(short index)
148 {
149 field_3_xf_index = index;
150 }
151
152
158
159 public void setSSTIndex(int index)
160 {
161 field_4_sst_index = index;
162 }
163
164
165 public int getRow()
166 {
167 return field_1_row;
168 }
169
170 public short getColumn()
171 {
172 return field_2_column;
173 }
174
175
181
182 public short getXFIndex()
183 {
184 return field_3_xf_index;
185 }
186
187
193
194 public int getSSTIndex()
195 {
196 return field_4_sst_index;
197 }
198
199 public String toString()
200 {
201 StringBuffer buffer = new StringBuffer();
202
203 buffer.append("[LABELSST]\n");
204 buffer.append(" .row = ")
205 .append(Integer.toHexString(getRow())).append("\n");
206 buffer.append(" .column = ")
207 .append(Integer.toHexString(getColumn())).append("\n");
208 buffer.append(" .xfindex = ")
209 .append(Integer.toHexString(getXFIndex())).append("\n");
210 buffer.append(" .sstindex = ")
211 .append(Integer.toHexString(getSSTIndex())).append("\n");
212 buffer.append("[/LABELSST]\n");
213 return buffer.toString();
214 }
215
216 public int serialize(int offset, byte [] data)
217 {
218 LittleEndian.putShort(data, 0 + offset, sid);
219 LittleEndian.putShort(data, 2 + offset, ( short ) 10);
220
221 LittleEndian.putShort(data, 4 + offset, ( short )getRow());
222 LittleEndian.putShort(data, 6 + offset, getColumn());
223 LittleEndian.putShort(data, 8 + offset, getXFIndex());
224 LittleEndian.putInt(data, 10 + offset, getSSTIndex());
225 return getRecordSize();
226 }
227
228 public int getRecordSize()
229 {
230 return 14;
231 }
232
233 public short getSid()
234 {
235 return this.sid;
236 }
237
238 public boolean isBefore(CellValueRecordInterface i)
239 {
240 if (this.getRow() > i.getRow())
241 {
242 return false;
243 }
244 if ((this.getRow() == i.getRow())
245 && (this.getColumn() > i.getColumn()))
246 {
247 return false;
248 }
249 if ((this.getRow() == i.getRow())
250 && (this.getColumn() == i.getColumn()))
251 {
252 return false;
253 }
254 return true;
255 }
256
257 public boolean isAfter(CellValueRecordInterface i)
258 {
259 if (this.getRow() < i.getRow())
260 {
261 return false;
262 }
263 if ((this.getRow() == i.getRow())
264 && (this.getColumn() < i.getColumn()))
265 {
266 return false;
267 }
268 if ((this.getRow() == i.getRow())
269 && (this.getColumn() == i.getColumn()))
270 {
271 return false;
272 }
273 return true;
274 }
275
276 public boolean isEqual(CellValueRecordInterface i)
277 {
278 return ((this.getRow() == i.getRow())
279 && (this.getColumn() == i.getColumn()));
280 }
281
282 public boolean isInValueSection()
283 {
284 return true;
285 }
286
287 public boolean isValue()
288 {
289 return true;
290 }
291
292 public int compareTo(Object obj)
293 {
294 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
295
296 if ((this.getRow() == loc.getRow())
297 && (this.getColumn() == loc.getColumn()))
298 {
299 return 0;
300 }
301 if (this.getRow() < loc.getRow())
302 {
303 return -1;
304 }
305 if (this.getRow() > loc.getRow())
306 {
307 return 1;
308 }
309 if (this.getColumn() < loc.getColumn())
310 {
311 return -1;
312 }
313 if (this.getColumn() > loc.getColumn())
314 {
315 return 1;
316 }
317 return -1;
318 }
319
320 public boolean equals(Object obj)
321 {
322 if (!(obj instanceof CellValueRecordInterface))
323 {
324 return false;
325 }
326 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj;
327
328 if ((this.getRow() == loc.getRow())
329 && (this.getColumn() == loc.getColumn()))
330 {
331 return true;
332 }
333 return false;
334 }
335
336 public Object clone() {
337 LabelSSTRecord rec = new LabelSSTRecord();
338 rec.field_1_row = field_1_row;
339 rec.field_2_column = field_2_column;
340 rec.field_3_xf_index = field_3_xf_index;
341 rec.field_4_sst_index = field_4_sst_index;
342 return rec;
343 }
344 }
345