You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [23/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java Sat May 22 20:56:44 2021
@@ -36,198 +36,198 @@ import org.apache.poi.util.LittleEndianO
* ArrayPtg elements and need to parse the data upto the FORMULA record size.
*/
public final class ArrayPtg extends Ptg {
- public static final byte sid = 0x20;
+ public static final byte sid = 0x20;
- private static final int RESERVED_FIELD_LEN = 7;
- /**
- * The size of the plain tArray token written within the standard formula tokens
- * (not including the data which comes after all formula tokens)
- */
- public static final int PLAIN_TOKEN_SIZE = 1 + RESERVED_FIELD_LEN;
-
- // 7 bytes of data (stored as an int, short and byte here)
- private final int _reserved0Int;
- private final int _reserved1Short;
- private final int _reserved2Byte;
-
- // data from these fields comes after the Ptg data of all tokens in current formula
- private final int _nColumns;
- private final int _nRows;
- private final Object[] _arrayValues;
-
- ArrayPtg(int reserved0, int reserved1, int reserved2, int nColumns, int nRows, Object[] arrayValues) {
- _reserved0Int = reserved0;
- _reserved1Short = reserved1;
- _reserved2Byte = reserved2;
- _nColumns = nColumns;
- _nRows = nRows;
- _arrayValues = arrayValues.clone();
- }
-
- public ArrayPtg(ArrayPtg other) {
- _reserved0Int = other._reserved0Int;
- _reserved1Short = other._reserved1Short;
- _reserved2Byte = other._reserved2Byte;
- _nColumns = other._nColumns;
- _nRows = other._nRows;
- _arrayValues = (other._arrayValues == null) ? null : other._arrayValues.clone();
- }
-
- /**
- * @param values2d array values arranged in rows
- */
- public ArrayPtg(Object[][] values2d) {
- int nColumns = values2d[0].length;
- int nRows = values2d.length;
- // convert 2-d to 1-d array (row by row according to getValueIndex())
- _nColumns = (short) nColumns;
- _nRows = (short) nRows;
-
- Object[] vv = new Object[_nColumns * _nRows];
- for (int r=0; r<nRows; r++) {
- Object[] rowData = values2d[r];
- for (int c=0; c<nColumns; c++) {
- vv[getValueIndex(c, r)] = rowData[c];
- }
- }
-
- _arrayValues = vv;
- _reserved0Int = 0;
- _reserved1Short = 0;
- _reserved2Byte = 0;
- }
- /**
- * @return 2-d array (inner index is rowIx, outer index is colIx)
- */
- public Object[][] getTokenArrayValues() {
- if (_arrayValues == null) {
- throw new IllegalStateException("array values not read yet");
- }
- Object[][] result = new Object[_nRows][_nColumns];
- for (int r = 0; r < _nRows; r++) {
- Object[] rowData = result[r];
- for (int c = 0; c < _nColumns; c++) {
- rowData[c] = _arrayValues[getValueIndex(c, r)];
- }
- }
- return result;
- }
-
- @Override
- public boolean isBaseToken() {
- return false;
- }
-
- /**
- * Note - (2D) array elements are stored row by row
- * @return the index into the internal 1D array for the specified column and row
- */
- /* package */ int getValueIndex(int colIx, int rowIx) {
- if(colIx < 0 || colIx >= _nColumns) {
- throw new IllegalArgumentException("Specified colIx (" + colIx
- + ") is outside the allowed range (0.." + (_nColumns-1) + ")");
- }
- if(rowIx < 0 || rowIx >= _nRows) {
- throw new IllegalArgumentException("Specified rowIx (" + rowIx
- + ") is outside the allowed range (0.." + (_nRows-1) + ")");
- }
- return rowIx * _nColumns + colIx;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeInt(_reserved0Int);
- out.writeShort(_reserved1Short);
- out.writeByte(_reserved2Byte);
- }
-
- public int writeTokenValueBytes(LittleEndianOutput out) {
-
- out.writeByte(_nColumns-1);
- out.writeShort(_nRows-1);
- ConstantValueParser.encode(out, _arrayValues);
- return 3 + ConstantValueParser.getEncodedSize(_arrayValues);
- }
-
- public int getRowCount() {
- return _nRows;
- }
-
- public int getColumnCount() {
- return _nColumns;
- }
-
- /** This size includes the size of the array Ptg plus the Array Ptg Token value size*/
- public int getSize() {
- return PLAIN_TOKEN_SIZE
- // data written after the all tokens:
- + 1 + 2 // column, row
- + ConstantValueParser.getEncodedSize(_arrayValues);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public String toFormulaString() {
- StringBuilder b = new StringBuilder();
- b.append("{");
- for (int y = 0; y < _nRows; y++) {
- if (y > 0) {
- b.append(";");
- }
- for (int x = 0; x < _nColumns; x++) {
- if (x > 0) {
- b.append(",");
- }
- Object o = _arrayValues[getValueIndex(x, y)];
- b.append(getConstantText(o));
- }
- }
- b.append("}");
- return b.toString();
- }
-
- private static String getConstantText(Object o) {
-
- if (o == null) {
- throw new RuntimeException("Array item cannot be null");
- }
- if (o instanceof String) {
- return "\"" + o + "\"";
- }
- if (o instanceof Double) {
- return NumberToTextConverter.toText((Double) o);
- }
- if (o instanceof Boolean) {
- return (Boolean) o ? "TRUE" : "FALSE";
- }
- if (o instanceof ErrorConstant) {
- return ((ErrorConstant)o).getText();
- }
- throw new IllegalArgumentException("Unexpected constant class (" + o.getClass().getName() + ")");
- }
+ private static final int RESERVED_FIELD_LEN = 7;
+ /**
+ * The size of the plain tArray token written within the standard formula tokens
+ * (not including the data which comes after all formula tokens)
+ */
+ public static final int PLAIN_TOKEN_SIZE = 1 + RESERVED_FIELD_LEN;
+
+ // 7 bytes of data (stored as an int, short and byte here)
+ private final int _reserved0Int;
+ private final int _reserved1Short;
+ private final int _reserved2Byte;
+
+ // data from these fields comes after the Ptg data of all tokens in current formula
+ private final int _nColumns;
+ private final int _nRows;
+ private final Object[] _arrayValues;
+
+ ArrayPtg(int reserved0, int reserved1, int reserved2, int nColumns, int nRows, Object[] arrayValues) {
+ _reserved0Int = reserved0;
+ _reserved1Short = reserved1;
+ _reserved2Byte = reserved2;
+ _nColumns = nColumns;
+ _nRows = nRows;
+ _arrayValues = arrayValues.clone();
+ }
+
+ public ArrayPtg(ArrayPtg other) {
+ _reserved0Int = other._reserved0Int;
+ _reserved1Short = other._reserved1Short;
+ _reserved2Byte = other._reserved2Byte;
+ _nColumns = other._nColumns;
+ _nRows = other._nRows;
+ _arrayValues = (other._arrayValues == null) ? null : other._arrayValues.clone();
+ }
+
+ /**
+ * @param values2d array values arranged in rows
+ */
+ public ArrayPtg(Object[][] values2d) {
+ int nColumns = values2d[0].length;
+ int nRows = values2d.length;
+ // convert 2-d to 1-d array (row by row according to getValueIndex())
+ _nColumns = (short) nColumns;
+ _nRows = (short) nRows;
+
+ Object[] vv = new Object[_nColumns * _nRows];
+ for (int r=0; r<nRows; r++) {
+ Object[] rowData = values2d[r];
+ for (int c=0; c<nColumns; c++) {
+ vv[getValueIndex(c, r)] = rowData[c];
+ }
+ }
+
+ _arrayValues = vv;
+ _reserved0Int = 0;
+ _reserved1Short = 0;
+ _reserved2Byte = 0;
+ }
+ /**
+ * @return 2-d array (inner index is rowIx, outer index is colIx)
+ */
+ public Object[][] getTokenArrayValues() {
+ if (_arrayValues == null) {
+ throw new IllegalStateException("array values not read yet");
+ }
+ Object[][] result = new Object[_nRows][_nColumns];
+ for (int r = 0; r < _nRows; r++) {
+ Object[] rowData = result[r];
+ for (int c = 0; c < _nColumns; c++) {
+ rowData[c] = _arrayValues[getValueIndex(c, r)];
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isBaseToken() {
+ return false;
+ }
+
+ /**
+ * Note - (2D) array elements are stored row by row
+ * @return the index into the internal 1D array for the specified column and row
+ */
+ /* package */ int getValueIndex(int colIx, int rowIx) {
+ if(colIx < 0 || colIx >= _nColumns) {
+ throw new IllegalArgumentException("Specified colIx (" + colIx
+ + ") is outside the allowed range (0.." + (_nColumns-1) + ")");
+ }
+ if(rowIx < 0 || rowIx >= _nRows) {
+ throw new IllegalArgumentException("Specified rowIx (" + rowIx
+ + ") is outside the allowed range (0.." + (_nRows-1) + ")");
+ }
+ return rowIx * _nColumns + colIx;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeInt(_reserved0Int);
+ out.writeShort(_reserved1Short);
+ out.writeByte(_reserved2Byte);
+ }
+
+ public int writeTokenValueBytes(LittleEndianOutput out) {
+
+ out.writeByte(_nColumns-1);
+ out.writeShort(_nRows-1);
+ ConstantValueParser.encode(out, _arrayValues);
+ return 3 + ConstantValueParser.getEncodedSize(_arrayValues);
+ }
+
+ public int getRowCount() {
+ return _nRows;
+ }
+
+ public int getColumnCount() {
+ return _nColumns;
+ }
+
+ /** This size includes the size of the array Ptg plus the Array Ptg Token value size*/
+ public int getSize() {
+ return PLAIN_TOKEN_SIZE
+ // data written after the all tokens:
+ + 1 + 2 // column, row
+ + ConstantValueParser.getEncodedSize(_arrayValues);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public String toFormulaString() {
+ StringBuilder b = new StringBuilder();
+ b.append("{");
+ for (int y = 0; y < _nRows; y++) {
+ if (y > 0) {
+ b.append(";");
+ }
+ for (int x = 0; x < _nColumns; x++) {
+ if (x > 0) {
+ b.append(",");
+ }
+ Object o = _arrayValues[getValueIndex(x, y)];
+ b.append(getConstantText(o));
+ }
+ }
+ b.append("}");
+ return b.toString();
+ }
+
+ private static String getConstantText(Object o) {
+
+ if (o == null) {
+ throw new RuntimeException("Array item cannot be null");
+ }
+ if (o instanceof String) {
+ return "\"" + o + "\"";
+ }
+ if (o instanceof Double) {
+ return NumberToTextConverter.toText((Double) o);
+ }
+ if (o instanceof Boolean) {
+ return (Boolean) o ? "TRUE" : "FALSE";
+ }
+ if (o instanceof ErrorConstant) {
+ return ((ErrorConstant)o).getText();
+ }
+ throw new IllegalArgumentException("Unexpected constant class (" + o.getClass().getName() + ")");
+ }
- @Override
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_ARRAY;
- }
+ return Ptg.CLASS_ARRAY;
+ }
- @Override
- public ArrayPtg copy() {
- return new ArrayPtg(this);
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "reserved0", () -> _reserved0Int,
- "reserved1", () -> _reserved1Short,
- "reserved2", () -> _reserved2Byte,
- "columnCount", this::getColumnCount,
- "rowCount", this::getRowCount,
- "arrayValues", () -> _arrayValues == null ? "#values#uninitialised#" : toFormulaString()
- );
- }
+ @Override
+ public ArrayPtg copy() {
+ return new ArrayPtg(this);
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "reserved0", () -> _reserved0Int,
+ "reserved1", () -> _reserved1Short,
+ "reserved2", () -> _reserved2Byte,
+ "columnCount", this::getColumnCount,
+ "rowCount", this::getRowCount,
+ "arrayValues", () -> _arrayValues == null ? "#values#uninitialised#" : toFormulaString()
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/BoolPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/BoolPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/BoolPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/BoolPtg.java Sat May 22 20:56:44 2021
@@ -28,54 +28,54 @@ import org.apache.poi.util.LittleEndianO
* Boolean (boolean) Stores a (java) boolean value in a formula.
*/
public final class BoolPtg extends ScalarConstantPtg {
- public static final int SIZE = 2;
- public static final byte sid = 0x1D;
+ public static final int SIZE = 2;
+ public static final byte sid = 0x1D;
- private static final BoolPtg FALSE = new BoolPtg(false);
- private static final BoolPtg TRUE = new BoolPtg(true);
+ private static final BoolPtg FALSE = new BoolPtg(false);
+ private static final BoolPtg TRUE = new BoolPtg(true);
- private final boolean _value;
+ private final boolean _value;
- private BoolPtg(boolean b) {
- _value = b;
- }
-
- public static BoolPtg valueOf(boolean b) {
- return b ? TRUE : FALSE;
- }
- public static BoolPtg read(LittleEndianInput in) {
- return valueOf(in.readByte() == 1);
- }
-
- public boolean getValue() {
- return _value;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeByte(_value ? 1 : 0);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString() {
- return _value ? "TRUE" : "FALSE";
- }
-
- @Override
- public BoolPtg copy() {
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("value", this::getValue);
- }
+ private BoolPtg(boolean b) {
+ _value = b;
+ }
+
+ public static BoolPtg valueOf(boolean b) {
+ return b ? TRUE : FALSE;
+ }
+ public static BoolPtg read(LittleEndianInput in) {
+ return valueOf(in.readByte() == 1);
+ }
+
+ public boolean getValue() {
+ return _value;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeByte(_value ? 1 : 0);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString() {
+ return _value ? "TRUE" : "FALSE";
+ }
+
+ @Override
+ public BoolPtg copy() {
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("value", this::getValue);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java Sat May 22 20:56:44 2021
@@ -25,7 +25,7 @@ public final class ConcatPtg extends Val
public static final ConcatPtg instance = new ConcatPtg();
private ConcatPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ControlPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ControlPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ControlPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ControlPtg.java Sat May 22 20:56:44 2021
@@ -19,14 +19,14 @@ package org.apache.poi.ss.formula.ptg;
public abstract class ControlPtg extends Ptg {
- protected ControlPtg() {}
+ protected ControlPtg() {}
- @Override
- public boolean isBaseToken() {
- return true;
- }
- @Override
+ @Override
+ public boolean isBaseToken() {
+ return true;
+ }
+ @Override
public final byte getDefaultOperandClass() {
- throw new IllegalStateException("Control tokens are not classified");
- }
+ throw new IllegalStateException("Control tokens are not classified");
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java Sat May 22 20:56:44 2021
@@ -34,65 +34,65 @@ import org.apache.poi.util.LittleEndianO
* @version 1.0-pre
*/
public final class DeletedArea3DPtg extends OperandPtg implements WorkbookDependentFormula {
- public static final byte sid = 0x3d;
- private final int field_1_index_extern_sheet;
- private final int unused1;
- private final int unused2;
-
- public DeletedArea3DPtg(int externSheetIndex) {
- field_1_index_extern_sheet = externSheetIndex;
- unused1 = 0;
- unused2 = 0;
- }
-
- public DeletedArea3DPtg(LittleEndianInput in) {
- field_1_index_extern_sheet = in.readUShort();
- unused1 = in.readInt();
- unused2 = in.readInt();
- }
- public String toFormulaString(FormulaRenderingWorkbook book) {
- return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString());
- }
- public String toFormulaString() {
- throw new RuntimeException("3D references need a workbook to determine formula text");
- }
- @Override
+ public static final byte sid = 0x3d;
+ private final int field_1_index_extern_sheet;
+ private final int unused1;
+ private final int unused2;
+
+ public DeletedArea3DPtg(int externSheetIndex) {
+ field_1_index_extern_sheet = externSheetIndex;
+ unused1 = 0;
+ unused2 = 0;
+ }
+
+ public DeletedArea3DPtg(LittleEndianInput in) {
+ field_1_index_extern_sheet = in.readUShort();
+ unused1 = in.readInt();
+ unused2 = in.readInt();
+ }
+ public String toFormulaString(FormulaRenderingWorkbook book) {
+ return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString());
+ }
+ public String toFormulaString() {
+ throw new RuntimeException("3D references need a workbook to determine formula text");
+ }
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_REF;
- }
+ return Ptg.CLASS_REF;
+ }
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return 11;
- }
-
- public int getExternSheetIndex() {
- return field_1_index_extern_sheet;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(field_1_index_extern_sheet);
- out.writeInt(unused1);
- out.writeInt(unused2);
- }
-
- @Override
- public DeletedArea3DPtg copy() {
- // immutable
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "externSheetIndex", this::getExternSheetIndex,
- "unused1", () -> unused1,
- "unused2", () -> unused2
- );
- }
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return 11;
+ }
+
+ public int getExternSheetIndex() {
+ return field_1_index_extern_sheet;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(field_1_index_extern_sheet);
+ out.writeInt(unused1);
+ out.writeInt(unused2);
+ }
+
+ @Override
+ public DeletedArea3DPtg copy() {
+ // immutable
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "externSheetIndex", this::getExternSheetIndex,
+ "unused1", () -> unused1,
+ "unused2", () -> unused2
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java Sat May 22 20:56:44 2021
@@ -35,57 +35,57 @@ import org.apache.poi.util.LittleEndianO
* @since 1.0-pre
*/
public final class DeletedRef3DPtg extends OperandPtg implements WorkbookDependentFormula {
- public static final byte sid = 0x3c;
- private final int field_1_index_extern_sheet;
- private final int unused1;
-
- /** Creates new DeletedRef3DPtg */
- public DeletedRef3DPtg(LittleEndianInput in) {
- field_1_index_extern_sheet = in.readUShort();
- unused1 = in.readInt();
- }
-
- public DeletedRef3DPtg(int externSheetIndex) {
- field_1_index_extern_sheet = externSheetIndex;
- unused1 = 0;
- }
-
- public String toFormulaString(FormulaRenderingWorkbook book) {
- return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString());
- }
- public String toFormulaString() {
- throw new RuntimeException("3D references need a workbook to determine formula text");
- }
- @Override
+ public static final byte sid = 0x3c;
+ private final int field_1_index_extern_sheet;
+ private final int unused1;
+
+ /** Creates new DeletedRef3DPtg */
+ public DeletedRef3DPtg(LittleEndianInput in) {
+ field_1_index_extern_sheet = in.readUShort();
+ unused1 = in.readInt();
+ }
+
+ public DeletedRef3DPtg(int externSheetIndex) {
+ field_1_index_extern_sheet = externSheetIndex;
+ unused1 = 0;
+ }
+
+ public String toFormulaString(FormulaRenderingWorkbook book) {
+ return ExternSheetNameResolver.prependSheetName(book, field_1_index_extern_sheet, FormulaError.REF.getString());
+ }
+ public String toFormulaString() {
+ throw new RuntimeException("3D references need a workbook to determine formula text");
+ }
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_REF;
- }
+ return Ptg.CLASS_REF;
+ }
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return 7;
- }
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(field_1_index_extern_sheet);
- out.writeInt(unused1);
- }
-
- @Override
- public DeletedRef3DPtg copy() {
- // immutable
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "externSheetIndex", () -> field_1_index_extern_sheet,
- "unused1", () -> unused1
- );
- }
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return 7;
+ }
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(field_1_index_extern_sheet);
+ out.writeInt(unused1);
+ }
+
+ @Override
+ public DeletedRef3DPtg copy() {
+ // immutable
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "externSheetIndex", () -> field_1_index_extern_sheet,
+ "unused1", () -> unused1
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DividePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DividePtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DividePtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/DividePtg.java Sat May 22 20:56:44 2021
@@ -26,7 +26,7 @@ public final class DividePtg extends Val
public static final DividePtg instance = new DividePtg();
private DividePtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/EqualPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/EqualPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/EqualPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/EqualPtg.java Sat May 22 20:56:44 2021
@@ -23,7 +23,7 @@ public final class EqualPtg extends Valu
public static final EqualPtg instance = new EqualPtg();
private EqualPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java Sat May 22 20:56:44 2021
@@ -28,7 +28,7 @@ public final class GreaterEqualPtg exten
public static final GreaterEqualPtg instance = new GreaterEqualPtg();
private GreaterEqualPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java Sat May 22 20:56:44 2021
@@ -28,7 +28,7 @@ public final class GreaterThanPtg extend
public static final GreaterThanPtg instance = new GreaterThanPtg();
private GreaterThanPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntPtg.java Sat May 22 20:56:44 2021
@@ -28,67 +28,67 @@ import org.apache.poi.util.LittleEndianO
* Integer (unsigned short integer) Stores an unsigned short value (java int) in a formula
*/
public final class IntPtg extends ScalarConstantPtg {
- // 16 bit unsigned integer
- private static final int MIN_VALUE = 0x0000;
- private static final int MAX_VALUE = 0xFFFF;
-
- /**
- * Excel represents integers 0..65535 with the tInt token.
- *
- * @return {@code true} if the specified value is within the range of values
- * {@code IntPtg} can represent.
- */
- public static boolean isInRange(int i) {
- return i >= MIN_VALUE && i <= MAX_VALUE;
- }
-
- public static final int SIZE = 3;
- public static final byte sid = 0x1e;
- private final int field_1_value;
-
- public IntPtg(LittleEndianInput in) {
- this(in.readUShort());
- }
-
- public IntPtg(int value) {
- if (!isInRange(value)) {
- throw new IllegalArgumentException("value is out of range: " + value);
- }
- field_1_value = value;
- }
-
- public int getValue() {
- return field_1_value;
- }
-
- @Override
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(getValue());
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- @Override
- public int getSize() {
- return SIZE;
- }
-
- @Override
- public String toFormulaString() {
- return String.valueOf(getValue());
- }
-
- @Override
- public IntPtg copy() {
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("value", this::getValue);
- }
+ // 16 bit unsigned integer
+ private static final int MIN_VALUE = 0x0000;
+ private static final int MAX_VALUE = 0xFFFF;
+
+ /**
+ * Excel represents integers 0..65535 with the tInt token.
+ *
+ * @return {@code true} if the specified value is within the range of values
+ * {@code IntPtg} can represent.
+ */
+ public static boolean isInRange(int i) {
+ return i >= MIN_VALUE && i <= MAX_VALUE;
+ }
+
+ public static final int SIZE = 3;
+ public static final byte sid = 0x1e;
+ private final int field_1_value;
+
+ public IntPtg(LittleEndianInput in) {
+ this(in.readUShort());
+ }
+
+ public IntPtg(int value) {
+ if (!isInRange(value)) {
+ throw new IllegalArgumentException("value is out of range: " + value);
+ }
+ field_1_value = value;
+ }
+
+ public int getValue() {
+ return field_1_value;
+ }
+
+ @Override
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(getValue());
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ @Override
+ public int getSize() {
+ return SIZE;
+ }
+
+ @Override
+ public String toFormulaString() {
+ return String.valueOf(getValue());
+ }
+
+ @Override
+ public IntPtg copy() {
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("value", this::getValue);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java Sat May 22 20:56:44 2021
@@ -20,46 +20,46 @@ package org.apache.poi.ss.formula.ptg;
import org.apache.poi.util.LittleEndianOutput;
public final class IntersectionPtg extends OperationPtg {
- public static final byte sid = 0x0f;
+ public static final byte sid = 0x0f;
- public static final IntersectionPtg instance = new IntersectionPtg();
+ public static final IntersectionPtg instance = new IntersectionPtg();
- private IntersectionPtg() {
- // enforce singleton
- }
+ private IntersectionPtg() {
+ // enforce singleton
+ }
- @Override
+ @Override
public final boolean isBaseToken() {
- return true;
- }
+ return true;
+ }
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return 1;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- }
-
- public String toFormulaString() {
- return " ";
- }
-
- public String toFormulaString(String[] operands) {
- return operands[0] + " " + operands[1];
- }
-
- public int getNumberOfOperands() {
- return 2;
- }
-
- @Override
- public IntersectionPtg copy() {
- return instance;
- }
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return 1;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ }
+
+ public String toFormulaString() {
+ return " ";
+ }
+
+ public String toFormulaString(String[] operands) {
+ return operands[0] + " " + operands[1];
+ }
+
+ public int getNumberOfOperands() {
+ return 2;
+ }
+
+ @Override
+ public IntersectionPtg copy() {
+ return instance;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java Sat May 22 20:56:44 2021
@@ -30,7 +30,7 @@ public final class LessEqualPtg extends
public static final LessEqualPtg instance = new LessEqualPtg();
private LessEqualPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java Sat May 22 20:56:44 2021
@@ -32,7 +32,7 @@ public final class LessThanPtg extends V
public static final LessThanPtg instance = new LessThanPtg();
private LessThanPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java Sat May 22 20:56:44 2021
@@ -25,59 +25,59 @@ import org.apache.poi.util.LittleEndianI
import org.apache.poi.util.LittleEndianOutput;
public final class MemAreaPtg extends OperandPtg {
- public static final short sid = 0x26;
- private static final int SIZE = 7;
- private final int field_1_reserved;
- private final int field_2_subex_len;
-
- /** Creates new MemAreaPtg */
-
- public MemAreaPtg(int subexLen) {
- field_1_reserved = 0;
- field_2_subex_len = subexLen;
- }
-
- public MemAreaPtg(LittleEndianInput in) {
- field_1_reserved = in.readInt();
- field_2_subex_len = in.readShort();
- }
-
- public int getLenRefSubexpression() {
- return field_2_subex_len;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeInt(field_1_reserved);
- out.writeShort(field_2_subex_len);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString() {
- return ""; // TODO: Not sure how to format this. -- DN
- }
+ public static final short sid = 0x26;
+ private static final int SIZE = 7;
+ private final int field_1_reserved;
+ private final int field_2_subex_len;
+
+ /** Creates new MemAreaPtg */
+
+ public MemAreaPtg(int subexLen) {
+ field_1_reserved = 0;
+ field_2_subex_len = subexLen;
+ }
+
+ public MemAreaPtg(LittleEndianInput in) {
+ field_1_reserved = in.readInt();
+ field_2_subex_len = in.readShort();
+ }
+
+ public int getLenRefSubexpression() {
+ return field_2_subex_len;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeInt(field_1_reserved);
+ out.writeShort(field_2_subex_len);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString() {
+ return ""; // TODO: Not sure how to format this. -- DN
+ }
- @Override
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
- }
+ return Ptg.CLASS_VALUE;
+ }
- @Override
- public MemAreaPtg copy() {
- // immutable
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
- }
+ @Override
+ public MemAreaPtg copy() {
+ // immutable
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java Sat May 22 20:56:44 2021
@@ -25,57 +25,57 @@ import org.apache.poi.util.LittleEndianI
import org.apache.poi.util.LittleEndianOutput;
public final class MemErrPtg extends OperandPtg {
- public static final short sid = 0x27;
- private static final int SIZE = 7;
- private int field_1_reserved;
- private short field_2_subex_len;
-
- public MemErrPtg(MemErrPtg other) {
- super(other);
- field_1_reserved = other.field_1_reserved;
- field_2_subex_len = other.field_2_subex_len;
- }
-
- public MemErrPtg(LittleEndianInput in) {
- field_1_reserved = in.readInt();
- field_2_subex_len = in.readShort();
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeInt(field_1_reserved);
- out.writeShort(field_2_subex_len);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString() {
- return "ERR#";
- }
+ public static final short sid = 0x27;
+ private static final int SIZE = 7;
+ private int field_1_reserved;
+ private short field_2_subex_len;
+
+ public MemErrPtg(MemErrPtg other) {
+ super(other);
+ field_1_reserved = other.field_1_reserved;
+ field_2_subex_len = other.field_2_subex_len;
+ }
+
+ public MemErrPtg(LittleEndianInput in) {
+ field_1_reserved = in.readInt();
+ field_2_subex_len = in.readShort();
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeInt(field_1_reserved);
+ out.writeShort(field_2_subex_len);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString() {
+ return "ERR#";
+ }
- @Override
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
- }
+ return Ptg.CLASS_VALUE;
+ }
- public int getLenRefSubexpression() {
- return field_2_subex_len;
- }
-
- @Override
- public MemErrPtg copy() {
- return new MemErrPtg(this);
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
- }
+ public int getLenRefSubexpression() {
+ return field_2_subex_len;
+ }
+
+ @Override
+ public MemErrPtg copy() {
+ return new MemErrPtg(this);
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java Sat May 22 20:56:44 2021
@@ -26,60 +26,60 @@ import org.apache.poi.util.LittleEndianO
public final class MemFuncPtg extends OperandPtg {
- public static final byte sid = 0x29;
- private final int field_1_len_ref_subexpression;
+ public static final byte sid = 0x29;
+ private final int field_1_len_ref_subexpression;
- /**
- * Creates new function pointer from a byte array usually called while
- * reading an excel file.
- */
- public MemFuncPtg(LittleEndianInput in) {
- this(in.readUShort());
- }
-
- public MemFuncPtg(int subExprLen) {
- field_1_len_ref_subexpression = subExprLen;
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return 3;
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(field_1_len_ref_subexpression);
- }
-
- public String toFormulaString() {
- return "";
- }
+ /**
+ * Creates new function pointer from a byte array usually called while
+ * reading an excel file.
+ */
+ public MemFuncPtg(LittleEndianInput in) {
+ this(in.readUShort());
+ }
+
+ public MemFuncPtg(int subExprLen) {
+ field_1_len_ref_subexpression = subExprLen;
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return 3;
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(field_1_len_ref_subexpression);
+ }
+
+ public String toFormulaString() {
+ return "";
+ }
- @Override
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_REF;
- }
+ return Ptg.CLASS_REF;
+ }
- public int getNumberOfOperands() {
- return field_1_len_ref_subexpression;
- }
-
- public int getLenRefSubexpression() {
- return field_1_len_ref_subexpression;
- }
-
- @Override
- public MemFuncPtg copy() {
- // immutable
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
- }
+ public int getNumberOfOperands() {
+ return field_1_len_ref_subexpression;
+ }
+
+ public int getLenRefSubexpression() {
+ return field_1_len_ref_subexpression;
+ }
+
+ @Override
+ public MemFuncPtg copy() {
+ // immutable
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("lenRefSubexpression", this::getLenRefSubexpression);
+ }
}
\ No newline at end of file
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java Sat May 22 20:56:44 2021
@@ -27,39 +27,39 @@ import org.apache.poi.util.LittleEndianO
*/
public final class MissingArgPtg extends ScalarConstantPtg {
- private static final int SIZE = 1;
- public static final byte sid = 0x16;
+ private static final int SIZE = 1;
+ public static final byte sid = 0x16;
- public static final Ptg instance = new MissingArgPtg();
+ public static final Ptg instance = new MissingArgPtg();
- private MissingArgPtg() {
- // enforce singleton
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString() {
- return " ";
- }
-
- @Override
- public MissingArgPtg copy() {
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return null;
- }
+ private MissingArgPtg() {
+ // enforce singleton
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString() {
+ return " ";
+ }
+
+ @Override
+ public MissingArgPtg copy() {
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return null;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java Sat May 22 20:56:44 2021
@@ -26,7 +26,7 @@ public final class MultiplyPtg extends V
public static final MultiplyPtg instance = new MultiplyPtg();
private MultiplyPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NamePtg.java Sat May 22 20:56:44 2021
@@ -30,78 +30,78 @@ import org.apache.poi.util.LittleEndianO
* See the spec at 2.5.198.76 PtgName
*/
public final class NamePtg extends OperandPtg implements WorkbookDependentFormula {
- public static final short sid = 0x23;
- private static final int SIZE = 5;
+ public static final short sid = 0x23;
+ private static final int SIZE = 5;
- /** one-based index to defined name record */
- private int field_1_label_index;
- private short field_2_zero; // reserved must be 0
-
- /**
- * @param nameIndex zero-based index to name within workbook
- */
- public NamePtg(int nameIndex) {
- field_1_label_index = 1 + nameIndex; // convert to 1-based
- }
-
- public NamePtg(NamePtg other) {
- super(other);
- field_1_label_index = other.field_1_label_index;
- field_2_zero = other.field_2_zero;
- }
-
- /** Creates new NamePtg */
- public NamePtg(LittleEndianInput in) {
- field_1_label_index = in.readUShort();
- field_2_zero = in.readShort();
- }
-
- /**
- * @return zero based index to a defined name record in the LinkTable
- */
- public int getIndex() {
- return field_1_label_index - 1; // convert to zero based
- }
-
- @Override
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(field_1_label_index);
- out.writeShort(field_2_zero);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- @Override
- public int getSize() {
- return SIZE;
- }
-
- @Override
- public String toFormulaString(FormulaRenderingWorkbook book) {
- return book.getNameText(this);
- }
-
- @Override
- public String toFormulaString() {
- throw new RuntimeException("3D references need a workbook to determine formula text");
- }
-
- @Override
- public byte getDefaultOperandClass() {
- return Ptg.CLASS_REF;
- }
-
- @Override
- public NamePtg copy() {
- return new NamePtg(this);
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("index", this::getIndex);
- }
+ /** one-based index to defined name record */
+ private int field_1_label_index;
+ private short field_2_zero; // reserved must be 0
+
+ /**
+ * @param nameIndex zero-based index to name within workbook
+ */
+ public NamePtg(int nameIndex) {
+ field_1_label_index = 1 + nameIndex; // convert to 1-based
+ }
+
+ public NamePtg(NamePtg other) {
+ super(other);
+ field_1_label_index = other.field_1_label_index;
+ field_2_zero = other.field_2_zero;
+ }
+
+ /** Creates new NamePtg */
+ public NamePtg(LittleEndianInput in) {
+ field_1_label_index = in.readUShort();
+ field_2_zero = in.readShort();
+ }
+
+ /**
+ * @return zero based index to a defined name record in the LinkTable
+ */
+ public int getIndex() {
+ return field_1_label_index - 1; // convert to zero based
+ }
+
+ @Override
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(field_1_label_index);
+ out.writeShort(field_2_zero);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ @Override
+ public int getSize() {
+ return SIZE;
+ }
+
+ @Override
+ public String toFormulaString(FormulaRenderingWorkbook book) {
+ return book.getNameText(this);
+ }
+
+ @Override
+ public String toFormulaString() {
+ throw new RuntimeException("3D references need a workbook to determine formula text");
+ }
+
+ @Override
+ public byte getDefaultOperandClass() {
+ return Ptg.CLASS_REF;
+ }
+
+ @Override
+ public NamePtg copy() {
+ return new NamePtg(this);
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("index", this::getIndex);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NameXPtg.java Sat May 22 20:56:44 2021
@@ -35,81 +35,81 @@ import org.apache.poi.util.LittleEndianO
* is {@link NameXPxg}
*/
public final class NameXPtg extends OperandPtg implements WorkbookDependentFormula {
- public static final short sid = 0x39;
- private static final int SIZE = 7;
+ public static final short sid = 0x39;
+ private static final int SIZE = 7;
- /** index to REF entry in externsheet record */
- private final int _sheetRefIndex;
- /** index to defined name or externname table(1 based) */
- private final int _nameNumber;
- /** reserved must be 0 */
- private final int _reserved;
-
- private NameXPtg(int sheetRefIndex, int nameNumber, int reserved) {
- _sheetRefIndex = sheetRefIndex;
- _nameNumber = nameNumber;
- _reserved = reserved;
- }
-
- /**
- * @param sheetRefIndex index to REF entry in externsheet record
- * @param nameIndex index to defined name or externname table
- */
- public NameXPtg(int sheetRefIndex, int nameIndex) {
- this(sheetRefIndex, nameIndex + 1, 0);
- }
-
- public NameXPtg(LittleEndianInput in) {
- this(in.readUShort(), in.readUShort(), in.readUShort());
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeShort(_sheetRefIndex);
- out.writeShort(_nameNumber);
- out.writeShort(_reserved);
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString(FormulaRenderingWorkbook book) {
- // -1 to convert definedNameIndex from 1-based to zero-based
- return book.resolveNameXText(this);
- }
- public String toFormulaString() {
- throw new RuntimeException("3D references need a workbook to determine formula text");
- }
+ /** index to REF entry in externsheet record */
+ private final int _sheetRefIndex;
+ /** index to defined name or externname table(1 based) */
+ private final int _nameNumber;
+ /** reserved must be 0 */
+ private final int _reserved;
+
+ private NameXPtg(int sheetRefIndex, int nameNumber, int reserved) {
+ _sheetRefIndex = sheetRefIndex;
+ _nameNumber = nameNumber;
+ _reserved = reserved;
+ }
+
+ /**
+ * @param sheetRefIndex index to REF entry in externsheet record
+ * @param nameIndex index to defined name or externname table
+ */
+ public NameXPtg(int sheetRefIndex, int nameIndex) {
+ this(sheetRefIndex, nameIndex + 1, 0);
+ }
+
+ public NameXPtg(LittleEndianInput in) {
+ this(in.readUShort(), in.readUShort(), in.readUShort());
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeShort(_sheetRefIndex);
+ out.writeShort(_nameNumber);
+ out.writeShort(_reserved);
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString(FormulaRenderingWorkbook book) {
+ // -1 to convert definedNameIndex from 1-based to zero-based
+ return book.resolveNameXText(this);
+ }
+ public String toFormulaString() {
+ throw new RuntimeException("3D references need a workbook to determine formula text");
+ }
- @Override
+ @Override
public byte getDefaultOperandClass() {
- return Ptg.CLASS_VALUE;
- }
+ return Ptg.CLASS_VALUE;
+ }
- public int getSheetRefIndex() {
- return _sheetRefIndex;
- }
- public int getNameIndex() {
- return _nameNumber - 1;
- }
-
- @Override
- public NameXPtg copy() {
- // immutable
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "sheetRefIndex", this::getSheetRefIndex,
- "nameIndex", this::getNameIndex
- );
- }
+ public int getSheetRefIndex() {
+ return _sheetRefIndex;
+ }
+ public int getNameIndex() {
+ return _nameNumber - 1;
+ }
+
+ @Override
+ public NameXPtg copy() {
+ // immutable
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "sheetRefIndex", this::getSheetRefIndex,
+ "nameIndex", this::getNameIndex
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java Sat May 22 20:56:44 2021
@@ -26,7 +26,7 @@ public final class NotEqualPtg extends V
public static final NotEqualPtg instance = new NotEqualPtg();
private NotEqualPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NumberPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NumberPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NumberPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/NumberPtg.java Sat May 22 20:56:44 2021
@@ -30,61 +30,61 @@ import org.apache.poi.util.LittleEndianO
* field using IEEE notation
*/
public final class NumberPtg extends ScalarConstantPtg {
- public static final int SIZE = 9;
- public static final byte sid = 0x1f;
- private final double field_1_value;
-
- public NumberPtg(LittleEndianInput in) {
- this(in.readDouble());
- }
-
- /**
- * Create a NumberPtg from a string representation of the number Number
- * format is not checked, it is expected to be validated in the parser that
- * calls this method.
- *
- * @param value String representation of a floating point number
- */
- public NumberPtg(String value) {
- this(Double.parseDouble(value));
- }
-
- public NumberPtg(double value) {
- field_1_value = value;
- }
-
- public double getValue() {
- return field_1_value;
- }
-
- @Override
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- out.writeDouble(getValue());
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- @Override
- public int getSize() {
- return SIZE;
- }
-
- @Override
- public String toFormulaString() {
- return NumberToTextConverter.toText(field_1_value);
- }
-
- @Override
- public NumberPtg copy() {
- return this;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("value", this::getValue);
- }
+ public static final int SIZE = 9;
+ public static final byte sid = 0x1f;
+ private final double field_1_value;
+
+ public NumberPtg(LittleEndianInput in) {
+ this(in.readDouble());
+ }
+
+ /**
+ * Create a NumberPtg from a string representation of the number Number
+ * format is not checked, it is expected to be validated in the parser that
+ * calls this method.
+ *
+ * @param value String representation of a floating point number
+ */
+ public NumberPtg(String value) {
+ this(Double.parseDouble(value));
+ }
+
+ public NumberPtg(double value) {
+ field_1_value = value;
+ }
+
+ public double getValue() {
+ return field_1_value;
+ }
+
+ @Override
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ out.writeDouble(getValue());
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ @Override
+ public int getSize() {
+ return SIZE;
+ }
+
+ @Override
+ public String toFormulaString() {
+ return NumberToTextConverter.toText(field_1_value);
+ }
+
+ @Override
+ public NumberPtg copy() {
+ return this;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("value", this::getValue);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/OperandPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/OperandPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/OperandPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/OperandPtg.java Sat May 22 20:56:44 2021
@@ -19,20 +19,20 @@ package org.apache.poi.ss.formula.ptg;
public abstract class OperandPtg extends Ptg {
- protected OperandPtg() {}
+ protected OperandPtg() {}
- protected OperandPtg(OperandPtg other) {
- super(other);
- }
+ protected OperandPtg(OperandPtg other) {
+ super(other);
+ }
- /**
- * All Operand {@link Ptg}s are classified ('relative', 'value', 'array')
- */
- @Override
+ /**
+ * All Operand {@link Ptg}s are classified ('relative', 'value', 'array')
+ */
+ @Override
public final boolean isBaseToken() {
- return false;
- }
+ return false;
+ }
- @Override
- public abstract OperandPtg copy();
+ @Override
+ public abstract OperandPtg copy();
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java Sat May 22 20:56:44 2021
@@ -29,43 +29,43 @@ import org.apache.poi.util.LittleEndianO
*/
public final class ParenthesisPtg extends ControlPtg {
- private static final int SIZE = 1;
- public static final byte sid = 0x15;
+ private static final int SIZE = 1;
+ public static final byte sid = 0x15;
- public static final ParenthesisPtg instance = new ParenthesisPtg();
+ public static final ParenthesisPtg instance = new ParenthesisPtg();
- private ParenthesisPtg() {
- // enforce singleton
- }
-
- public void write(LittleEndianOutput out) {
- out.writeByte(sid + getPtgClass());
- }
-
- @Override
- public byte getSid() {
- return sid;
- }
-
- public int getSize() {
- return SIZE;
- }
-
- public String toFormulaString() {
- return "()";
- }
-
- public String toFormulaString(String[] operands) {
- return "(" + operands[0] + ")";
- }
-
- @Override
- public ParenthesisPtg copy() {
- return instance;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return null;
- }
+ private ParenthesisPtg() {
+ // enforce singleton
+ }
+
+ public void write(LittleEndianOutput out) {
+ out.writeByte(sid + getPtgClass());
+ }
+
+ @Override
+ public byte getSid() {
+ return sid;
+ }
+
+ public int getSize() {
+ return SIZE;
+ }
+
+ public String toFormulaString() {
+ return "()";
+ }
+
+ public String toFormulaString(String[] operands) {
+ return "(" + operands[0] + ")";
+ }
+
+ @Override
+ public ParenthesisPtg copy() {
+ return instance;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return null;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PercentPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PercentPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PercentPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PercentPtg.java Sat May 22 20:56:44 2021
@@ -29,7 +29,7 @@ public final class PercentPtg extends Va
public static final PercentPtg instance = new PercentPtg();
private PercentPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PowerPtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PowerPtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PowerPtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/PowerPtg.java Sat May 22 20:56:44 2021
@@ -23,7 +23,7 @@ public final class PowerPtg extends Valu
public static final PowerPtg instance = new PowerPtg();
private PowerPtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ptg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ptg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ptg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ptg.java Sat May 22 20:56:44 2021
@@ -40,285 +40,285 @@ import org.apache.poi.util.LittleEndianO
* evaluation logic, so POI mostly accesses {@code Ptg}s in the same way.
*/
public abstract class Ptg implements Duplicatable, GenericRecord {
- public static final Ptg[] EMPTY_PTG_ARRAY = { };
+ public static final Ptg[] EMPTY_PTG_ARRAY = { };
- public static final byte CLASS_REF = 0x00;
- public static final byte CLASS_VALUE = 0x20;
- public static final byte CLASS_ARRAY = 0x40;
-
- private byte ptgClass = CLASS_REF; //base ptg
-
- protected Ptg() {}
-
- protected Ptg(Ptg other) {
- ptgClass = other.ptgClass;
- }
-
- /**
- * Reads {@code size} bytes of the input stream, to create an array of {@code Ptg}s.
- * Extra data (beyond {@code size}) may be read if and {@code ArrayPtg}s are present.
- */
- public static Ptg[] readTokens(int size, LittleEndianInput in) {
- List<Ptg> temp = new ArrayList<>(4 + size / 2);
- int pos = 0;
- boolean hasArrayPtgs = false;
- while (pos < size) {
- Ptg ptg = Ptg.createPtg(in);
- if (ptg instanceof ArrayInitialPtg) {
- hasArrayPtgs = true;
- }
- pos += ptg.getSize();
- temp.add(ptg);
- }
- if(pos != size) {
- throw new RuntimeException("Ptg array size mismatch");
- }
- if (hasArrayPtgs) {
- Ptg[] result = toPtgArray(temp);
- for (int i=0;i<result.length;i++) {
- if (result[i] instanceof ArrayInitialPtg) {
- result[i] = ((ArrayInitialPtg) result[i]).finishReading(in);
- }
- }
- return result;
- }
- return toPtgArray(temp);
- }
-
- public static Ptg createPtg(LittleEndianInput in) {
- byte id = in.readByte();
-
- if (id < 0x20) {
- return createBasePtg(id, in);
- }
-
- Ptg retval = createClassifiedPtg(id, in);
-
- if (id >= 0x60) {
- retval.setClass(CLASS_ARRAY);
- } else if (id >= 0x40) {
- retval.setClass(CLASS_VALUE);
- } else {
- retval.setClass(CLASS_REF);
- }
- return retval;
- }
-
- private static Ptg createClassifiedPtg(byte id, LittleEndianInput in) {
-
- int baseId = id & 0x1F | 0x20;
-
- switch (baseId) {
- case ArrayPtg.sid: return new ArrayInitialPtg(in);//0x20, 0x40, 0x60
- case FuncPtg.sid: return FuncPtg.create(in); // 0x21, 0x41, 0x61
- case FuncVarPtg.sid: return FuncVarPtg.create(in);//0x22, 0x42, 0x62
- case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
- case RefPtg.sid: return new RefPtg(in); // 0x24, 0x44, 0x64
- case AreaPtg.sid: return new AreaPtg(in); // 0x25, 0x45, 0x65
- case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
- case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
- case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
- case RefErrorPtg.sid: return new RefErrorPtg(in); // 0x2a, 0x4a, 0x6a
- case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
- case RefNPtg.sid: return new RefNPtg(in); // 0x2c, 0x4c, 0x6c
- case AreaNPtg.sid: return new AreaNPtg(in); // 0x2d, 0x4d, 0x6d
-
- case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
- case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
- case Area3DPtg.sid: return new Area3DPtg(in); // 0x3b, 0x5b, 0x7b
- case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
- case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
- }
- throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
- Integer.toHexString(id) + " (" + ( int ) id + ")");
- }
-
- private static Ptg createBasePtg(byte id, LittleEndianInput in) {
- switch(id) {
- case 0x00: return new UnknownPtg(id); // TODO - not a real Ptg
- case ExpPtg.sid: return new ExpPtg(in); // 0x01
- case TblPtg.sid: return new TblPtg(in); // 0x02
- case AddPtg.sid: return AddPtg.instance; // 0x03
- case SubtractPtg.sid: return SubtractPtg.instance; // 0x04
- case MultiplyPtg.sid: return MultiplyPtg.instance; // 0x05
- case DividePtg.sid: return DividePtg.instance; // 0x06
- case PowerPtg.sid: return PowerPtg.instance; // 0x07
- case ConcatPtg.sid: return ConcatPtg.instance; // 0x08
- case LessThanPtg.sid: return LessThanPtg.instance; // 0x09
- case LessEqualPtg.sid: return LessEqualPtg.instance; // 0x0a
- case EqualPtg.sid: return EqualPtg.instance; // 0x0b
- case GreaterEqualPtg.sid: return GreaterEqualPtg.instance;// 0x0c
- case GreaterThanPtg.sid: return GreaterThanPtg.instance; // 0x0d
- case NotEqualPtg.sid: return NotEqualPtg.instance; // 0x0e
- case IntersectionPtg.sid: return IntersectionPtg.instance;// 0x0f
- case UnionPtg.sid: return UnionPtg.instance; // 0x10
- case RangePtg.sid: return RangePtg.instance; // 0x11
- case UnaryPlusPtg.sid: return UnaryPlusPtg.instance; // 0x12
- case UnaryMinusPtg.sid: return UnaryMinusPtg.instance; // 0x13
- case PercentPtg.sid: return PercentPtg.instance; // 0x14
- case ParenthesisPtg.sid: return ParenthesisPtg.instance; // 0x15
- case MissingArgPtg.sid: return MissingArgPtg.instance; // 0x16
-
- case StringPtg.sid: return new StringPtg(in); // 0x17
- // not implemented yet: case SxNamePtg.sid: return new SxNamePtg(in); // 0x18
- case AttrPtg.sid: return new AttrPtg(in); // 0x19
- case ErrPtg.sid: return ErrPtg.read(in); // 0x1c
- case BoolPtg.sid: return BoolPtg.read(in); // 0x1d
- case IntPtg.sid: return new IntPtg(in); // 0x1e
- case NumberPtg.sid: return new NumberPtg(in); // 0x1f
- }
- throw new RuntimeException("Unexpected base token id (" + id + ")");
- }
-
- private static Ptg[] toPtgArray(List<Ptg> l) {
- if (l.isEmpty()) {
- return EMPTY_PTG_ARRAY;
- }
- Ptg[] result = new Ptg[l.size()];
- l.toArray(result);
- return result;
- }
- /**
- * This method will return the same result as {@link #getEncodedSizeWithoutArrayData(Ptg[])}
- * if there are no array tokens present.
- * @return the full size taken to encode the specified {@code Ptg}s
- */
- public static int getEncodedSize(Ptg[] ptgs) {
- int result = 0;
- for (Ptg ptg : ptgs) {
- result += ptg.getSize();
- }
- return result;
- }
- /**
- * Used to calculate value that should be encoded at the start of the encoded Ptg token array;
- * @return the size of the encoded Ptg tokens not including any trailing array data.
- */
- public static int getEncodedSizeWithoutArrayData(Ptg[] ptgs) {
- int result = 0;
- for (Ptg ptg : ptgs) {
- if (ptg instanceof ArrayPtg) {
- result += ArrayPtg.PLAIN_TOKEN_SIZE;
- } else {
- result += ptg.getSize();
- }
- }
- return result;
- }
- /**
- * Writes the ptgs to the data buffer, starting at the specified offset.
- *
- * <br>
- * The 2 byte encode length field is <b>not</b> written by this method.
- * @return number of bytes written
- */
- public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
- LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset); // NOSONAR
-
- List<Ptg> arrayPtgs = null;
-
- for (Ptg ptg : ptgs) {
- ptg.write(out);
- if (ptg instanceof ArrayPtg) {
- if (arrayPtgs == null) {
- arrayPtgs = new ArrayList<>(5);
- }
- arrayPtgs.add(ptg);
- }
- }
- if (arrayPtgs != null) {
- for (Ptg arrayPtg : arrayPtgs) {
- ArrayPtg p = (ArrayPtg) arrayPtg;
- p.writeTokenValueBytes(out);
- }
- }
- return out.getWriteIndex() - offset;
- }
-
- /**
- * @return the encoded length of this Ptg, including the initial Ptg type identifier byte.
- */
- public abstract int getSize();
-
- public abstract void write(LittleEndianOutput out);
-
- /**
- * return a string representation of this token alone
- */
- public abstract String toFormulaString();
-
- @Override
- public final String toString() {
- return GenericRecordJsonWriter.marshal(this);
- }
-
- public final void setClass(byte thePtgClass) {
- if (isBaseToken()) {
- throw new RuntimeException("setClass should not be called on a base token");
- }
- ptgClass = thePtgClass;
- }
-
- /**
- * @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
- */
- public final byte getPtgClass() {
- return ptgClass;
- }
-
- /**
- * Debug / diagnostic method to get this token's 'operand class' type.
- * @return 'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
- */
- public final char getRVAType() {
- if (isBaseToken()) {
- return '.';
- }
- switch (ptgClass) {
- case Ptg.CLASS_REF: return 'R';
- case Ptg.CLASS_VALUE: return 'V';
- case Ptg.CLASS_ARRAY: return 'A';
- }
- throw new RuntimeException("Unknown operand class (" + ptgClass + ")");
- }
-
- public abstract byte getDefaultOperandClass();
-
- /**
- * @return {@code false} if this token is classified as 'reference', 'value', or 'array'
- */
- public abstract boolean isBaseToken();
-
- public static boolean doesFormulaReferToDeletedCell(Ptg[] ptgs) {
- for (Ptg ptg : ptgs) {
- if (isDeletedCellRef(ptg)) {
- return true;
- }
- }
- return false;
- }
-
- private static boolean isDeletedCellRef(Ptg ptg) {
- if (ptg == ErrPtg.REF_INVALID) {
- return true;
- }
- if (ptg instanceof DeletedArea3DPtg) {
- return true;
- }
- if (ptg instanceof DeletedRef3DPtg) {
- return true;
- }
- if (ptg instanceof AreaErrPtg) {
- return true;
- }
- return ptg instanceof RefErrorPtg;
- }
-
- @Override
- public abstract Ptg copy();
-
- /**
- * @return structure id of the parsed thing, or {@code -1} if the record has no sid
- */
- public abstract byte getSid();
+ public static final byte CLASS_REF = 0x00;
+ public static final byte CLASS_VALUE = 0x20;
+ public static final byte CLASS_ARRAY = 0x40;
+
+ private byte ptgClass = CLASS_REF; //base ptg
+
+ protected Ptg() {}
+
+ protected Ptg(Ptg other) {
+ ptgClass = other.ptgClass;
+ }
+
+ /**
+ * Reads {@code size} bytes of the input stream, to create an array of {@code Ptg}s.
+ * Extra data (beyond {@code size}) may be read if and {@code ArrayPtg}s are present.
+ */
+ public static Ptg[] readTokens(int size, LittleEndianInput in) {
+ List<Ptg> temp = new ArrayList<>(4 + size / 2);
+ int pos = 0;
+ boolean hasArrayPtgs = false;
+ while (pos < size) {
+ Ptg ptg = Ptg.createPtg(in);
+ if (ptg instanceof ArrayInitialPtg) {
+ hasArrayPtgs = true;
+ }
+ pos += ptg.getSize();
+ temp.add(ptg);
+ }
+ if(pos != size) {
+ throw new RuntimeException("Ptg array size mismatch");
+ }
+ if (hasArrayPtgs) {
+ Ptg[] result = toPtgArray(temp);
+ for (int i=0;i<result.length;i++) {
+ if (result[i] instanceof ArrayInitialPtg) {
+ result[i] = ((ArrayInitialPtg) result[i]).finishReading(in);
+ }
+ }
+ return result;
+ }
+ return toPtgArray(temp);
+ }
+
+ public static Ptg createPtg(LittleEndianInput in) {
+ byte id = in.readByte();
+
+ if (id < 0x20) {
+ return createBasePtg(id, in);
+ }
+
+ Ptg retval = createClassifiedPtg(id, in);
+
+ if (id >= 0x60) {
+ retval.setClass(CLASS_ARRAY);
+ } else if (id >= 0x40) {
+ retval.setClass(CLASS_VALUE);
+ } else {
+ retval.setClass(CLASS_REF);
+ }
+ return retval;
+ }
+
+ private static Ptg createClassifiedPtg(byte id, LittleEndianInput in) {
+
+ int baseId = id & 0x1F | 0x20;
+
+ switch (baseId) {
+ case ArrayPtg.sid: return new ArrayInitialPtg(in);//0x20, 0x40, 0x60
+ case FuncPtg.sid: return FuncPtg.create(in); // 0x21, 0x41, 0x61
+ case FuncVarPtg.sid: return FuncVarPtg.create(in);//0x22, 0x42, 0x62
+ case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
+ case RefPtg.sid: return new RefPtg(in); // 0x24, 0x44, 0x64
+ case AreaPtg.sid: return new AreaPtg(in); // 0x25, 0x45, 0x65
+ case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
+ case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
+ case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
+ case RefErrorPtg.sid: return new RefErrorPtg(in); // 0x2a, 0x4a, 0x6a
+ case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
+ case RefNPtg.sid: return new RefNPtg(in); // 0x2c, 0x4c, 0x6c
+ case AreaNPtg.sid: return new AreaNPtg(in); // 0x2d, 0x4d, 0x6d
+
+ case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
+ case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
+ case Area3DPtg.sid: return new Area3DPtg(in); // 0x3b, 0x5b, 0x7b
+ case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
+ case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
+ }
+ throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
+ Integer.toHexString(id) + " (" + ( int ) id + ")");
+ }
+
+ private static Ptg createBasePtg(byte id, LittleEndianInput in) {
+ switch(id) {
+ case 0x00: return new UnknownPtg(id); // TODO - not a real Ptg
+ case ExpPtg.sid: return new ExpPtg(in); // 0x01
+ case TblPtg.sid: return new TblPtg(in); // 0x02
+ case AddPtg.sid: return AddPtg.instance; // 0x03
+ case SubtractPtg.sid: return SubtractPtg.instance; // 0x04
+ case MultiplyPtg.sid: return MultiplyPtg.instance; // 0x05
+ case DividePtg.sid: return DividePtg.instance; // 0x06
+ case PowerPtg.sid: return PowerPtg.instance; // 0x07
+ case ConcatPtg.sid: return ConcatPtg.instance; // 0x08
+ case LessThanPtg.sid: return LessThanPtg.instance; // 0x09
+ case LessEqualPtg.sid: return LessEqualPtg.instance; // 0x0a
+ case EqualPtg.sid: return EqualPtg.instance; // 0x0b
+ case GreaterEqualPtg.sid: return GreaterEqualPtg.instance;// 0x0c
+ case GreaterThanPtg.sid: return GreaterThanPtg.instance; // 0x0d
+ case NotEqualPtg.sid: return NotEqualPtg.instance; // 0x0e
+ case IntersectionPtg.sid: return IntersectionPtg.instance;// 0x0f
+ case UnionPtg.sid: return UnionPtg.instance; // 0x10
+ case RangePtg.sid: return RangePtg.instance; // 0x11
+ case UnaryPlusPtg.sid: return UnaryPlusPtg.instance; // 0x12
+ case UnaryMinusPtg.sid: return UnaryMinusPtg.instance; // 0x13
+ case PercentPtg.sid: return PercentPtg.instance; // 0x14
+ case ParenthesisPtg.sid: return ParenthesisPtg.instance; // 0x15
+ case MissingArgPtg.sid: return MissingArgPtg.instance; // 0x16
+
+ case StringPtg.sid: return new StringPtg(in); // 0x17
+ // not implemented yet: case SxNamePtg.sid: return new SxNamePtg(in); // 0x18
+ case AttrPtg.sid: return new AttrPtg(in); // 0x19
+ case ErrPtg.sid: return ErrPtg.read(in); // 0x1c
+ case BoolPtg.sid: return BoolPtg.read(in); // 0x1d
+ case IntPtg.sid: return new IntPtg(in); // 0x1e
+ case NumberPtg.sid: return new NumberPtg(in); // 0x1f
+ }
+ throw new RuntimeException("Unexpected base token id (" + id + ")");
+ }
+
+ private static Ptg[] toPtgArray(List<Ptg> l) {
+ if (l.isEmpty()) {
+ return EMPTY_PTG_ARRAY;
+ }
+ Ptg[] result = new Ptg[l.size()];
+ l.toArray(result);
+ return result;
+ }
+ /**
+ * This method will return the same result as {@link #getEncodedSizeWithoutArrayData(Ptg[])}
+ * if there are no array tokens present.
+ * @return the full size taken to encode the specified {@code Ptg}s
+ */
+ public static int getEncodedSize(Ptg[] ptgs) {
+ int result = 0;
+ for (Ptg ptg : ptgs) {
+ result += ptg.getSize();
+ }
+ return result;
+ }
+ /**
+ * Used to calculate value that should be encoded at the start of the encoded Ptg token array;
+ * @return the size of the encoded Ptg tokens not including any trailing array data.
+ */
+ public static int getEncodedSizeWithoutArrayData(Ptg[] ptgs) {
+ int result = 0;
+ for (Ptg ptg : ptgs) {
+ if (ptg instanceof ArrayPtg) {
+ result += ArrayPtg.PLAIN_TOKEN_SIZE;
+ } else {
+ result += ptg.getSize();
+ }
+ }
+ return result;
+ }
+ /**
+ * Writes the ptgs to the data buffer, starting at the specified offset.
+ *
+ * <br>
+ * The 2 byte encode length field is <b>not</b> written by this method.
+ * @return number of bytes written
+ */
+ public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
+ LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset); // NOSONAR
+
+ List<Ptg> arrayPtgs = null;
+
+ for (Ptg ptg : ptgs) {
+ ptg.write(out);
+ if (ptg instanceof ArrayPtg) {
+ if (arrayPtgs == null) {
+ arrayPtgs = new ArrayList<>(5);
+ }
+ arrayPtgs.add(ptg);
+ }
+ }
+ if (arrayPtgs != null) {
+ for (Ptg arrayPtg : arrayPtgs) {
+ ArrayPtg p = (ArrayPtg) arrayPtg;
+ p.writeTokenValueBytes(out);
+ }
+ }
+ return out.getWriteIndex() - offset;
+ }
+
+ /**
+ * @return the encoded length of this Ptg, including the initial Ptg type identifier byte.
+ */
+ public abstract int getSize();
+
+ public abstract void write(LittleEndianOutput out);
+
+ /**
+ * return a string representation of this token alone
+ */
+ public abstract String toFormulaString();
+
+ @Override
+ public final String toString() {
+ return GenericRecordJsonWriter.marshal(this);
+ }
+
+ public final void setClass(byte thePtgClass) {
+ if (isBaseToken()) {
+ throw new RuntimeException("setClass should not be called on a base token");
+ }
+ ptgClass = thePtgClass;
+ }
+
+ /**
+ * @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
+ */
+ public final byte getPtgClass() {
+ return ptgClass;
+ }
+
+ /**
+ * Debug / diagnostic method to get this token's 'operand class' type.
+ * @return 'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
+ */
+ public final char getRVAType() {
+ if (isBaseToken()) {
+ return '.';
+ }
+ switch (ptgClass) {
+ case Ptg.CLASS_REF: return 'R';
+ case Ptg.CLASS_VALUE: return 'V';
+ case Ptg.CLASS_ARRAY: return 'A';
+ }
+ throw new RuntimeException("Unknown operand class (" + ptgClass + ")");
+ }
+
+ public abstract byte getDefaultOperandClass();
+
+ /**
+ * @return {@code false} if this token is classified as 'reference', 'value', or 'array'
+ */
+ public abstract boolean isBaseToken();
+
+ public static boolean doesFormulaReferToDeletedCell(Ptg[] ptgs) {
+ for (Ptg ptg : ptgs) {
+ if (isDeletedCellRef(ptg)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isDeletedCellRef(Ptg ptg) {
+ if (ptg == ErrPtg.REF_INVALID) {
+ return true;
+ }
+ if (ptg instanceof DeletedArea3DPtg) {
+ return true;
+ }
+ if (ptg instanceof DeletedRef3DPtg) {
+ return true;
+ }
+ if (ptg instanceof AreaErrPtg) {
+ return true;
+ }
+ return ptg instanceof RefErrorPtg;
+ }
+
+ @Override
+ public abstract Ptg copy();
+
+ /**
+ * @return structure id of the parsed thing, or {@code -1} if the record has no sid
+ */
+ public abstract byte getSid();
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/RangePtg.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/RangePtg.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/RangePtg.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/RangePtg.java Sat May 22 20:56:44 2021
@@ -27,7 +27,7 @@ public final class RangePtg extends Ope
public static final RangePtg instance = new RangePtg();
private RangePtg() {
- // enforce singleton
+ // enforce singleton
}
@Override
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java Sat May 22 20:56:44 2021
@@ -22,41 +22,41 @@ import org.apache.poi.util.LittleEndianI
import org.apache.poi.util.LittleEndianOutput;
abstract class Ref2DPtgBase extends RefPtgBase {
- private static final int SIZE = 5;
+ private static final int SIZE = 5;
- protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
- setRow(row);
- setColumn(column);
- setRowRelative(isRowRelative);
- setColRelative(isColumnRelative);
- }
+ protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
+ setRow(row);
+ setColumn(column);
+ setRowRelative(isRowRelative);
+ setColRelative(isColumnRelative);
+ }
- protected Ref2DPtgBase(Ref2DPtgBase other) {
- super(other);
- }
+ protected Ref2DPtgBase(Ref2DPtgBase other) {
+ super(other);
+ }
- protected Ref2DPtgBase(LittleEndianInput in) {
- readCoordinates(in);
- }
+ protected Ref2DPtgBase(LittleEndianInput in) {
+ readCoordinates(in);
+ }
- protected Ref2DPtgBase(CellReference cr) {
- super(cr);
- }
+ protected Ref2DPtgBase(CellReference cr) {
+ super(cr);
+ }
- @Override
+ @Override
public void write(LittleEndianOutput out) {
- out.writeByte(getSid() + getPtgClass());
- writeCoordinates(out);
- }
+ out.writeByte(getSid() + getPtgClass());
+ writeCoordinates(out);
+ }
- @Override
+ @Override
public final String toFormulaString() {
- return formatReferenceAsString();
- }
+ return formatReferenceAsString();
+ }
- @Override
+ @Override
public final int getSize() {
- return SIZE;
- }
+ return SIZE;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org