Package org.apache.poi.ss.formula.ptg
Class Ptg
- java.lang.Object
-
- org.apache.poi.ss.formula.ptg.Ptg
-
- All Implemented Interfaces:
Serializable,Duplicatable,GenericRecord
- Direct Known Subclasses:
ArrayPtg,ControlPtg,OperandPtg,OperationPtg,ScalarConstantPtg,UnknownPtg
public abstract class Ptg extends Object implements Duplicatable, GenericRecord, Serializable
Ptgrepresents a syntactic token in a formula. 'PTG' is an acronym for 'parse thing'. Originally, the name referred to the single byte identifier at the start of the token, but in POI,Ptgencapsulates the whole formula token (initial byte + value data).Ptgs are logically arranged in a tree representing the structure of the parsed formula. However, in BIFF filesPtgs are written/read in Reverse-Polish Notation order. The RPN ordering also simplifies formula evaluation logic, so POI mostly accessesPtgs in the same way.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static byteCLASS_ARRAYstatic byteCLASS_REFstatic byteCLASS_VALUEstatic Ptg[]EMPTY_PTG_ARRAY
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Ptgcopy()static PtgcreatePtg(LittleEndianInput in)static PtgcreatePtg(LittleEndianInput in, SpreadsheetVersion version)static booleandoesFormulaReferToDeletedCell(Ptg[] ptgs)abstract bytegetDefaultOperandClass()static intgetEncodedSize(Ptg[] ptgs)This method will return the same result asgetEncodedSizeWithoutArrayData(Ptg[])if there are no array tokens present.static intgetEncodedSize(Ptg[] ptgs, SpreadsheetVersion version)This method will return the same result asgetEncodedSizeWithoutArrayData(Ptg[])if there are no array tokens present.static intgetEncodedSizeWithoutArrayData(Ptg[] ptgs)Used to calculate value that should be encoded at the start of the encoded Ptg token array;static intgetEncodedSizeWithoutArrayData(Ptg[] ptgs, SpreadsheetVersion version)bytegetPtgClass()chargetRVAType()Debug / diagnostic method to get this token's 'operand class' type.abstract bytegetSid()abstract intgetSize(SpreadsheetVersion version)abstract booleanisBaseToken()static Ptg[]readTokens(int size, LittleEndianInput in)Readssizebytes of the input stream, to create an array ofPtgs.static Ptg[]readTokens(int size, LittleEndianInput in, SpreadsheetVersion version)static intserializePtgs(Ptg[] ptgs, byte[] array, int offset)Writes the ptgs to the data buffer, starting at the specified offset.static intserializePtgs(Ptg[] ptgs, byte[] array, int offset, SpreadsheetVersion version)voidsetClass(byte thePtgClass)abstract StringtoFormulaString()return a string representation of this token aloneStringtoString()abstract voidwrite(LittleEndianOutput out, SpreadsheetVersion version)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.poi.common.usermodel.GenericRecord
getGenericChildren, getGenericProperties, getGenericRecordType
-
-
-
-
Field Detail
-
EMPTY_PTG_ARRAY
public static final Ptg[] EMPTY_PTG_ARRAY
-
CLASS_REF
public static final byte CLASS_REF
- See Also:
- Constant Field Values
-
CLASS_VALUE
public static final byte CLASS_VALUE
- See Also:
- Constant Field Values
-
CLASS_ARRAY
public static final byte CLASS_ARRAY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Ptg
protected Ptg()
-
Ptg
protected Ptg(Ptg other)
-
-
Method Detail
-
readTokens
public static Ptg[] readTokens(int size, LittleEndianInput in)
Readssizebytes of the input stream, to create an array ofPtgs. Extra data (beyondsize) may be read if andArrayPtgs are present.
-
readTokens
public static Ptg[] readTokens(int size, LittleEndianInput in, SpreadsheetVersion version)
-
createPtg
public static Ptg createPtg(LittleEndianInput in)
-
createPtg
public static Ptg createPtg(LittleEndianInput in, SpreadsheetVersion version)
-
getEncodedSize
public static int getEncodedSize(Ptg[] ptgs)
This method will return the same result asgetEncodedSizeWithoutArrayData(Ptg[])if there are no array tokens present.- Returns:
- the full size taken to encode the specified
Ptgs
-
getEncodedSize
public static int getEncodedSize(Ptg[] ptgs, SpreadsheetVersion version)
This method will return the same result asgetEncodedSizeWithoutArrayData(Ptg[])if there are no array tokens present.- Returns:
- the full size taken to encode the specified
Ptgs
-
getEncodedSizeWithoutArrayData
public static int getEncodedSizeWithoutArrayData(Ptg[] ptgs)
Used to calculate value that should be encoded at the start of the encoded Ptg token array;- Returns:
- the size of the encoded Ptg tokens not including any trailing array data.
-
getEncodedSizeWithoutArrayData
public static int getEncodedSizeWithoutArrayData(Ptg[] ptgs, SpreadsheetVersion version)
-
serializePtgs
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset)
Writes the ptgs to the data buffer, starting at the specified offset.
The 2 byte encode length field is not written by this method.- Returns:
- number of bytes written
-
serializePtgs
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset, SpreadsheetVersion version)
-
getSize
public abstract int getSize(SpreadsheetVersion version)
- Returns:
- the encoded length of this Ptg, including the initial Ptg type identifier byte.
-
write
public abstract void write(LittleEndianOutput out, SpreadsheetVersion version)
-
toFormulaString
public abstract String toFormulaString()
return a string representation of this token alone
-
setClass
public final void setClass(byte thePtgClass)
-
getPtgClass
public final byte getPtgClass()
- Returns:
- the 'operand class' (REF/VALUE/ARRAY) for this Ptg
-
getRVAType
public final char getRVAType()
Debug / diagnostic method to get this token's 'operand class' type.- Returns:
- 'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
-
getDefaultOperandClass
public abstract byte getDefaultOperandClass()
-
isBaseToken
public abstract boolean isBaseToken()
- Returns:
falseif this token is classified as 'reference', 'value', or 'array'
-
doesFormulaReferToDeletedCell
public static boolean doesFormulaReferToDeletedCell(Ptg[] ptgs)
-
copy
public abstract Ptg copy()
- Specified by:
copyin interfaceDuplicatable- Returns:
- a deep copy of the implementing class / instance
-
getSid
public abstract byte getSid()
- Returns:
- structure id of the parsed thing, or
-1if the record has no sid
-
-