📄 ptg.java
字号:
/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.==================================================================== */package org.apache.poi.hssf.record.formula;import java.util.List;import java.util.ArrayList;import java.util.Stack;import org.apache.poi.hssf.model.Workbook;import org.apache.poi.hssf.record.RecordInputStream;/** * * @author andy * @author avik * @author Jason Height (jheight at chariot dot net dot au) */public abstract class Ptg{ /* convert infix order ptg list to rpn order ptg list * @return List ptgs in RPN order * @param infixPtgs List of ptgs in infix order */ /* DO NOT REMOVE *we keep this method in case we wish to change the way we parse *It needs a getPrecedence in OperationsPtg public static List ptgsToRpn(List infixPtgs) { java.util.Stack operands = new java.util.Stack(); java.util.List retval = new java.util.Stack(); java.util.ListIterator i = infixPtgs.listIterator(); Object p; OperationPtg o ; boolean weHaveABracket = false; while (i.hasNext()) { p=i.next(); if (p instanceof OperationPtg) { if (p instanceof ParenthesisPtg) { if (!weHaveABracket) { operands.push(p); weHaveABracket = true; } else { o = (OperationPtg) operands.pop(); while (!(o instanceof ParenthesisPtg)) { retval.add(o); } weHaveABracket = false; } } else { while (!operands.isEmpty() && ((OperationPtg) operands.peek()).getPrecedence() >= ((OperationPtg) p).getPrecedence() ) { //TODO handle ^ since it is right associative retval.add(operands.pop()); } operands.push(p); } } else { retval.add(p); } } while (!operands.isEmpty()) { if (operands.peek() instanceof ParenthesisPtg ){ //throw some error } else { retval.add(operands.pop()); } } return retval; } */ public static Stack createParsedExpressionTokens(short size, RecordInputStream in ) { Stack stack = new Stack(); int pos = 0; List arrayPtgs = null; while ( pos < size ) { Ptg ptg = Ptg.createPtg( in ); if (ptg instanceof ArrayPtg) { if (arrayPtgs == null) arrayPtgs = new ArrayList(5); arrayPtgs.add(ptg); pos += 8; } else pos += ptg.getSize(); stack.push( ptg ); } if (arrayPtgs != null) { for (int i=0;i<arrayPtgs.size();i++) { ArrayPtg p = (ArrayPtg)arrayPtgs.get(i); p.readTokenValues(in); } } return stack; } public static Ptg createPtg(RecordInputStream in) { byte id = in.readByte(); Ptg retval = null; switch (id) { case ExpPtg.sid : // 0x01 retval = new ExpPtg(in); break; case AddPtg.sid : // 0x03 retval = new AddPtg(in); break; case SubtractPtg.sid : // 0x04 retval = new SubtractPtg(in); break; case MultiplyPtg.sid : // 0x05 retval = new MultiplyPtg(in); break; case DividePtg.sid : // 0x06 retval = new DividePtg(in); break; case PowerPtg.sid : // 0x07 retval = new PowerPtg(in); break; case ConcatPtg.sid : // 0x08 retval = new ConcatPtg(in); break; case LessThanPtg.sid: // 0x09 retval = new LessThanPtg(in); break; case LessEqualPtg.sid : // 0x0a retval = new LessEqualPtg(in); break; case EqualPtg.sid : // 0x0b retval = new EqualPtg(in); break; case GreaterEqualPtg.sid : // 0x0c retval = new GreaterEqualPtg(in); break; case GreaterThanPtg.sid : // 0x0d retval = new GreaterThanPtg(in); break; case NotEqualPtg.sid : // 0x0e retval = new NotEqualPtg(in); break; case IntersectionPtg.sid : // 0x0f retval = new IntersectionPtg(in); break; case UnionPtg.sid : // 0x10 retval = new UnionPtg(in); break; case RangePtg.sid : // 0x11 retval = new RangePtg(in); break; case UnaryPlusPtg.sid : // 0x12 retval = new UnaryPlusPtg(in); break; case UnaryMinusPtg.sid : // 0x13 retval = new UnaryMinusPtg(in); break; case PercentPtg.sid : // 0x14 retval = new PercentPtg(in); break; case ParenthesisPtg.sid : // 0x15 retval = new ParenthesisPtg(in); break; case MissingArgPtg.sid : // 0x16 retval = new MissingArgPtg(in); break; case StringPtg.sid : // 0x17 retval = new StringPtg(in); break; case AttrPtg.sid : // 0x19 retval = new AttrPtg(in); break; case ErrPtg.sid : // 0x1c retval = new ErrPtg(in); break; case BoolPtg.sid : // 0x1d retval = new BoolPtg(in); break; case IntPtg.sid : // 0x1e retval = new IntPtg(in); break; case NumberPtg.sid : // 0x1f retval = new NumberPtg(in); break; case ArrayPtg.sid : // 0x20 retval = new ArrayPtg(in); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -