]> source.dussan.org Git - poi.git/commitdiff
#64036 - Replace reflection calls in factories for Java 9+
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 16 Aug 2020 16:54:25 +0000 (16:54 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 16 Aug 2020 16:54:25 +0000 (16:54 +0000)
removed some unnecessary reflection calls OperationEvaluatorFactory

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880903 13f79535-47bb-0310-9956-ffa450edef68

58 files changed:
src/java/org/apache/poi/ss/formula/OperationEvaluatorFactory.java
src/java/org/apache/poi/ss/formula/ptg/AddPtg.java
src/java/org/apache/poi/ss/formula/ptg/Area2DPtgBase.java
src/java/org/apache/poi/ss/formula/ptg/Area3DPtg.java
src/java/org/apache/poi/ss/formula/ptg/Area3DPxg.java
src/java/org/apache/poi/ss/formula/ptg/AreaErrPtg.java
src/java/org/apache/poi/ss/formula/ptg/AreaNPtg.java
src/java/org/apache/poi/ss/formula/ptg/AreaPtg.java
src/java/org/apache/poi/ss/formula/ptg/ArrayInitialPtg.java
src/java/org/apache/poi/ss/formula/ptg/ArrayPtg.java
src/java/org/apache/poi/ss/formula/ptg/AttrPtg.java
src/java/org/apache/poi/ss/formula/ptg/BoolPtg.java
src/java/org/apache/poi/ss/formula/ptg/ConcatPtg.java
src/java/org/apache/poi/ss/formula/ptg/Deleted3DPxg.java
src/java/org/apache/poi/ss/formula/ptg/DeletedArea3DPtg.java
src/java/org/apache/poi/ss/formula/ptg/DeletedRef3DPtg.java
src/java/org/apache/poi/ss/formula/ptg/DividePtg.java
src/java/org/apache/poi/ss/formula/ptg/EqualPtg.java
src/java/org/apache/poi/ss/formula/ptg/ErrPtg.java
src/java/org/apache/poi/ss/formula/ptg/ExpPtg.java
src/java/org/apache/poi/ss/formula/ptg/FuncPtg.java
src/java/org/apache/poi/ss/formula/ptg/FuncVarPtg.java
src/java/org/apache/poi/ss/formula/ptg/GreaterEqualPtg.java
src/java/org/apache/poi/ss/formula/ptg/GreaterThanPtg.java
src/java/org/apache/poi/ss/formula/ptg/IntPtg.java
src/java/org/apache/poi/ss/formula/ptg/IntersectionPtg.java
src/java/org/apache/poi/ss/formula/ptg/LessEqualPtg.java
src/java/org/apache/poi/ss/formula/ptg/LessThanPtg.java
src/java/org/apache/poi/ss/formula/ptg/MemAreaPtg.java
src/java/org/apache/poi/ss/formula/ptg/MemErrPtg.java
src/java/org/apache/poi/ss/formula/ptg/MemFuncPtg.java
src/java/org/apache/poi/ss/formula/ptg/MissingArgPtg.java
src/java/org/apache/poi/ss/formula/ptg/MultiplyPtg.java
src/java/org/apache/poi/ss/formula/ptg/NamePtg.java
src/java/org/apache/poi/ss/formula/ptg/NameXPtg.java
src/java/org/apache/poi/ss/formula/ptg/NameXPxg.java
src/java/org/apache/poi/ss/formula/ptg/NotEqualPtg.java
src/java/org/apache/poi/ss/formula/ptg/NumberPtg.java
src/java/org/apache/poi/ss/formula/ptg/ParenthesisPtg.java
src/java/org/apache/poi/ss/formula/ptg/PercentPtg.java
src/java/org/apache/poi/ss/formula/ptg/PowerPtg.java
src/java/org/apache/poi/ss/formula/ptg/Ptg.java
src/java/org/apache/poi/ss/formula/ptg/RangePtg.java
src/java/org/apache/poi/ss/formula/ptg/Ref2DPtgBase.java
src/java/org/apache/poi/ss/formula/ptg/Ref3DPtg.java
src/java/org/apache/poi/ss/formula/ptg/Ref3DPxg.java
src/java/org/apache/poi/ss/formula/ptg/RefErrorPtg.java
src/java/org/apache/poi/ss/formula/ptg/RefNPtg.java
src/java/org/apache/poi/ss/formula/ptg/RefPtg.java
src/java/org/apache/poi/ss/formula/ptg/StringPtg.java
src/java/org/apache/poi/ss/formula/ptg/SubtractPtg.java
src/java/org/apache/poi/ss/formula/ptg/TblPtg.java
src/java/org/apache/poi/ss/formula/ptg/UnaryMinusPtg.java
src/java/org/apache/poi/ss/formula/ptg/UnaryPlusPtg.java
src/java/org/apache/poi/ss/formula/ptg/UnionPtg.java
src/java/org/apache/poi/ss/formula/ptg/UnknownPtg.java
src/java/org/apache/poi/ss/formula/ptg/ValueOperatorPtg.java
src/testcases/org/apache/poi/ss/formula/ptg/TestAbstractFunctionPtg.java

index 65676a61fde8a5d5571e5bfaba19be7684ce6d11..ca10b13075f4589ea0c6283b14f845ff96c61199 100644 (file)
 
 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<OperationPtg, Function> _instancesByPtgClass = initialiseInstancesMap();
+       private static final Map<Byte, Function> _instancesByPtgClass = initialiseInstancesMap();
 
        private OperationEvaluatorFactory() {
                // no instances of this class
        }
 
-       private static Map<OperationPtg, Function> initialiseInstancesMap() {
-               Map<OperationPtg, Function> m = new HashMap<>(32);
+       private static Map<Byte, Function> initialiseInstancesMap() {
+               Map<Byte, Function> 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<OperationPtg, Function> 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);
index aedc6dd86fdeb196c9b76ec101e48214aea1a4c9..717a39010bba2cc0613ea696a8b8a10e14a20492 100644 (file)
@@ -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
index f43a288a64b0d88f15c937bbdd1c1ea0cea98c4d..ccfd9c76cf9cea4a39632176e1992b2877b36415 100644 (file)
@@ -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);
index 31a08f46b1c77950ae2a5f1176cc5e30439de97a..9a21b606605f4a803fc7bc64005b96b7c4967721 100644 (file)
@@ -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;
index e86df93a84e5b78ee9ecea158a1b7b24d76e0fe3..729fc0e74216597fb5e0d01752d22fae6d271542 100644 (file)
@@ -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;
     }
index dba6c16f51013438bfb92126b3c789fb4bf93ff2..4a9a041e548402314ae20327d0396e1cab4e97d7 100644 (file)
@@ -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;
        }
index 0c0faca5052b0a1f3a53cd8df98aea04ac263e40..1627704dfea3b258dfe9efed53f8651300e01455 100644 (file)
@@ -34,7 +34,8 @@ public final class AreaNPtg extends Area2DPtgBase {
                super(in);
        }
 
-       protected byte getSid() {
+       @Override
+       public byte getSid() {
                return sid;
        }
 
index ca711e6f06ad6829d817bfa668252d4199ba3329..0ee4c0292e2be3f0c26e172a48dc81b82639ac31 100644 (file)
@@ -43,7 +43,7 @@ public final class AreaPtg extends Area2DPtgBase {
     }
 
        @Override
-       protected byte getSid() {
+       public byte getSid() {
                return sid;
        }
 
index bfd3b8d0a9b1aecbbd0f692e8aadc45fcb966d56..f242fb2b39bf415f1265afa1b7b574d9873fabb5 100644 (file)
@@ -95,4 +95,9 @@ final class ArrayInitialPtg extends Ptg {
                        "reserved2", () -> _reserved2
                );
        }
+
+       @Override
+       public byte getSid() {
+               return -1;
+       }
 }
index fd6d932e7460d3786e953845ac7ed65001046efd..aff4aa391855b445caf9f5301588927ae1cd1b8b 100644 (file)
@@ -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("{");
index e1fe9ab49de4810b42d75a6bef4247ef58606152..16dc206dbbeea223229eca5b71c764bf06e12699 100644 (file)
@@ -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;
index 467eb67473eec99f1d956c6569a94250802a3b82..a94986f7fe1d5f2b77e89bce70c9a9dde9e2bd77 100644 (file)
@@ -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;
        }
index 91d0840d3c3d5343f2f06102fb6057e5b28404ef..bedcb94162913cea6f4f7dd1074f3f5967235e87 100644 (file)
@@ -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
index 26701d06ade18a11618f345a7517af23d39c378f..b58b8e5298c424d2a2a2413aef30a51704671010 100644 (file)
@@ -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");
     }
index 679b43047612e2b87cf75d680844cd136be07cb3..023bc8d9202e3126e734bda8ff8d4524cbbf2ff4 100644 (file)
@@ -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;
        }
index cca55f5e00f353cfde5033cb50eddd02874b2ce8..ea2805203cc09c9c1f53ba880647a59a2af143c2 100644 (file)
@@ -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;
        }
index d2b11921a63891eebed78aa6273373a6aa0ec1e7..f53cb09ebd0b5f2670b0d058a0c0e7a2e71067bb 100644 (file)
@@ -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
index 99961e3eda3d05d43fc9a51d8630b394f8fbdbb1..596be4912ca3948795230b6fb2d61a9891b72dfa 100644 (file)
@@ -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
index 708ff3073331f920787f51ada2db256503330705..6cb5d41803511f78a64e1918379070e75f238b33 100644 (file)
@@ -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;
     }
index e63f6cdf7d3532ce21c92fe80659ae2b3c7ba9f5..93249caa39f41c86fd8e103dbc4f818ff98bec38 100644 (file)
@@ -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;
index 6fc76a5815283c2dd9a682d81b201a43d536ed03..4b01512aac1173c9c2006e3fd115c8358c815917 100644 (file)
@@ -49,6 +49,11 @@ public final class FuncPtg extends AbstractFunctionPtg {
         out.writeShort(getFunctionIndex());
     }
 
+    @Override
+    public byte getSid() {
+        return sid;
+    }
+
     public int getSize() {
         return SIZE;
     }
index 1445aeb0d7b4cd456ba7b380ea61ff508d02afac..398ec47b0558c934b54b9ada009e6375ddc89640 100644 (file)
@@ -88,6 +88,11 @@ public final class FuncVarPtg extends AbstractFunctionPtg {
         out.writeShort(getFunctionIndex());
     }
 
+    @Override
+    public byte getSid() {
+        return sid;
+    }
+
     public int getSize() {
         return SIZE;
     }
index c89d1c8876c052661048afd669842c3beccc3a71..513a537dec9aa70ad93e0367c27697fef611ba7d 100644 (file)
@@ -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
index 307fb6eee7f6ffd252db3fb858b3c9962e43e70c..98a8c2fea88e08aa343b25c625d55b8ddc03faed 100644 (file)
@@ -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
index 6f214532cf3ae30784c9a3a9ae48dabd9cdbe598..230883e9e2ef887fdc60330fcc6d8fcfdf238df6 100644 (file)
@@ -66,6 +66,11 @@ public final class IntPtg extends ScalarConstantPtg {
                out.writeShort(getValue());
        }
 
+       @Override
+       public byte getSid() {
+               return sid;
+       }
+
        public int getSize() {
                return SIZE;
        }
index 9a641654faced844ef338a4843d7a5c487f33fcd..abad733c4e65ade8d9d8df9094e0ecc3c577aad1 100644 (file)
@@ -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() {
index d7aa350c633ee8a00b66698e5857cfe23b0312d1..d94206a39cf34d95850ad82a7621b84e083d8d3a 100644 (file)
@@ -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
index f98b215cd8f9f42385756e9554f39485bad5254a..74ed426f8f59ab683221b7a3935312cc258d50ee 100644 (file)
@@ -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
index 2797a20cec872ae1c8ee38298c8306cc83a35fc9..f1eb6d0b8a2938d706777714a0751326646f808d 100644 (file)
@@ -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;
        }
index 4d0ee89ca1cad0f50d6d9a3e5525245ef4a8c9be..2f70c197fc0597e276b9dd0ac7a267ba2329b1c5 100644 (file)
@@ -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;
        }
index 7cc9532dcbd86a037c6e696c9e62e205e95019ad..532e66c5c2ca2145466663dfa966961551ac88c9 100644 (file)
@@ -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;
        }
index b1505dc09c89377f7b9d2e7c7083a8f4785eb273..e474aabf374c3578631b6ccaf2d90c916638c3cc 100644 (file)
@@ -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;
        }
index c99e90318a9ec06fb70cfcc3f91fc24f14d16def..d6dc2e2016a1f3d638fdcbbd34fe39370bb0b729 100644 (file)
@@ -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
index a3520b4108ae3582d589768370187cffb7c40ab1..8084fa4337df784aa2c04a83667f943311f78051 100644 (file)
@@ -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;
index 0dc640c2994f1c543ec730596058f4bcf27e4b91..4874c78eab39321c39bf37d1ef5c9c6246ac6165 100644 (file)
@@ -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;
        }
index 13a6a1dba4bc3126135fbe64134488067c704c52..8ed4c9c43f4825ee6db35df96d52f3fa160df2e3 100644 (file)
@@ -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;
     }
index 07725ebfda486e3c340031db83a2853a106b9e72..aaf2b11f29b341e91025c2b2844953390550ca8d 100644 (file)
@@ -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
index 1444135d65bab21fbbde898b120bbc6b51810072..b58d207317d5cbd13bbbba060058982776750de9 100644 (file)
@@ -62,6 +62,11 @@ public final class NumberPtg extends ScalarConstantPtg {
                out.writeDouble(getValue());
        }
 
+       @Override
+       public byte getSid() {
+               return sid;
+       }
+
        public int getSize() {
                return SIZE;
        }
index 13be77a41814485d20dd7c45aee46f40334f3bb6..11bbeb2970edc15e888659dc0788509096b3dcea 100644 (file)
@@ -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;
        }
index b5e6664d16aec8af32730f5c7b273a8ad1e15a6a..90d999790c9bcdb04d4a48947a440abc903a6861 100644 (file)
@@ -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
index d7bd306b49b1b8f702bc71c7d13a052c56dd79a4..f759abe4936fa0a7024b17d75a21d53e44ef2cbb 100644 (file)
@@ -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
index fc5691ac59834c13a45dd857d9096e1e4c28ee32..3651ab93b21da75d35e3697e26e902bd31df0c9b 100644 (file)
@@ -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();
 }
index 35b43414c7cb7c4f68e5d3d6e3bcbf5a4579dbc8..5c2d42a5391e2a88da84b07e4799060260defd3e 100644 (file)
@@ -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()
index fb052fa266ffcaf6667cb3ae02a1ddcd60e94301..a34327dee4a99b10828cd619cb6084e6e6cf62a9 100644 (file)
@@ -55,8 +55,6 @@ abstract class Ref2DPtgBase extends RefPtgBase {
                return formatReferenceAsString();
        }
 
-       protected abstract byte getSid();
-
        @Override
     public final int getSize() {
                return SIZE;
index 3679b97467be9e862754dfde8737005907f1819d..654e57cf9b8d61b369a30898fe7438ae1bfaa34f 100644 (file)
@@ -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;
     }
index 0348cd0e8d1842a0c9b647f99d170561b4544eab..cebc0dcd6a6fc4425b24dad329a2db0689584f64 100644 (file)
@@ -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;
     }
index fa67ccbdc45b24138ab44474cb191da687b39d2e..a3effafbf000bdfbfaa26d159817a586e14044a3 100644 (file)
@@ -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;
     }
 
index faf6e9ab8da72a35b4ae6181ea3d338813bcf0e1..4aa9f54801ee158ecd52ac96b76d961fe7e97975 100644 (file)
@@ -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();
index 0f9811a4bb3f34b9013dfd4badd05a316267abcb..668ba2b172b4d9e7da4d310d3d1c6a70f70e0b1a 100644 (file)
@@ -50,7 +50,8 @@ public final class RefPtg extends Ref2DPtgBase {
                super(cr);
        }
 
-       protected byte getSid() {
+       @Override
+       public byte getSid() {
                return sid;
        }
 
index 9ccffe769700e80e9417aa5ec7d5cb8859703e24..52e8ee388e607944a0b566b5a5dfe372cf761d8d 100644 (file)
@@ -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);
     }
index 54e7817f5b16a4b0f5a438ed1f7e05993ed9a0d2..591a47b5652dadbb053e44a744ee365f17148de8 100644 (file)
@@ -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
index 90218bda70d890c038b39afb6403b6917921053c..a4eec5a6bd734cdcba24994c28f2153ab38f0c8a 100644 (file)
@@ -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;
     }
index a2579778263d2ef67ac7e82e304612832546b1eb..fa936b2cab6a3a713d8cb0ec4b3009e2c6203bad 100644 (file)
@@ -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
index 68a0d0e1ae6439c2a4eb15dbafcc294286202220..91cb9012effc6e9330bb81e89281cfb61cdb0f3d 100644 (file)
@@ -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
index 681f9efc54ef700a42fd9ef9cade63421528f6de..2c1d770da64174331bffe8b5b964769c46ad5fe9 100644 (file)
@@ -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()
index b8930d0ee1da59b150d642534ed342aec5144641..bd92b9b56ef59418dfeb80a585187e967a131cdd 100644 (file)
@@ -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;
     }
index a3e595df044e98f0fa47f6f41c8698461e86751f..1eff73a826b0f8158bd9d7d6c065895ce2d58166 100644 (file)
@@ -43,8 +43,6 @@ public abstract class ValueOperatorPtg extends OperationPtg {
                out.writeByte(getSid());
        }
 
-       protected abstract byte getSid();
-
        public final int getSize() {
                return 1;
        }
index 0dbd1e6ae6f223ade373f96ec17550ac52ce6e4d..e4b73a3de441bfcdc9f4657965ba67386a7c23b3 100644 (file)
@@ -49,6 +49,11 @@ public class TestAbstractFunctionPtg  {
             super(functionIndex, pReturnClass, paramTypes, nParams);
         }
 
+        @Override
+        public byte getSid() {
+            return -1;
+        }
+
         public int getSize() {
             return 0;
         }