org.apache.poi.hssf.record.formula
Class Ptg

java.lang.Object
  extended by org.apache.poi.hssf.record.formula.Ptg
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ArrayPtg, BoolPtg, ControlPtg, ErrPtg, IntPtg, MissingArgPtg, NumberPtg, OperandPtg, OperationPtg, StringPtg, UnknownPtg

public abstract class Ptg
extends java.lang.Object
implements java.lang.Cloneable

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.

Author:
andy, avik, Jason Height (jheight at chariot dot net dot au)

Field Summary
static byte CLASS_ARRAY
           
static byte CLASS_REF
           
static byte CLASS_VALUE
           
static Ptg[] EMPTY_PTG_ARRAY
           
 
Constructor Summary
Ptg()
           
 
Method Summary
protected  java.lang.Object clone()
           
 Ptg copy()
           
static Ptg createPtg(RecordInputStream in)
           
 byte[] getBytes()
           
abstract  byte getDefaultOperandClass()
           
static int getEncodedSize(Ptg[] ptgs)
          This method will return the same result as getEncodedSizeWithoutArrayData(Ptg[]) if there are no array tokens present.
static int getEncodedSizeWithoutArrayData(Ptg[] ptgs)
          Used to calculate value that should be encoded at the start of the encoded Ptg token array;
 byte getPtgClass()
           
 char getRVAType()
          Debug / diagnostic method to get this token's 'operand class' type.
abstract  int getSize()
           
abstract  boolean isBaseToken()
           
static Ptg[] readTokens(int size, RecordInputStream in)
          Reads size bytes of the input stream, to create an array of Ptgs.
static int serializePtgs(Ptg[] ptgs, byte[] array, int offset)
          Writes the ptgs to the data buffer, starting at the specified offset.
 void setClass(byte thePtgClass)
           
 java.lang.String toDebugString()
          dump a debug representation (hexdump) to a string
abstract  java.lang.String toFormulaString()
          return a string representation of this token alone
 java.lang.String toString()
          Overridden toString method to ensure object hash is not printed.
abstract  void writeBytes(byte[] array, int offset)
          write this Ptg to a byte array
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

public Ptg()
Method Detail

readTokens

public static Ptg[] readTokens(int size,
                               RecordInputStream 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.


createPtg

public static Ptg createPtg(RecordInputStream in)

copy

public final Ptg copy()
Returns:
a distinct copy of this Ptg if the class is mutable, or the same instance if the class is immutable.

clone

protected java.lang.Object clone()
Overrides:
clone in class java.lang.Object

getEncodedSize

public static int getEncodedSize(Ptg[] ptgs)
This method will return the same result as getEncodedSizeWithoutArrayData(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.

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

getSize

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

getBytes

public final byte[] getBytes()
Returns:
the encoded length of this Ptg, not including the initial Ptg type identifier byte.

writeBytes

public abstract void writeBytes(byte[] array,
                                int offset)
write this Ptg to a byte array


toFormulaString

public abstract java.lang.String toFormulaString()
return a string representation of this token alone


toDebugString

public final java.lang.String toDebugString()
dump a debug representation (hexdump) to a string


toString

public java.lang.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

Overrides:
toString in class java.lang.Object

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:
false if this token is classified as 'reference', 'value', or 'array'


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.