Top Description Fields Constructors Methods
org.apache.poi.ss.formula.ptg

public abstract Class Ptg

extends Object
implements Duplicatable, GenericRecord
Class Inheritance
All Implemented Interfaces
org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.common.Duplicatable
Known Direct Subclasses
org.apache.poi.ss.formula.ptg.ScalarConstantPtg, org.apache.poi.ss.formula.ptg.UnknownPtg, org.apache.poi.ss.formula.ptg.ArrayInitialPtg, org.apache.poi.ss.formula.ptg.ArrayPtg, org.apache.poi.ss.formula.ptg.ControlPtg, org.apache.poi.ss.formula.ptg.OperandPtg, org.apache.poi.ss.formula.ptg.OperationPtg
Imports
java.util.ArrayList, .List, org.apache.poi.common.Duplicatable, org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.util.GenericRecordJsonWriter, .LittleEndianByteArrayOutputStream, .LittleEndianInput, .LittleEndianOutput

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

Modifier and TypeField and Description
public static final byte
public static final byte
public static final byte
public static final Ptg[]
private byte

Constructor Summary

AccessConstructor and Description
protected
Ptg()

protected
Ptg(Ptg other)

Method Summary

Modifier and TypeMethod and Description
public abstract Ptg
private static Ptg
private static Ptg
public static Ptg
public static boolean
public abstract byte
public static int

Returns:

the full size taken to encode the specified Ptgs
getEncodedSize
(Ptg[] ptgs)

This method will return the same result as getEncodedSizeWithoutArrayData(Ptg[]) if there are no array tokens present.

public static int

Returns:

the size of the encoded Ptg tokens not including any trailing array data.
getEncodedSizeWithoutArrayData
(Ptg[] ptgs)

Used to calculate value that should be encoded at the start of the encoded Ptg token array;

public final byte

Returns:

the 'operand class' (REF/VALUE/ARRAY) for this Ptg
getPtgClass
()

public final char

Returns:

'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens
getRVAType
()

Debug / diagnostic method to get this token's 'operand class' type.

public abstract byte

Returns:

structure id of the parsed thing, or -1 if the record has no sid
getSid
()

public abstract int

Returns:

the encoded length of this Ptg, including the initial Ptg type identifier byte.
getSize
()

public abstract boolean

Returns:

false if this token is classified as 'reference', 'value', or 'array'
isBaseToken
()

private static boolean
public static Ptg[]
readTokens(int size, LittleEndianInput in)

Reads size bytes of the input stream, to create an array of Ptgs.

public static int

Returns:

number of bytes written
serializePtgs
(Ptg[] ptgs, byte[] array, int offset)

Writes the ptgs to the data buffer, starting at the specified offset.

public final void
setClass(byte thePtgClass)

public abstract String
toFormulaString()

return a string representation of this token alone

private static Ptg[]
public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public abstract void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CLASS_ARRAYback to summary
public static final byte CLASS_ARRAY
CLASS_REFback to summary
public static final byte CLASS_REF
CLASS_VALUEback to summary
public static final byte CLASS_VALUE
EMPTY_PTG_ARRAYback to summary
public static final Ptg[] EMPTY_PTG_ARRAY
ptgClassback to summary
private byte ptgClass

Constructor Detail

Ptgback to summary
protected Ptg()
Ptgback to summary
protected Ptg(Ptg other)

Method Detail

copyback to summary
public abstract Ptg copy()

Redeclares org.apache.poi.common.Duplicatable.copy.

Returns:Ptg

Doc from org.apache.poi.common.Duplicatable.copy.

a deep copy of the implementing class / instance

Annotations
@Override
createBasePtgback to summary
private static Ptg createBasePtg(byte id, LittleEndianInput in)
createClassifiedPtgback to summary
private static Ptg createClassifiedPtg(byte id, LittleEndianInput in)
createPtgback to summary
public static Ptg createPtg(LittleEndianInput in)
doesFormulaReferToDeletedCellback to summary
public static boolean doesFormulaReferToDeletedCell(Ptg[] ptgs)
getDefaultOperandClassback to summary
public abstract byte getDefaultOperandClass()
getEncodedSizeback to summary
public static int getEncodedSize(Ptg[] ptgs)

This method will return the same result as getEncodedSizeWithoutArrayData(Ptg[]) if there are no array tokens present.

Returns:int

the full size taken to encode the specified Ptgs

getEncodedSizeWithoutArrayDataback to summary
public static int getEncodedSizeWithoutArrayData(Ptg[] ptgs)

Used to calculate value that should be encoded at the start of the encoded Ptg token array;

Returns:int

the size of the encoded Ptg tokens not including any trailing array data.

getPtgClassback to summary
public final byte getPtgClass()
Returns:byte

the 'operand class' (REF/VALUE/ARRAY) for this Ptg

getRVATypeback to summary
public final char getRVAType()

Debug / diagnostic method to get this token's 'operand class' type.

Returns:char

'R' for 'reference', 'V' for 'value', 'A' for 'array' and '.' for base tokens

getSidback to summary
public abstract byte getSid()
Returns:byte

structure id of the parsed thing, or -1 if the record has no sid

getSizeback to summary
public abstract int getSize()
Returns:int

the encoded length of this Ptg, including the initial Ptg type identifier byte.

isBaseTokenback to summary
public abstract boolean isBaseToken()
Returns:boolean

false if this token is classified as 'reference', 'value', or 'array'

isDeletedCellRefback to summary
private static boolean isDeletedCellRef(Ptg ptg)
readTokensback to summary
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.

serializePtgsback to summary
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:int

number of bytes written

setClassback to summary
public final void setClass(byte thePtgClass)
toFormulaStringback to summary
public abstract String toFormulaString()

return a string representation of this token alone

toPtgArrayback to summary
private static Ptg[] toPtgArray(List<Ptg> l)
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeback to summary
public abstract void write(LittleEndianOutput out)