1 16 17 18 package org.apache.poi.hssf.record.formula; 19 20 import org.apache.poi.hssf.model.Workbook; 21 22 import org.apache.poi.util.LittleEndian; 23 import org.apache.poi.util.BitField; 24 25 import java.util.List ; 26 27 34 35 public class AttrPtg 36 extends OperationPtg 37 { 38 public final static byte sid = 0x19; 39 private final static int SIZE = 4; 40 private byte field_1_options; 41 private short field_2_data; 42 private BitField semiVolatile = new BitField(0x01); 43 private BitField optiIf = new BitField(0x02); 44 private BitField optiChoose = new BitField(0x04); 45 private BitField optGoto = new BitField(0x08); 46 private BitField sum = new BitField(0x10); 47 private BitField baxcel = new BitField(0x20); 48 private BitField space = new BitField(0x40); 49 50 public AttrPtg() { 51 } 52 53 public AttrPtg(byte [] data, int offset) 54 { 55 offset++; field_1_options = data[ offset + 0 ]; 57 field_2_data = LittleEndian.getShort(data, offset + 1); 58 } 59 60 public void setOptions(byte options) 61 { 62 field_1_options = options; 63 } 64 65 public byte getOptions() 66 { 67 return field_1_options; 68 } 69 70 public boolean isSemiVolatile() 71 { 72 return semiVolatile.isSet(getOptions()); 73 } 74 75 public boolean isOptimizedIf() 76 { 77 return optiIf.isSet(getOptions()); 78 } 79 80 public boolean isOptimizedChoose() 81 { 82 return optiChoose.isSet(getOptions()); 83 } 84 85 public boolean isGoto() 87 { 88 return optGoto.isSet(getOptions()); 89 } 90 91 public boolean isSum() 92 { 93 return sum.isSet(getOptions()); 94 } 95 96 public void setSum(boolean bsum) { 97 field_1_options=sum.setByteBoolean(field_1_options,bsum); 98 } 99 100 public void setOptimizedIf(boolean bif) { 101 field_1_options=optiIf.setByteBoolean(field_1_options,bif); 102 } 103 104 108 public void setGoto(boolean isGoto) { 109 field_1_options=optGoto.setByteBoolean(field_1_options, isGoto); 110 } 111 112 public boolean isBaxcel() 114 { 115 return baxcel.isSet(getOptions()); 116 } 117 118 public boolean isSpace() 120 { 121 return space.isSet(getOptions()); 122 } 123 124 public void setData(short data) 125 { 126 field_2_data = data; 127 } 128 129 public short getData() 130 { 131 return field_2_data; 132 } 133 134 public String toString() 135 { 136 StringBuffer buffer = new StringBuffer (); 137 138 buffer.append("AttrPtg\n"); 139 buffer.append("options=").append(field_1_options).append("\n"); 140 buffer.append("data =").append(field_2_data).append("\n"); 141 buffer.append("semi =").append(isSemiVolatile()).append("\n"); 142 buffer.append("optimif=").append(isOptimizedIf()).append("\n"); 143 buffer.append("optchos=").append(isOptimizedChoose()).append("\n"); 144 buffer.append("isGoto =").append(isGoto()).append("\n"); 145 buffer.append("isSum =").append(isSum()).append("\n"); 146 buffer.append("isBaxce=").append(isBaxcel()).append("\n"); 147 buffer.append("isSpace=").append(isSpace()).append("\n"); 148 return buffer.toString(); 149 } 150 151 public void writeBytes(byte [] array, int offset) 152 { 153 array[offset]=sid; 154 array[offset+1]=field_1_options; 155 LittleEndian.putShort(array,offset+2,field_2_data); 156 } 157 158 public int getSize() 159 { 160 return SIZE; 161 } 162 163 public String toFormulaString(String [] operands) { 164 if(space.isSet(field_1_options)) { 165 return operands[ 0 ]; 166 } else if (optiIf.isSet(field_1_options)) { 167 return toFormulaString((Workbook)null) + "(" + operands[ 0 ] +")"; 168 } else if (optGoto.isSet(field_1_options)) { 169 return toFormulaString((Workbook)null) + operands[0]; } else { 171 return toFormulaString((Workbook)null) + "(" + operands[ 0 ] + ")"; 172 } 173 } 174 175 176 public int getNumberOfOperands() 177 { 178 return 1; 179 } 180 181 public int getType() 182 { 183 return -1; 184 } 185 186 public String toFormulaString(Workbook book) { 187 if(semiVolatile.isSet(field_1_options)) { 188 return "ATTR(semiVolatile)"; 189 } 190 if(optiIf.isSet(field_1_options)) { 191 return "IF"; 192 } 193 if( optiChoose.isSet(field_1_options)) { 194 return "CHOOSE"; 195 } 196 if(optGoto.isSet(field_1_options)) { 197 return ""; 198 } 199 if(sum.isSet(field_1_options)) { 200 return "SUM"; 201 } 202 if(baxcel.isSet(field_1_options)) { 203 return "ATTR(baxcel)"; 204 } 205 if(space.isSet(field_1_options)) { 206 return ""; 207 } 208 return "UNKNOWN ATTRIBUTE"; 209 } 210 211 212 213 public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;} 214 215 public Object clone() { 216 AttrPtg ptg = new AttrPtg(); 217 ptg.field_1_options = field_1_options; 218 ptg.field_2_data = field_2_data; 219 return ptg; 220 } 221 } 222 | Popular Tags |