Package org.apache.poi.ss.formula.ptg
Class Ptg
java.lang.Object
org.apache.poi.ss.formula.ptg.Ptg
- All Implemented Interfaces:
org.apache.poi.common.Duplicatable,GenericRecord
- Direct Known Subclasses:
ArrayPtg,ControlPtg,OperandPtg,OperationPtg,ScalarConstantPtg,UnknownPtg
public abstract class Ptg
extends Object
implements org.apache.poi.common.Duplicatable, GenericRecord
Ptg represents 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, Ptg encapsulates
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 files Ptgs are written/read in
Reverse-Polish Notation order. The RPN ordering also simplifies formula
evaluation logic, so POI mostly accesses Ptgs in the same way.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytestatic final bytestatic final bytestatic final Ptg[] -
Method Summary
Modifier and TypeMethodDescriptionabstract Ptgcopy()static Ptgstatic booleandoesFormulaReferToDeletedCell(Ptg[] ptgs) abstract bytestatic intgetEncodedSize(Ptg[] ptgs) 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;final bytefinal charDebug / diagnostic method to get this token's 'operand class' type.abstract bytegetSid()abstract intgetSize()abstract booleanstatic Ptg[]readTokens(int size, LittleEndianInput in) Readssizebytes of the input stream, to create an array ofPtgs.static intserializePtgs(Ptg[] ptgs, byte[] array, int offset) Writes the ptgs to the data buffer, starting at the specified offset.final voidsetClass(byte thePtgClass) abstract Stringreturn a string representation of this token alonefinal StringtoString()abstract voidwrite(LittleEndianOutput out) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.poi.common.usermodel.GenericRecord
getGenericChildren, getGenericProperties, getGenericRecordType
-
Field Details
-
EMPTY_PTG_ARRAY
-
CLASS_REF
public static final byte CLASS_REF- See Also:
-
CLASS_VALUE
public static final byte CLASS_VALUE- See Also:
-
CLASS_ARRAY
public static final byte CLASS_ARRAY- See Also:
-
-
Method Details
-
readTokens
Readssizebytes of the input stream, to create an array ofPtgs. Extra data (beyondsize) may be read if andArrayPtgs are present. -
createPtg
-
getEncodedSize
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
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.
-
serializePtgs
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
-
getSize
public abstract int getSize()- Returns:
- the encoded length of this Ptg, including the initial Ptg type identifier byte.
-
write
-
toFormulaString
return a string representation of this token alone -
toString
-
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
-
copy
- Specified by:
copyin interfaceorg.apache.poi.common.Duplicatable
-
getSid
public abstract byte getSid()- Returns:
- structure id of the parsed thing, or
-1if the record has no sid
-