1 2 17 18 19 24 package org.apache.poi.hssf.record; 25 26 import org.apache.poi.util.LittleEndian; 27 import org.apache.poi.hssf.record.Record; 28 29 36 37 public class NumberRecord 38 extends Record 39 implements CellValueRecordInterface, Comparable 40 { 41 public static final short sid = 0x203; 42 private int field_1_row; 44 private short field_2_col; 45 private short field_3_xf; 46 private double field_4_value; 47 48 49 public NumberRecord() 50 { 51 } 52 53 60 61 public NumberRecord(short id, short size, byte [] data) 62 { 63 super(id, size, data); 64 } 65 66 74 75 public NumberRecord(short id, short size, byte [] data, int offset) 76 { 77 super(id, size, data, offset); 78 } 79 80 87 88 protected void fillFields(byte [] data, short size, int offset) 89 { 90 field_1_row = LittleEndian.getUShort(data, 0 + offset); 92 field_2_col = LittleEndian.getShort(data, 2 + offset); 93 field_3_xf = LittleEndian.getShort(data, 4 + offset); 94 field_4_value = LittleEndian.getDouble(data, 6 + offset); 95 } 96 97 public void setRow(int row) 99 { 100 field_1_row = row; 101 } 102 103 public void setColumn(short col) 104 { 105 field_2_col = col; 106 } 107 108 113 114 public void setXFIndex(short xf) 115 { 116 field_3_xf = xf; 117 } 118 119 124 125 public void setValue(double value) 126 { 127 field_4_value = value; 128 } 129 130 public int getRow() 132 { 133 return field_1_row; 134 } 135 136 public short getColumn() 137 { 138 return field_2_col; 139 } 140 141 146 147 public short getXFIndex() 148 { 149 return field_3_xf; 150 } 151 152 157 158 public double getValue() 159 { 160 return field_4_value; 161 } 162 163 public String toString() 164 { 165 StringBuffer buffer = new StringBuffer (); 166 167 buffer.append("[NUMBER]\n"); 168 buffer.append(" .row = ") 169 .append(Integer.toHexString(getRow())).append("\n"); 170 buffer.append(" .col = ") 171 .append(Integer.toHexString(getColumn())).append("\n"); 172 buffer.append(" .xfindex = ") 173 .append(Integer.toHexString(getXFIndex())).append("\n"); 174 buffer.append(" .value = ").append(getValue()) 175 .append("\n"); 176 buffer.append("[/NUMBER]\n"); 177 return buffer.toString(); 178 } 179 180 187 188 public int serialize(int offset, byte [] data) 189 { 190 LittleEndian.putShort(data, 0 + offset, sid); 191 LittleEndian.putShort(data, 2 + offset, ( short ) 14); 192 LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); 194 LittleEndian.putShort(data, 6 + offset, getColumn()); 195 LittleEndian.putShort(data, 8 + offset, getXFIndex()); 196 LittleEndian.putDouble(data, 10 + offset, getValue()); 197 return getRecordSize(); 198 } 199 200 public int getRecordSize() 201 { 202 return 18; 203 } 204 205 211 212 protected void validateSid(short id) 213 { 214 if (id != sid) 215 { 216 throw new RecordFormatException("NOT A Number RECORD"); 217 } 218 } 219 220 public short getSid() 221 { 222 return this.sid; 223 } 224 225 public boolean isBefore(CellValueRecordInterface i) 226 { 227 if (this.getRow() > i.getRow()) 228 { 229 return false; 230 } 231 if ((this.getRow() == i.getRow()) 232 && (this.getColumn() > i.getColumn())) 233 { 234 return false; 235 } 236 if ((this.getRow() == i.getRow()) 237 && (this.getColumn() == i.getColumn())) 238 { 239 return false; 240 } 241 return true; 242 } 243 244 public boolean isAfter(CellValueRecordInterface i) 245 { 246 if (this.getRow() < i.getRow()) 247 { 248 return false; 249 } 250 if ((this.getRow() == i.getRow()) 251 && (this.getColumn() < i.getColumn())) 252 { 253 return false; 254 } 255 if ((this.getRow() == i.getRow()) 256 && (this.getColumn() == i.getColumn())) 257 { 258 return false; 259 } 260 return true; 261 } 262 263 public boolean isEqual(CellValueRecordInterface i) 264 { 265 return ((this.getRow() == i.getRow()) 266 && (this.getColumn() == i.getColumn())); 267 } 268 269 public boolean isInValueSection() 270 { 271 return true; 272 } 273 274 public boolean isValue() 275 { 276 return true; 277 } 278 279 public int compareTo(Object obj) 280 { 281 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 282 283 if ((this.getRow() == loc.getRow()) 284 && (this.getColumn() == loc.getColumn())) 285 { 286 return 0; 287 } 288 if (this.getRow() < loc.getRow()) 289 { 290 return -1; 291 } 292 if (this.getRow() > loc.getRow()) 293 { 294 return 1; 295 } 296 if (this.getColumn() < loc.getColumn()) 297 { 298 return -1; 299 } 300 if (this.getColumn() > loc.getColumn()) 301 { 302 return 1; 303 } 304 return -1; 305 } 306 307 public boolean equals(Object obj) 308 { 309 if (!(obj instanceof CellValueRecordInterface)) 310 { 311 return false; 312 } 313 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 314 315 if ((this.getRow() == loc.getRow()) 316 && (this.getColumn() == loc.getColumn())) 317 { 318 return true; 319 } 320 return false; 321 } 322 323 public Object clone() { 324 NumberRecord rec = new NumberRecord(); 325 rec.field_1_row = field_1_row; 326 rec.field_2_col = field_2_col; 327 rec.field_3_xf = field_3_xf; 328 rec.field_4_value = field_4_value; 329 return rec; 330 } 331 } 332 | Popular Tags |