From d6a97ce38d1fe4f266949110b76b38741149f2c3 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 16 Aug 2020 16:54:25 +0000 Subject: [PATCH] #64036 - Replace reflection calls in factories for Java 9+ removed some unnecessary reflection calls OperationEvaluatorFactory git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880903 13f79535-47bb-0310-9956-ffa450edef68 --- .../ss/formula/OperationEvaluatorFactory.java | 85 ++++++++----------- .../org/apache/poi/ss/formula/ptg/AddPtg.java | 12 +-- .../poi/ss/formula/ptg/Area2DPtgBase.java | 2 - .../apache/poi/ss/formula/ptg/Area3DPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/Area3DPxg.java | 5 ++ .../apache/poi/ss/formula/ptg/AreaErrPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/AreaNPtg.java | 3 +- .../apache/poi/ss/formula/ptg/AreaPtg.java | 2 +- .../poi/ss/formula/ptg/ArrayInitialPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/ArrayPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/AttrPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/BoolPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/ConcatPtg.java | 12 +-- .../poi/ss/formula/ptg/Deleted3DPxg.java | 6 ++ .../poi/ss/formula/ptg/DeletedArea3DPtg.java | 6 ++ .../poi/ss/formula/ptg/DeletedRef3DPtg.java | 6 ++ .../apache/poi/ss/formula/ptg/DividePtg.java | 12 +-- .../apache/poi/ss/formula/ptg/EqualPtg.java | 13 +-- .../org/apache/poi/ss/formula/ptg/ErrPtg.java | 5 ++ .../org/apache/poi/ss/formula/ptg/ExpPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/FuncPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/FuncVarPtg.java | 5 ++ .../poi/ss/formula/ptg/GreaterEqualPtg.java | 14 +-- .../poi/ss/formula/ptg/GreaterThanPtg.java | 15 ++-- .../org/apache/poi/ss/formula/ptg/IntPtg.java | 5 ++ .../poi/ss/formula/ptg/IntersectionPtg.java | 12 +-- .../poi/ss/formula/ptg/LessEqualPtg.java | 11 +-- .../poi/ss/formula/ptg/LessThanPtg.java | 14 ++- .../apache/poi/ss/formula/ptg/MemAreaPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/MemErrPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/MemFuncPtg.java | 5 ++ .../poi/ss/formula/ptg/MissingArgPtg.java | 5 ++ .../poi/ss/formula/ptg/MultiplyPtg.java | 12 +-- .../apache/poi/ss/formula/ptg/NamePtg.java | 5 ++ .../apache/poi/ss/formula/ptg/NameXPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/NameXPxg.java | 5 ++ .../poi/ss/formula/ptg/NotEqualPtg.java | 14 +-- .../apache/poi/ss/formula/ptg/NumberPtg.java | 5 ++ .../poi/ss/formula/ptg/ParenthesisPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/PercentPtg.java | 11 +-- .../apache/poi/ss/formula/ptg/PowerPtg.java | 13 +-- .../org/apache/poi/ss/formula/ptg/Ptg.java | 5 ++ .../apache/poi/ss/formula/ptg/RangePtg.java | 18 ++-- .../poi/ss/formula/ptg/Ref2DPtgBase.java | 2 - .../apache/poi/ss/formula/ptg/Ref3DPtg.java | 5 ++ .../apache/poi/ss/formula/ptg/Ref3DPxg.java | 5 ++ .../poi/ss/formula/ptg/RefErrorPtg.java | 8 +- .../apache/poi/ss/formula/ptg/RefNPtg.java | 7 +- .../org/apache/poi/ss/formula/ptg/RefPtg.java | 3 +- .../apache/poi/ss/formula/ptg/StringPtg.java | 5 ++ .../poi/ss/formula/ptg/SubtractPtg.java | 12 +-- .../org/apache/poi/ss/formula/ptg/TblPtg.java | 5 ++ .../poi/ss/formula/ptg/UnaryMinusPtg.java | 10 +-- .../poi/ss/formula/ptg/UnaryPlusPtg.java | 10 +-- .../apache/poi/ss/formula/ptg/UnionPtg.java | 18 ++-- .../apache/poi/ss/formula/ptg/UnknownPtg.java | 7 +- .../poi/ss/formula/ptg/ValueOperatorPtg.java | 2 - .../formula/ptg/TestAbstractFunctionPtg.java | 5 ++ 58 files changed, 294 insertions(+), 213 deletions(-) diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java b/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java index 65676a61fd..ca10b13075 100644 --- a/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java +++ b/src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java @@ -17,12 +17,24 @@ package org.apache.poi.ss.formula; -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Map; +import org.apache.poi.ss.formula.eval.ConcatEval; +import org.apache.poi.ss.formula.eval.FunctionEval; +import org.apache.poi.ss.formula.eval.IntersectionEval; +import org.apache.poi.ss.formula.eval.PercentEval; +import org.apache.poi.ss.formula.eval.RangeEval; +import org.apache.poi.ss.formula.eval.RelationalOperationEval; +import org.apache.poi.ss.formula.eval.TwoOperandNumericOperation; +import org.apache.poi.ss.formula.eval.UnaryMinusEval; +import org.apache.poi.ss.formula.eval.UnaryPlusEval; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; +import org.apache.poi.ss.formula.functions.ArrayFunction; import org.apache.poi.ss.formula.functions.FreeRefFunction; +import org.apache.poi.ss.formula.functions.Function; +import org.apache.poi.ss.formula.functions.Indirect; import org.apache.poi.ss.formula.ptg.AbstractFunctionPtg; import org.apache.poi.ss.formula.ptg.AddPtg; import org.apache.poi.ss.formula.ptg.ConcatPtg; @@ -42,20 +54,6 @@ import org.apache.poi.ss.formula.ptg.RangePtg; import org.apache.poi.ss.formula.ptg.SubtractPtg; import org.apache.poi.ss.formula.ptg.UnaryMinusPtg; import org.apache.poi.ss.formula.ptg.UnaryPlusPtg; -import org.apache.poi.ss.formula.eval.ConcatEval; -import org.apache.poi.ss.formula.eval.FunctionEval; -import org.apache.poi.ss.formula.eval.IntersectionEval; -import org.apache.poi.ss.formula.eval.PercentEval; -import org.apache.poi.ss.formula.eval.RangeEval; -import org.apache.poi.ss.formula.eval.RelationalOperationEval; -import org.apache.poi.ss.formula.eval.TwoOperandNumericOperation; -import org.apache.poi.ss.formula.eval.UnaryMinusEval; -import org.apache.poi.ss.formula.eval.UnaryPlusEval; -import org.apache.poi.ss.formula.eval.ValueEval; -import org.apache.poi.ss.formula.function.FunctionMetadataRegistry; -import org.apache.poi.ss.formula.functions.ArrayFunction; -import org.apache.poi.ss.formula.functions.Function; -import org.apache.poi.ss.formula.functions.Indirect; import org.apache.poi.ss.util.CellRangeAddress; /** @@ -66,47 +64,36 @@ import org.apache.poi.ss.util.CellRangeAddress; */ final class OperationEvaluatorFactory { - private static final Map _instancesByPtgClass = initialiseInstancesMap(); + private static final Map _instancesByPtgClass = initialiseInstancesMap(); private OperationEvaluatorFactory() { // no instances of this class } - private static Map initialiseInstancesMap() { - Map m = new HashMap<>(32); + private static Map initialiseInstancesMap() { + Map m = new HashMap<>(32); - put(m, EqualPtg.instance, RelationalOperationEval.EqualEval); - put(m, GreaterEqualPtg.instance, RelationalOperationEval.GreaterEqualEval); - put(m, GreaterThanPtg.instance, RelationalOperationEval.GreaterThanEval); - put(m, LessEqualPtg.instance, RelationalOperationEval.LessEqualEval); - put(m, LessThanPtg.instance, RelationalOperationEval.LessThanEval); - put(m, NotEqualPtg.instance, RelationalOperationEval.NotEqualEval); + m.put(AddPtg.instance.getSid(), TwoOperandNumericOperation.AddEval); // 0x03 + m.put(SubtractPtg.instance.getSid(), TwoOperandNumericOperation.SubtractEval); // 0x04 + m.put(MultiplyPtg.instance.getSid(), TwoOperandNumericOperation.MultiplyEval); // 0x05 + m.put(DividePtg.instance.getSid(), TwoOperandNumericOperation.DivideEval); // 0x06 + m.put(PowerPtg.instance.getSid(), TwoOperandNumericOperation.PowerEval); // 0x07 + m.put(ConcatPtg.instance.getSid(), ConcatEval.instance); // 0x08 + m.put(LessThanPtg.instance.getSid(), RelationalOperationEval.LessThanEval); // 0x09 + m.put(LessEqualPtg.instance.getSid(), RelationalOperationEval.LessEqualEval); // 0x0a + m.put(EqualPtg.instance.getSid(), RelationalOperationEval.EqualEval); // 0x0b + m.put(GreaterEqualPtg.instance.getSid(), RelationalOperationEval.GreaterEqualEval); // 0x0c + m.put(GreaterThanPtg.instance.getSid(), RelationalOperationEval.GreaterThanEval); // 0x0D + m.put(NotEqualPtg.instance.getSid(), RelationalOperationEval.NotEqualEval); // 0x0e + m.put(IntersectionPtg.instance.getSid(), IntersectionEval.instance); // 0x0f + m.put(RangePtg.instance.getSid(), RangeEval.instance); // 0x11 + m.put(UnaryPlusPtg.instance.getSid(), UnaryPlusEval.instance); // 0x12 + m.put(UnaryMinusPtg.instance.getSid(), UnaryMinusEval.instance); // 0x13 + m.put(PercentPtg.instance.getSid(), PercentEval.instance); // 0x14 - put(m, ConcatPtg.instance, ConcatEval.instance); - put(m, AddPtg.instance, TwoOperandNumericOperation.AddEval); - put(m, DividePtg.instance, TwoOperandNumericOperation.DivideEval); - put(m, MultiplyPtg.instance, TwoOperandNumericOperation.MultiplyEval); - put(m, PercentPtg.instance, PercentEval.instance); - put(m, PowerPtg.instance, TwoOperandNumericOperation.PowerEval); - put(m, SubtractPtg.instance, TwoOperandNumericOperation.SubtractEval); - put(m, UnaryMinusPtg.instance, UnaryMinusEval.instance); - put(m, UnaryPlusPtg.instance, UnaryPlusEval.instance); - put(m, RangePtg.instance, RangeEval.instance); - put(m, IntersectionPtg.instance, IntersectionEval.instance); return m; } - private static void put(Map m, OperationPtg ptgKey, - Function instance) { - // make sure ptg has single private constructor because map lookups assume singleton keys - Constructor[] cc = ptgKey.getClass().getDeclaredConstructors(); - if (cc.length > 1 || !Modifier.isPrivate(cc[0].getModifiers())) { - throw new RuntimeException("Failed to verify instance (" - + ptgKey.getClass().getName() + ") is a singleton."); - } - m.put(ptgKey, instance); - } - /** * returns the OperationEval concrete impl instance corresponding * to the supplied operationPtg @@ -116,7 +103,7 @@ final class OperationEvaluatorFactory { if(ptg == null) { throw new IllegalArgumentException("ptg must not be null"); } - Function result = _instancesByPtgClass.get(ptg); + Function result = _instancesByPtgClass.get(ptg.getSid()); FreeRefFunction udfFunc = null; if (result == null) { if (ptg instanceof AbstractFunctionPtg) { @@ -149,7 +136,7 @@ final class OperationEvaluatorFactory { return func.evaluateArray(args, ec.getRowIndex(), ec.getColumnIndex()); } } - + return result.evaluate(args, ec.getRowIndex(), ec.getColumnIndex()); } else if (udfFunc != null){ return udfFunc.evaluate(args, ec); diff --git a/src/java/org/apache/poi/ss/formula/ptg/AddPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AddPtg.java index aedc6dd86f..717a39010b 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AddPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AddPtg.java @@ -31,8 +31,9 @@ public final class AddPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -41,12 +42,7 @@ public final class AddPtg extends ValueOperatorPtg { /** implementation of method from OperationsPtg*/ public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(ADD); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + ADD + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/Area2DPtgBase.java b/src/java/org/apache/poi/ss/formula/ptg/Area2DPtgBase.java index f43a288a64..ccfd9c76cf 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Area2DPtgBase.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Area2DPtgBase.java @@ -43,8 +43,6 @@ public abstract class Area2DPtgBase extends AreaPtgBase { readCoordinates(in); } - protected abstract byte getSid(); - public final void write(LittleEndianOutput out) { out.writeByte(getSid() + getPtgClass()); writeCoordinates(out); diff --git a/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java b/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java index 31a08f46b1..9a21b60660 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java @@ -77,6 +77,11 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor writeCoordinates(out); } + @Override + public byte getSid() { + return sid; + } + @Override public int getSize() { return SIZE; diff --git a/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java b/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java index e86df93a84..729fc0e742 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java @@ -99,6 +99,11 @@ public final class Area3DPxg extends AreaPtgBase implements Pxg3D { return sb.toString(); } + @Override + public byte getSid() { + return -1; + } + public int getSize() { return 1; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java index dba6c16f51..4a9a041e54 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java @@ -58,6 +58,11 @@ public final class AreaErrPtg extends OperandPtg { return Ptg.CLASS_REF; } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 9; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaNPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AreaNPtg.java index 0c0faca505..1627704dfe 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaNPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaNPtg.java @@ -34,7 +34,8 @@ public final class AreaNPtg extends Area2DPtgBase { super(in); } - protected byte getSid() { + @Override + public byte getSid() { return sid; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java index ca711e6f06..0ee4c0292e 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java @@ -43,7 +43,7 @@ public final class AreaPtg extends Area2DPtgBase { } @Override - protected byte getSid() { + public byte getSid() { return sid; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ArrayInitialPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ArrayInitialPtg.java index bfd3b8d0a9..f242fb2b39 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ArrayInitialPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ArrayInitialPtg.java @@ -95,4 +95,9 @@ final class ArrayInitialPtg extends Ptg { "reserved2", () -> _reserved2 ); } + + @Override + public byte getSid() { + return -1; + } } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java index fd6d932e74..aff4aa3918 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java @@ -164,6 +164,11 @@ public final class ArrayPtg extends Ptg { + ConstantValueParser.getEncodedSize(_arrayValues); } + @Override + public byte getSid() { + return sid; + } + public String toFormulaString() { StringBuilder b = new StringBuilder(); b.append("{"); diff --git a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java index e1fe9ab49d..16dc206dbb 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java @@ -186,6 +186,11 @@ public final class AttrPtg extends ControlPtg { } } + @Override + public byte getSid() { + return sid; + } + public int getSize() { if (_jumpTable != null) { return SIZE + (_jumpTable.length + 1) * LittleEndianConsts.SHORT_SIZE; diff --git a/src/java/org/apache/poi/ss/formula/ptg/BoolPtg.java b/src/java/org/apache/poi/ss/formula/ptg/BoolPtg.java index 467eb67473..a94986f7fe 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/BoolPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/BoolPtg.java @@ -56,6 +56,11 @@ public final class BoolPtg extends ScalarConstantPtg { out.writeByte(_value ? 1 : 0); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java index 91d0840d3c..bedcb94162 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java @@ -28,8 +28,9 @@ public final class ConcatPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -37,12 +38,7 @@ public final class ConcatPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(CONCAT); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + CONCAT + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java b/src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java index 26701d06ad..b58b8e5298 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java @@ -78,9 +78,15 @@ public final class Deleted3DPxg extends OperandPtg implements Pxg { return Ptg.CLASS_VALUE; } + @Override + public byte getSid() { + return -1; + } + public int getSize() { return 1; } + public void write(LittleEndianOutput out) { throw new IllegalStateException("XSSF-only Ptg, should not be serialised"); } diff --git a/src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java b/src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java index 679b430476..023bc8d920 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java @@ -59,6 +59,12 @@ public final class DeletedArea3DPtg extends OperandPtg implements WorkbookDepend public byte getDefaultOperandClass() { return Ptg.CLASS_REF; } + + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 11; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java b/src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java index cca55f5e00..ea2805203c 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java @@ -59,6 +59,12 @@ public final class DeletedRef3DPtg extends OperandPtg implements WorkbookDepende public byte getDefaultOperandClass() { return Ptg.CLASS_REF; } + + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 7; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/DividePtg.java b/src/java/org/apache/poi/ss/formula/ptg/DividePtg.java index d2b11921a6..f53cb09ebd 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/DividePtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/DividePtg.java @@ -29,8 +29,9 @@ public final class DividePtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -38,12 +39,7 @@ public final class DividePtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append("/"); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + "/" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java b/src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java index 99961e3eda..596be4912c 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java @@ -30,8 +30,9 @@ public final class EqualPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -39,13 +40,7 @@ public final class EqualPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - - buffer.append(operands[ 0 ]); - buffer.append("="); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + "=" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java index 708ff30733..6cb5d41803 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java @@ -69,6 +69,11 @@ public final class ErrPtg extends ScalarConstantPtg { return FormulaError.forInt(field_1_error_code).getString(); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ExpPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ExpPtg.java index e63f6cdf7d..93249caa39 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ExpPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ExpPtg.java @@ -48,6 +48,11 @@ public final class ExpPtg extends ControlPtg { out.writeShort(field_2_first_col); } + @Override + public byte getSid() { + return sid; + } + @Override public int getSize() { return SIZE; diff --git a/src/java/org/apache/poi/ss/formula/ptg/FuncPtg.java b/src/java/org/apache/poi/ss/formula/ptg/FuncPtg.java index 6fc76a5815..4b01512aac 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/FuncPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/FuncPtg.java @@ -49,6 +49,11 @@ public final class FuncPtg extends AbstractFunctionPtg { out.writeShort(getFunctionIndex()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/FuncVarPtg.java b/src/java/org/apache/poi/ss/formula/ptg/FuncVarPtg.java index 1445aeb0d7..398ec47b05 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/FuncVarPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/FuncVarPtg.java @@ -88,6 +88,11 @@ public final class FuncVarPtg extends AbstractFunctionPtg { out.writeShort(getFunctionIndex()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java b/src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java index c89d1c8876..513a537dec 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java @@ -31,8 +31,9 @@ public final class GreaterEqualPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -40,14 +41,7 @@ public final class GreaterEqualPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - - buffer.append(">="); - buffer.append(operands[ 1 ]); - - return buffer.toString(); + return operands[0] + ">=" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java b/src/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java index 307fb6eee7..98a8c2fea8 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java @@ -31,8 +31,9 @@ public final class GreaterThanPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } /** @@ -48,14 +49,8 @@ public final class GreaterThanPtg extends ValueOperatorPtg { * @param operands a String array of operands * @return String the Formula as a String */ - public String toFormulaString(String[] operands) - { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(GREATERTHAN); - buffer.append(operands[ 1 ]); - return buffer.toString(); + public String toFormulaString(String[] operands) { + return operands[0] + GREATERTHAN + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/IntPtg.java b/src/java/org/apache/poi/ss/formula/ptg/IntPtg.java index 6f214532cf..230883e9e2 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/IntPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/IntPtg.java @@ -66,6 +66,11 @@ public final class IntPtg extends ScalarConstantPtg { out.writeShort(getValue()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java b/src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java index 9a641654fa..abad733c4e 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java @@ -32,6 +32,11 @@ public final class IntersectionPtg extends OperationPtg { return true; } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 1; } @@ -45,12 +50,7 @@ public final class IntersectionPtg extends OperationPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[0]); - buffer.append(" "); - buffer.append(operands[1]); - return buffer.toString(); + return operands[0] + " " + operands[1]; } public int getNumberOfOperands() { diff --git a/src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java b/src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java index d7aa350c63..d94206a39c 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java @@ -33,8 +33,9 @@ public final class LessEqualPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -42,11 +43,7 @@ public final class LessEqualPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - buffer.append( operands[0] ); - buffer.append("<="); - buffer.append( operands[1] ); - return buffer.toString(); + return operands[0] + "<=" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java b/src/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java index f98b215cd8..74ed426f8f 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java @@ -35,8 +35,9 @@ public final class LessThanPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } /** @@ -52,13 +53,8 @@ public final class LessThanPtg extends ValueOperatorPtg { * @param operands a String array of operands * @return String the Formula as a String */ - public String toFormulaString(String[] operands) - { - StringBuilder buffer = new StringBuilder(); - buffer.append(operands[ 0 ]); - buffer.append(LESSTHAN); - buffer.append(operands[ 1 ]); - return buffer.toString(); + public String toFormulaString(String[] operands) { + return operands[0] + LESSTHAN + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java b/src/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java index 2797a20cec..f1eb6d0b8a 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java @@ -52,6 +52,11 @@ public final class MemAreaPtg extends OperandPtg { out.writeShort(field_2_subex_len); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java b/src/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java index 4d0ee89ca1..2f70c197fc 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java @@ -47,6 +47,11 @@ public final class MemErrPtg extends OperandPtg { out.writeShort(field_2_subex_len); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java b/src/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java index 7cc9532dcb..532e66c5c2 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java @@ -41,6 +41,11 @@ public final class MemFuncPtg extends OperandPtg { field_1_len_ref_subexpression = subExprLen; } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 3; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java b/src/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java index b1505dc09c..e474aabf37 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java @@ -40,6 +40,11 @@ public final class MissingArgPtg extends ScalarConstantPtg { out.writeByte(sid + getPtgClass()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java b/src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java index c99e90318a..d6dc2e2016 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java @@ -29,8 +29,9 @@ public final class MultiplyPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -38,12 +39,7 @@ public final class MultiplyPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append("*"); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + "*" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/NamePtg.java b/src/java/org/apache/poi/ss/formula/ptg/NamePtg.java index a3520b4108..8084fa4337 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/NamePtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/NamePtg.java @@ -70,6 +70,11 @@ public final class NamePtg extends OperandPtg implements WorkbookDependentFormul out.writeShort(field_2_zero); } + @Override + public byte getSid() { + return sid; + } + @Override public int getSize() { return SIZE; diff --git a/src/java/org/apache/poi/ss/formula/ptg/NameXPtg.java b/src/java/org/apache/poi/ss/formula/ptg/NameXPtg.java index 0dc640c299..4874c78eab 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/NameXPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/NameXPtg.java @@ -70,6 +70,11 @@ public final class NameXPtg extends OperandPtg implements WorkbookDependentFormu out.writeShort(_reserved); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/NameXPxg.java b/src/java/org/apache/poi/ss/formula/ptg/NameXPxg.java index 13a6a1dba4..8ed4c9c43f 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/NameXPxg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/NameXPxg.java @@ -94,6 +94,11 @@ public final class NameXPxg extends OperandPtg implements Pxg { return Ptg.CLASS_VALUE; } + @Override + public byte getSid() { + return -1; + } + public int getSize() { return 1; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java b/src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java index 07725ebfda..aaf2b11f29 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java @@ -29,8 +29,9 @@ public final class NotEqualPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -38,14 +39,7 @@ public final class NotEqualPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append( operands[0] ); - - buffer.append("<>"); - buffer.append( operands[1] ); - - return buffer.toString(); + return operands[0] + "<>" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/NumberPtg.java b/src/java/org/apache/poi/ss/formula/ptg/NumberPtg.java index 1444135d65..b58d207317 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/NumberPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/NumberPtg.java @@ -62,6 +62,11 @@ public final class NumberPtg extends ScalarConstantPtg { out.writeDouble(getValue()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java index 13be77a418..11bbeb2970 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java @@ -42,6 +42,11 @@ public final class ParenthesisPtg extends ControlPtg { out.writeByte(sid + getPtgClass()); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/PercentPtg.java b/src/java/org/apache/poi/ss/formula/ptg/PercentPtg.java index b5e6664d16..90d999790c 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/PercentPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/PercentPtg.java @@ -32,8 +32,9 @@ public final class PercentPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -41,11 +42,7 @@ public final class PercentPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(PERCENT); - return buffer.toString(); + return operands[0] + PERCENT; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java b/src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java index d7bd306b49..f759abe493 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java @@ -26,8 +26,9 @@ public final class PowerPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -35,13 +36,7 @@ public final class PowerPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - - buffer.append(operands[ 0 ]); - buffer.append("^"); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + "^" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/Ptg.java b/src/java/org/apache/poi/ss/formula/ptg/Ptg.java index fc5691ac59..3651ab93b2 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Ptg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Ptg.java @@ -319,4 +319,9 @@ public abstract class Ptg implements Duplicatable, GenericRecord { @Override public abstract Ptg copy(); + + /** + * @return structure id of the parsed thing, or {@code -1} if the record has no sid + */ + public abstract byte getSid(); } diff --git a/src/java/org/apache/poi/ss/formula/ptg/RangePtg.java b/src/java/org/apache/poi/ss/formula/ptg/RangePtg.java index 35b43414c7..5c2d42a539 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/RangePtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/RangePtg.java @@ -34,8 +34,12 @@ public final class RangePtg extends OperationPtg { return true; } - public int getSize() - { + @Override + public byte getSid() { + return sid; + } + + public int getSize() { return SIZE; } @@ -50,14 +54,8 @@ public final class RangePtg extends OperationPtg { /** implementation of method from OperationsPtg*/ - public String toFormulaString(String[] operands) - { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(":"); - buffer.append(operands[ 1 ]); - return buffer.toString(); + public String toFormulaString(String[] operands) { + return operands[0] + ":" + operands[1]; } public int getNumberOfOperands() diff --git a/src/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java b/src/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java index fb052fa266..a34327dee4 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java @@ -55,8 +55,6 @@ abstract class Ref2DPtgBase extends RefPtgBase { return formatReferenceAsString(); } - protected abstract byte getSid(); - @Override public final int getSize() { return SIZE; diff --git a/src/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java b/src/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java index 3679b97467..654e57cf9b 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java @@ -67,6 +67,11 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu writeCoordinates(out); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java b/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java index 0348cd0e8d..cebc0dcd6a 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java @@ -98,6 +98,11 @@ public final class Ref3DPxg extends RefPtgBase implements Pxg3D { return sb.toString(); } + @Override + public byte getSid() { + return -1; + } + public int getSize() { return 1; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java b/src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java index fa67ccbdc4..a3effafbf0 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java @@ -52,8 +52,12 @@ public final class RefErrorPtg extends OperandPtg { out.writeInt(field_1_reserved); } - public int getSize() - { + @Override + public byte getSid() { + return sid; + } + + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/RefNPtg.java b/src/java/org/apache/poi/ss/formula/ptg/RefNPtg.java index faf6e9ab8d..4aa9f54801 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/RefNPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/RefNPtg.java @@ -31,9 +31,10 @@ public final class RefNPtg extends Ref2DPtgBase { super(other); } - protected byte getSid() { - return sid; - } + @Override + public byte getSid() { + return sid; + } protected final String formatReferenceAsString() { StringBuilder builder = new StringBuilder(); diff --git a/src/java/org/apache/poi/ss/formula/ptg/RefPtg.java b/src/java/org/apache/poi/ss/formula/ptg/RefPtg.java index 0f9811a4bb..668ba2b172 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/RefPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/RefPtg.java @@ -50,7 +50,8 @@ public final class RefPtg extends Ref2DPtgBase { super(cr); } - protected byte getSid() { + @Override + public byte getSid() { return sid; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/StringPtg.java b/src/java/org/apache/poi/ss/formula/ptg/StringPtg.java index 9ccffe7697..52e8ee388e 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/StringPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/StringPtg.java @@ -84,6 +84,11 @@ public final class StringPtg extends ScalarConstantPtg { } } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return 3 + field_3_string.length() * (_is16bitUnicode ? 2 : 1); } diff --git a/src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java b/src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java index 54e7817f5b..591a47b565 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java @@ -26,8 +26,9 @@ public final class SubtractPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -35,12 +36,7 @@ public final class SubtractPtg extends ValueOperatorPtg { } public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append("-"); - buffer.append(operands[ 1 ]); - return buffer.toString(); + return operands[0] + "-" + operands[1]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/TblPtg.java b/src/java/org/apache/poi/ss/formula/ptg/TblPtg.java index 90218bda70..a4eec5a6bd 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/TblPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/TblPtg.java @@ -58,6 +58,11 @@ public final class TblPtg extends ControlPtg { out.writeShort(field_2_first_col); } + @Override + public byte getSid() { + return sid; + } + public int getSize() { return SIZE; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/UnaryMinusPtg.java b/src/java/org/apache/poi/ss/formula/ptg/UnaryMinusPtg.java index a257977826..fa936b2cab 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/UnaryMinusPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/UnaryMinusPtg.java @@ -31,8 +31,9 @@ public final class UnaryMinusPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -41,10 +42,7 @@ public final class UnaryMinusPtg extends ValueOperatorPtg { /** implementation of method from OperationsPtg*/ public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - buffer.append(MINUS); - buffer.append(operands[ 0]); - return buffer.toString(); + return MINUS + operands[0]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/UnaryPlusPtg.java b/src/java/org/apache/poi/ss/formula/ptg/UnaryPlusPtg.java index 68a0d0e1ae..91cb9012ef 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/UnaryPlusPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/UnaryPlusPtg.java @@ -31,8 +31,9 @@ public final class UnaryPlusPtg extends ValueOperatorPtg { // enforce singleton } - protected byte getSid() { - return sid; + @Override + public byte getSid() { + return sid; } public int getNumberOfOperands() { @@ -41,10 +42,7 @@ public final class UnaryPlusPtg extends ValueOperatorPtg { /** implementation of method from OperationsPtg*/ public String toFormulaString(String[] operands) { - StringBuilder buffer = new StringBuilder(); - buffer.append(ADD); - buffer.append(operands[ 0]); - return buffer.toString(); + return ADD + operands[0]; } @Override diff --git a/src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java b/src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java index 681f9efc54..2c1d770da6 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java @@ -36,8 +36,12 @@ public final class UnionPtg extends OperationPtg { return true; } - public int getSize() - { + @Override + public byte getSid() { + return sid; + } + + public int getSize() { return 1; } @@ -52,14 +56,8 @@ public final class UnionPtg extends OperationPtg { /** implementation of method from OperationsPtg*/ - public String toFormulaString(String[] operands) - { - StringBuilder buffer = new StringBuilder(); - - buffer.append(operands[ 0 ]); - buffer.append(","); - buffer.append(operands[ 1 ]); - return buffer.toString(); + public String toFormulaString(String[] operands) { + return operands[0] + "," + operands[1]; } public int getNumberOfOperands() diff --git a/src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java b/src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java index b8930d0ee1..bd92b9b56e 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java @@ -22,7 +22,7 @@ import java.util.function.Supplier; import org.apache.poi.util.LittleEndianOutput; public class UnknownPtg extends Ptg { - private short size = 1; + private final short size = 1; private final int _sid; public UnknownPtg(int sid) { @@ -36,6 +36,11 @@ public class UnknownPtg extends Ptg { out.writeByte(_sid); } + @Override + public byte getSid() { + return (byte)_sid; + } + public int getSize() { return size; } diff --git a/src/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java b/src/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java index a3e595df04..1eff73a826 100644 --- a/src/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java +++ b/src/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java @@ -43,8 +43,6 @@ public abstract class ValueOperatorPtg extends OperationPtg { out.writeByte(getSid()); } - protected abstract byte getSid(); - public final int getSize() { return 1; } diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java index 0dbd1e6ae6..e4b73a3de4 100644 --- a/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java +++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java @@ -49,6 +49,11 @@ public class TestAbstractFunctionPtg { super(functionIndex, pReturnClass, paramTypes, nParams); } + @Override + public byte getSid() { + return -1; + } + public int getSize() { return 0; } -- 2.39.5