Class Ptg

  • Direct Known Subclasses:
    ArrayPtg, ControlPtg, OperandPtg, OperationPtg, ScalarConstantPtg, UnknownPtg

    public abstract class Ptg
    extends Object
    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.

    • Constructor Detail

      • Ptg

        public Ptg()
    • Method Detail

      • readTokens

        public static Ptg[] readTokens​(int size,
                                       LittleEndianInput in)
        Reads size bytes of the input stream, to create an array of Ptgs. Extra data (beyond size) may be read if and ArrayPtgs are present.
      • getEncodedSize

        public static int getEncodedSize​(Ptg[] ptgs)
        This method will return the same result as getEncodedSizeWithoutArrayData(Ptg[]) if there are no array tokens present.
        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;
        the size of the encoded Ptg tokens not including any trailing array data.
      • 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.
        number of bytes written
      • getSize

        public abstract int getSize()
        the encoded length of this Ptg, including the initial Ptg type identifier byte.
      • toFormulaString

        public abstract String toFormulaString()
        return a string representation of this token alone
      • toString

        public String toString()
        Overridden toString method to ensure object hash is not printed. This helps get rid of gratuitous diffs when comparing two dumps Subclasses may output more relevant information by overriding this method
        toString in class Object
      • setClass

        public final void setClass​(byte thePtgClass)
      • getPtgClass

        public final byte getPtgClass()
        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.
        'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
      • getDefaultOperandClass

        public abstract byte getDefaultOperandClass()
      • isBaseToken

        public abstract boolean isBaseToken()
        false if this token is classified as 'reference', 'value', or 'array'
      • doesFormulaReferToDeletedCell

        public static boolean doesFormulaReferToDeletedCell​(Ptg[] ptgs)