1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.IntList; 22 import org.apache.poi.util.LittleEndian; 23 24 34 35 public class IndexRecord 36 extends Record 37 { 38 public final static short sid = 0x20B; 39 public final static int DBCELL_CAPACITY = 30; 40 public int field_1_zero; public int field_2_first_row; public int field_3_last_row_add1; public int field_4_zero; public IntList field_5_dbcells; 46 public IndexRecord() 47 { 48 } 49 50 57 58 public IndexRecord(short id, short size, byte [] data) 59 { 60 super(id, size, data); 61 } 62 63 71 72 public IndexRecord(short id, short size, byte [] data, int offset) 73 { 74 super(id, size, data, offset); 75 } 76 77 protected void validateSid(short id) 78 { 79 if (id != sid) 80 { 81 throw new RecordFormatException("NOT An Index RECORD"); 82 } 83 } 84 85 protected void fillFields(byte [] data, short size, int offset) 86 { 87 field_5_dbcells = 88 new IntList(DBCELL_CAPACITY); field_1_zero = LittleEndian.getInt(data, 0 + offset); 90 field_2_first_row = LittleEndian.getInt(data, 4 + offset); 91 field_3_last_row_add1 = LittleEndian.getInt(data, 8 + offset); 92 field_4_zero = LittleEndian.getInt(data, 12 + offset); 93 for (int k = 16; k < size; k = k + 4) 94 { 95 96 field_5_dbcells.add(LittleEndian.getInt(data, k + offset)); 98 } 99 } 100 101 public void setFirstRow(int row) 102 { 103 field_2_first_row = row; 104 } 105 106 public void setLastRowAdd1(int row) 107 { 108 field_3_last_row_add1 = row; 109 } 110 111 public void addDbcell(int cell) 112 { 113 if (field_5_dbcells == null) 114 { 115 field_5_dbcells = new IntList(); 116 } 117 field_5_dbcells.add(cell); 118 } 119 120 public void setDbcell(int cell, int value) 121 { 122 field_5_dbcells.set(cell, value); 123 } 124 125 public int getFirstRow() 126 { 127 return field_2_first_row; 128 } 129 130 public int getLastRowAdd1() 131 { 132 return field_3_last_row_add1; 133 } 134 135 public int getNumDbcells() 136 { 137 if (field_5_dbcells == null) 138 { 139 return 0; 140 } 141 return field_5_dbcells.size(); 142 } 143 144 public int getDbcellAt(int cellnum) 145 { 146 return field_5_dbcells.get(cellnum); 147 } 148 149 public String toString() 150 { 151 StringBuffer buffer = new StringBuffer (); 152 153 buffer.append("[INDEX]\n"); 154 buffer.append(" .firstrow = ") 155 .append(Integer.toHexString(getFirstRow())).append("\n"); 156 buffer.append(" .lastrowadd1 = ") 157 .append(Integer.toHexString(getLastRowAdd1())).append("\n"); 158 for (int k = 0; k < getNumDbcells(); k++) 159 { 160 buffer.append(" .dbcell_" + k + " = ") 161 .append(Integer.toHexString(getDbcellAt(k))).append("\n"); 162 } 163 buffer.append("[/INDEX]\n"); 164 return buffer.toString(); 165 } 166 167 public int serialize(int offset, byte [] data) 168 { 169 LittleEndian.putShort(data, 0 + offset, sid); 170 LittleEndian.putShort(data, 2 + offset, 171 ( short ) (16 + (getNumDbcells() * 4))); 172 LittleEndian.putInt(data, 4 + offset, 0); 173 LittleEndian.putInt(data, 8 + offset, getFirstRow()); 174 LittleEndian.putInt(data, 12 + offset, getLastRowAdd1()); 175 LittleEndian.putInt(data, 16 + offset, 0); 176 for (int k = 0; k < getNumDbcells(); k++) 177 { 178 LittleEndian.putInt(data, (k * 4) + 20 + offset, getDbcellAt(k)); 179 } 180 return getRecordSize(); 181 } 182 183 public int getRecordSize() 184 { 185 return 20 + (getNumDbcells() * 4); 186 } 187 188 191 public static int getRecordSizeForBlockCount(int blockCount) { 192 return 20 + (4 * blockCount); 193 } 194 195 public short getSid() 196 { 197 return this.sid; 198 } 199 200 public Object clone() { 201 IndexRecord rec = new IndexRecord(); 202 rec.field_1_zero = field_1_zero; 203 rec.field_2_first_row = field_2_first_row; 204 rec.field_3_last_row_add1 = field_3_last_row_add1; 205 rec.field_4_zero = field_4_zero; 206 rec.field_5_dbcells = new IntList(); 207 rec.field_5_dbcells.addAll(field_5_dbcells); 208 return rec; 209 } 210 } 211 | Popular Tags |