Example usage for org.apache.poi.ss.formula.ptg FuncVarPtg create

List of usage examples for org.apache.poi.ss.formula.ptg FuncVarPtg create

Introduction

In this page you can find the example usage for org.apache.poi.ss.formula.ptg FuncVarPtg create.

Prototype

private static FuncVarPtg create(int numArgs, int functionIndex) 

Source Link

Usage

From source file:org.tiefaces.components.websheet.utility.ShiftFormulaUtility.java

License:MIT License

/**
 * Convert ptg.//from   w  w  w.ja va 2 s  .  co m
 *
 * @param ptgs
 *            the ptgs
 * @param position
 *            the position
 * @param shiftFormulaRef
 *            the shift formula ref
 * @param ptg
 *            the ptg
 * @return the ptg[]
 */
private static Ptg[] convertPtg(final Ptg[] ptgs, final int position, final ShiftFormulaRef shiftFormulaRef,
        final Object ptg) {

    byte originalOperandClass = -1;

    if (!((Ptg) ptg).isBaseToken()) {
        originalOperandClass = ((Ptg) ptg).getPtgClass();
    }

    int currentRow;
    currentRow = getFirstSupportedRowNumFromPtg(ptg);
    if ((currentRow >= 0) && shiftFormulaRef.getWatchList().contains(currentRow)) {
        return convertPtgForWatchList(ptgs, position, shiftFormulaRef, ptg, originalOperandClass, currentRow);

    }
    // no need change ptg
    if ((ptg instanceof AttrPtg) && (shiftFormulaRef.getFormulaChanged() > 1)) {
        AttrPtg newPtg = (AttrPtg) ptg;
        if (newPtg.isSum()) {
            FuncVarPtg fptg = FuncVarPtg.create("sum", shiftFormulaRef.getFormulaChanged());
            return singlePtg(fptg, fptg.getPtgClass(), shiftFormulaRef.getFormulaChanged());
        }
    }
    return singlePtg(ptg, originalOperandClass, shiftFormulaRef.getFormulaChanged());

}

From source file:org.tiefaces.components.websheet.utility.ShiftFormulaUtility.java

License:MIT License

/**
 * Single ptg./*from www  .jav a  2  s.  c om*/
 *
 * @param ptg
 *            the ptg
 * @param originalOperandClass
 *            the original operand class
 * @param formulaChanged
 *            the formula changed
 * @return the ptg[]
 */
private static Ptg[] singlePtg(final Object ptg, final byte originalOperandClass, final int formulaChanged) {
    Ptg[] newPtg = new Ptg[1];
    if (originalOperandClass != (-1)) {
        ((Ptg) ptg).setClass(originalOperandClass);
    }
    Object ptgAfter = ptg;
    if (ptg instanceof FuncVarPtg) {
        FuncVarPtg fptg = (FuncVarPtg) ptg;
        if ((formulaChanged > 0) && (fptg.getNumberOfOperands() != formulaChanged)) {
            ptgAfter = FuncVarPtg.create(((FuncVarPtg) ptg).getName(), formulaChanged);
        }
    }
    newPtg[0] = (Ptg) ptgAfter;
    return newPtg;
}