1 2 17 18 19 24 package org.apache.poi.hssf.record; 25 26 import org.apache.poi.util.LittleEndian; 27 28 35 36 public class BoolErrRecord 37 extends Record 38 implements CellValueRecordInterface, Comparable 39 { 40 public final static short sid = 0x205; 41 private int field_1_row; 43 private short field_2_column; 44 private short field_3_xf_index; 45 private byte field_4_bBoolErr; 46 private byte field_5_fError; 47 48 49 50 public BoolErrRecord() 51 { 52 } 53 54 61 62 public BoolErrRecord(short id, short size, byte [] data) 63 { 64 super(id, size, data); 65 } 66 67 75 76 public BoolErrRecord(short id, short size, byte [] data, int offset) 77 { 78 super(id, size, data, offset); 79 } 80 81 88 89 protected void fillFields(byte [] data, short size, int offset) 90 { 91 field_1_row = LittleEndian.getUShort(data, 0 + offset); 93 field_2_column = LittleEndian.getShort(data, 2 + offset); 94 field_3_xf_index = LittleEndian.getShort(data, 4 + offset); 95 field_4_bBoolErr = data[ 6 + offset ]; 96 field_5_fError = data[ 7 + offset ]; 97 } 98 99 public void setRow(int row) 101 { 102 field_1_row = row; 103 } 104 105 public void setColumn(short col) 106 { 107 field_2_column = col; 108 } 109 110 115 116 public void setXFIndex(short xf) 117 { 118 field_3_xf_index = xf; 119 } 120 121 126 127 public void setValue(boolean value) 128 { 129 field_4_bBoolErr = value ? ( byte ) 1 130 : ( byte ) 0; 131 field_5_fError = ( byte ) 0; 132 } 133 134 141 142 public void setValue(byte value) 143 { 144 if ( (value==0)||(value==7)||(value==15)||(value==23)||(value==29)||(value==36)||(value==42)) { 145 field_4_bBoolErr = value; 146 field_5_fError = ( byte ) 1; 147 } else { 148 throw new RuntimeException ("Error Value can only be 0,7,15,23,29,36 or 42. It cannot be "+value); 149 } 150 } 151 152 public int getRow() 154 { 155 return field_1_row; 156 } 157 158 public short getColumn() 159 { 160 return field_2_column; 161 } 162 163 168 169 public short getXFIndex() 170 { 171 return field_3_xf_index; 172 } 173 174 179 180 public boolean getBooleanValue() 181 { 182 return (field_4_bBoolErr != 0); 183 } 184 185 190 191 public byte getErrorValue() 192 { 193 return field_4_bBoolErr; 194 } 195 196 201 202 public boolean isBoolean() 203 { 204 return (field_5_fError == ( byte ) 0); 205 } 206 207 210 public void setError(boolean val) { 211 field_5_fError = (byte) (val == false ? 0 : 1); 212 } 213 214 219 220 public boolean isError() 221 { 222 return (field_5_fError != ( byte ) 0); 223 } 224 225 public String toString() 226 { 227 StringBuffer buffer = new StringBuffer (); 228 229 buffer.append("[BOOLERR]\n"); 230 buffer.append(" .row = ") 231 .append(Integer.toHexString(getRow())).append("\n"); 232 buffer.append(" .col = ") 233 .append(Integer.toHexString(getColumn())).append("\n"); 234 buffer.append(" .xfindex = ") 235 .append(Integer.toHexString(getXFIndex())).append("\n"); 236 if (isBoolean()) 237 { 238 buffer.append(" .booleanValue = ").append(getBooleanValue()) 239 .append("\n"); 240 } 241 else 242 { 243 buffer.append(" .errorValue = ").append(getErrorValue()) 244 .append("\n"); 245 } 246 buffer.append("[/BOOLERR]\n"); 247 return buffer.toString(); 248 } 249 250 257 258 public int serialize(int offset, byte [] data) 259 { 260 LittleEndian.putShort(data, 0 + offset, sid); 261 LittleEndian.putShort(data, 2 + offset, ( short ) 8); 262 LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); 264 LittleEndian.putShort(data, 6 + offset, getColumn()); 265 LittleEndian.putShort(data, 8 + offset, getXFIndex()); 266 data[ 10 + offset ] = field_4_bBoolErr; 267 data[ 11 + offset ] = field_5_fError; 268 return getRecordSize(); 269 } 270 271 public int getRecordSize() 272 { 273 return 12; 274 } 275 276 282 283 protected void validateSid(short id) 284 { 285 if (id != this.sid) 286 { 287 throw new RecordFormatException("Not a valid BoolErrRecord"); 288 } 289 } 290 291 public short getSid() 292 { 293 return this.sid; 294 } 295 296 public boolean isBefore(CellValueRecordInterface i) 297 { 298 if (this.getRow() > i.getRow()) 299 { 300 return false; 301 } 302 if ((this.getRow() == i.getRow()) 303 && (this.getColumn() > i.getColumn())) 304 { 305 return false; 306 } 307 if ((this.getRow() == i.getRow()) 308 && (this.getColumn() == i.getColumn())) 309 { 310 return false; 311 } 312 return true; 313 } 314 315 public boolean isAfter(CellValueRecordInterface i) 316 { 317 if (this.getRow() < i.getRow()) 318 { 319 return false; 320 } 321 if ((this.getRow() == i.getRow()) 322 && (this.getColumn() < i.getColumn())) 323 { 324 return false; 325 } 326 if ((this.getRow() == i.getRow()) 327 && (this.getColumn() == i.getColumn())) 328 { 329 return false; 330 } 331 return true; 332 } 333 334 public boolean isEqual(CellValueRecordInterface i) 335 { 336 return ((this.getRow() == i.getRow()) 337 && (this.getColumn() == i.getColumn())); 338 } 339 340 public boolean isInValueSection() 341 { 342 return true; 343 } 344 345 public boolean isValue() 346 { 347 return true; 348 } 349 350 public int compareTo(Object obj) 351 { 352 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 353 354 if ((this.getRow() == loc.getRow()) 355 && (this.getColumn() == loc.getColumn())) 356 { 357 return 0; 358 } 359 if (this.getRow() < loc.getRow()) 360 { 361 return -1; 362 } 363 if (this.getRow() > loc.getRow()) 364 { 365 return 1; 366 } 367 if (this.getColumn() < loc.getColumn()) 368 { 369 return -1; 370 } 371 if (this.getColumn() > loc.getColumn()) 372 { 373 return 1; 374 } 375 return -1; 376 } 377 378 public boolean equals(Object obj) 379 { 380 if (!(obj instanceof CellValueRecordInterface)) 381 { 382 return false; 383 } 384 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 385 386 if ((this.getRow() == loc.getRow()) 387 && (this.getColumn() == loc.getColumn())) 388 { 389 return true; 390 } 391 return false; 392 } 393 394 public Object clone() { 395 BoolErrRecord rec = new BoolErrRecord(); 396 rec.field_1_row = field_1_row; 397 rec.field_2_column = field_2_column; 398 rec.field_3_xf_index = field_3_xf_index; 399 rec.field_4_bBoolErr = field_4_bBoolErr; 400 rec.field_5_fError = field_5_fError; 401 return rec; 402 } 403 } 404 | Popular Tags |