]> source.dussan.org Git - poi.git/commitdiff
Sonar fixes - String literals should not be duplicated
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 5 Apr 2020 20:50:40 +0000 (20:50 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 5 Apr 2020 20:50:40 +0000 (20:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876163 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java
src/examples/src/org/apache/poi/ss/examples/ConditionalFormats.java
src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java
src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTest.java
src/java/org/apache/poi/POIReadOnlyDocument.java
src/java/org/apache/poi/common/usermodel/fonts/FontCharset.java
src/java/org/apache/poi/hpsf/ClassIDPredefined.java
src/java/org/apache/poi/hssf/dev/FormulaViewer.java

index 41ccbe0b036029b9071877309ed8d78957cb3d9e..517e99b0449e7245eb935b62ca8f900d2fbdeede 100644 (file)
@@ -48,6 +48,7 @@ import org.apache.poi.sl.usermodel.VerticalAlignment;
  *
  * @author Yegor Kozlov
  */
+@SuppressWarnings("java:S1192")
 public final class ApacheconEU08 {
 
     public static void main(String[] args) throws IOException {
index 4415bfd5f25c2994c7b695e5da14dfdb7fb990dc..fbbcab895dc09fafb55d6f5a63719bd6a0ebb53c 100644 (file)
@@ -45,6 +45,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  *
  * @author Yegor Kozlov
  */
+@SuppressWarnings("java:S1192")
 public class BusinessPlan {
 
     private static final String[] titles = {
index 654e837a42bc15829f0fca55329449efafc3ad81..28a861b6c2e484cf6b081adde35807ae037dea14 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  *   http://www.contextures.com/xlcondformat03.html
  * </p>
  */
+@SuppressWarnings("java:S1192")
 public class ConditionalFormats {
 
     /**
index b6bad2b4c0ed2667a1b9ce285b7d31a7945006d5..4dfd6f530222d96bf88379b8bf977112400b1d3d 100644 (file)
@@ -80,8 +80,9 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  *  }
  * </pre>
  */
+@SuppressWarnings("java:S1192")
 public class ExcelComparator {
-    
+
     private static final String CELL_DATA_DOES_NOT_MATCH = "Cell Data does not Match ::";
     private static final String CELL_FONT_ATTRIBUTES_DOES_NOT_MATCH = "Cell Font Attributes does not Match ::";
 
@@ -91,7 +92,7 @@ public class ExcelComparator {
         Row row;
         Cell cell;
     }
-    
+
     List<String> listOfDifferences = new ArrayList<>();
 
     public static void main(String[] args) throws Exception {
@@ -108,7 +109,7 @@ public class ExcelComparator {
             }
         }
     }
-    
+
     /**
      * Utility to compare Excel File Contents cell by cell for all sheets.
      *
@@ -231,16 +232,16 @@ public class ExcelComparator {
             if (loc2.workbook.getNumberOfSheets() <= i) {
                 return;
             }
-            
+
             loc1.sheet = loc1.workbook.getSheetAt(i);
             loc2.sheet = loc2.workbook.getSheetAt(i);
 
             Iterator<Row> ri1 = loc1.sheet.rowIterator();
             Iterator<Row> ri2 = loc2.sheet.rowIterator();
-            
+
             int num1 = (ri1.hasNext()) ? ri1.next().getPhysicalNumberOfCells() : 0;
             int num2 = (ri2.hasNext()) ? ri2.next().getPhysicalNumberOfCells() : 0;
-            
+
             if (num1 != num2) {
                 String str = String.format(Locale.ROOT, "%s\nworkbook1 -> %s [%d] != workbook2 -> %s [%d]",
                     "Number Of Columns does not Match ::",
@@ -263,7 +264,7 @@ public class ExcelComparator {
 
             loc1.sheet = loc1.workbook.getSheetAt(i);
             loc2.sheet = loc2.workbook.getSheetAt(i);
-            
+
             int num1 = loc1.sheet.getPhysicalNumberOfRows();
             int num2 = loc2.sheet.getPhysicalNumberOfRows();
 
@@ -292,7 +293,7 @@ public class ExcelComparator {
             );
 
             listOfDifferences.add(str);
-            
+
         }
     }
 
@@ -313,7 +314,7 @@ public class ExcelComparator {
         for (int i = 0; i < loc1.workbook.getNumberOfSheets(); i++) {
             String name1 = loc1.workbook.getSheetName(i);
             String name2 = (loc2.workbook.getNumberOfSheets() > i) ? loc2.workbook.getSheetName(i) : "";
-            
+
             if (!name1.equals(name2)) {
                 String str = String.format(Locale.ROOT, "%s\nworkbook1 -> %s [%d] != workbook2 -> %s [%d]",
                     "Name of the sheets do not match ::", name1, i+1, name2, i+1
@@ -461,7 +462,7 @@ public class ExcelComparator {
         Color col = loc.cell.getCellStyle().getFillForegroundColorColor();
         return (col instanceof XSSFColor) ? ((XSSFColor)col).getARGBHex() : "NO COLOR";
     }
-    
+
     /**
      * Checks if cell file back ground matches.
      */
index 7dc92ee49bc09192f5cd9b8f523d8dc365f5ff1c..4714090bf11ef29babf2b08868609316515ebad7 100644 (file)
 
 package org.apache.poi.ss.examples;
 
-import org.apache.poi.xssf.usermodel.*;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
-import java.util.Map;
-import java.util.HashMap;
 import java.io.FileOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.usermodel.PrintSetup;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * Simple Loan Calculator. Demonstrates advance usage of cell formulas and named ranges.
@@ -34,6 +45,7 @@ import java.io.FileOutputStream;
  *
  * @author Yegor Kozlov
  */
+@SuppressWarnings("java:S1192")
 public class LoanCalculator {
 
     public static void main(String[] args) throws Exception {
index 92aba4d30798dc9d2f9cb8c696f29651e224c269..8484c0998c3d62b60391d6d4263e6023d5add9f9 100644 (file)
@@ -25,8 +25,8 @@ import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.poi.ooxml.POIXMLTypeLoader;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ooxml.POIXMLTypeLoader;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.FillPatternType;
@@ -42,6 +42,7 @@ import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
+@SuppressWarnings("java:S1192")
 public class SSPerformanceTest {
     public static void main(String[] args) throws IOException {
         if (args.length < 4) {
index 6ab8a294382e03d9e0ddf6fe51621181ab14ecd8..5d65bd353981323c39aab8578254492c63f4c280 100644 (file)
 
 package org.apache.poi.ss.examples;
 
-import org.apache.poi.xssf.usermodel.*;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-
-import java.util.Map;
-import java.util.HashMap;
 import java.io.FileOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.PrintSetup;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  * A weekly timesheet created using Apache POI.
@@ -33,6 +44,7 @@ import java.io.FileOutputStream;
  *
  * @author Yegor Kozlov
  */
+@SuppressWarnings("java:S1192")
 public class TimesheetDemo {
     private static final String[] titles = {
             "Person",  "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
index 74221715a9feb982c991a84c2e886241383d4b4e..874bce4d7650f677d7f190a437fda4fae2a3c8cc 100644 (file)
@@ -53,6 +53,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  * This example shows how to display a spreadsheet in HTML using the classes for
  * spreadsheet display.
  */
+@SuppressWarnings("java:S1192")
 public class ToHtml {
     private final Workbook wb;
     private final Appendable output;
index 586f85566782a4c3881c39c93218402a9915126c..2fd45cab15020c98100b7b2c1d5fe9f5057b0b80 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.ss.excelant;
 
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.function.Supplier;
 
 import org.apache.poi.ss.excelant.util.ExcelAntEvaluationResult;
 import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
@@ -30,131 +31,126 @@ import org.apache.tools.ant.Task;
  * This class represents a single test.  In order for the test any and all
  * ExcelAntEvaluateCell evaluations must pass.  Therefore it is recommended
  * that you use only 1 evaluator but you can use more if you choose.
- * 
+ *
  * @author Jon Svede ( jon [at] loquatic [dot] com )
  * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
  *
  */
+@SuppressWarnings("unused")
 public class ExcelAntTest extends Task{
        private LinkedList<ExcelAntEvaluateCell> evaluators;
-       
+
        private LinkedList<Task> testTasks;
-       
+
        private String name;
-       
+
        private double globalPrecision;
-       
+
        private boolean showSuccessDetails;
-       
+
        private boolean showFailureDetail;
        LinkedList<String> failureMessages;
-       
+
 
        private ExcelAntWorkbookUtil workbookUtil;
-       
+
        private boolean passed = true;
 
-       
+
        public ExcelAntTest() {
                evaluators = new LinkedList<>();
                failureMessages = new LinkedList<>();
                testTasks = new LinkedList<>();
        }
-       
+
        public void setPrecision( double precision ) {
                globalPrecision = precision;
        }
-       
+
        public void setWorkbookUtil( ExcelAntWorkbookUtil wbUtil ) {
                workbookUtil = wbUtil;
        }
-       
-       
+
+
        public void setShowFailureDetail( boolean value ) {
                showFailureDetail = value;
        }
-       
+
        public void setName( String nm ) {
                name = nm;
        }
-       
+
        public String getName() {
                return name;
        }
-       
+
        public void setShowSuccessDetails( boolean details ) {
            showSuccessDetails = details;
        }
-       
+
        public boolean showSuccessDetails() {
            return showSuccessDetails;
        }
-       
+
        public void addSetDouble( ExcelAntSetDoubleCell setter ) {
            addSetter( setter );
        }
-       
+
        public void addSetString( ExcelAntSetStringCell setter ){
            addSetter( setter );
        }
-       
+
        public void addSetFormula( ExcelAntSetFormulaCell setter ) {
            addSetter( setter );
        }
-       
+
        public void addHandler( ExcelAntHandlerTask handler ) {
            testTasks.add( handler );
        }
-       
+
        private void addSetter( ExcelAntSet setter ) {
-//             setters.add( setter );
                testTasks.add( setter );
        }
-       
+
        public void addEvaluate( ExcelAntEvaluateCell evaluator ) {
-//             evaluators.add( evaluator );
                testTasks.add( evaluator );
        }
-       
-//     public LinkedList<ExcelAntSet> getSetters() {
-//             return setters;
-//     }
 
        protected LinkedList<ExcelAntEvaluateCell> getEvaluators() {
                return evaluators;
        }
-       
+
        @Override
     public void execute() throws BuildException {
-           
+
            Iterator<Task> taskIt = testTasks.iterator();
 
            int testCount = evaluators.size();
            int failureCount = 0;
-               
+
            // roll over all sub task elements in one loop.  This allows the
-           // ordering of the sub elements to be considered. 
+           // ordering of the sub elements to be considered.
            while( taskIt.hasNext() ) {
                Task task = taskIt.next();
-               
+
               // log( task.getClass().getName(), Project.MSG_INFO );
-               
+
                if( task instanceof ExcelAntSet ) {
                    ExcelAntSet set = (ExcelAntSet) task;
                    set.setWorkbookUtil(workbookUtil);
                    set.execute();
                }
-               
+
                if( task instanceof ExcelAntHandlerTask ) {
                    ExcelAntHandlerTask handler = (ExcelAntHandlerTask)task;
                    handler.setEAWorkbookUtil(workbookUtil );
                    handler.execute();
                }
-               
+
                if (task instanceof ExcelAntEvaluateCell ) {
                    ExcelAntEvaluateCell eval = (ExcelAntEvaluateCell)task;
                    eval.setWorkbookUtil( workbookUtil );
-                   
+
                    if( globalPrecision > 0 ) {
                        log( "setting globalPrecision to " + globalPrecision + " in the evaluator", Project.MSG_VERBOSE );
                        eval.setGlobalPrecision( globalPrecision );
@@ -163,48 +159,41 @@ public class ExcelAntTest extends Task{
                    try {
                        eval.execute();
                        ExcelAntEvaluationResult result = eval.getResult();
-                       if( result.didTestPass() &&
-                                                       !result.evaluationCompleteWithError()) {
+
+                                       Supplier<String> details = () ->
+                                               result.getCellName() + ".  It evaluated to " +
+                                               result.getReturnValue() + " when the value of " +
+                                               eval.getExpectedValue() + " with precision of " +
+                                               eval.getPrecision();
+
+                       if( result.didTestPass() && !result.evaluationCompleteWithError()) {
                            if(showSuccessDetails) {
-                               log("Succeeded when evaluating " + 
-                                result.getCellName() + ".  It evaluated to " + 
-                             result.getReturnValue() + " when the value of " + 
-                             eval.getExpectedValue() + " with precision of " + 
-                             eval.getPrecision(), Project.MSG_INFO );
+                               log("Succeeded when evaluating " + details.get(), Project.MSG_INFO );
                            }
                        } else {
                            if(showFailureDetail) {
-                               failureMessages.add( "\tFailed to evaluate cell " + 
-                                result.getCellName() + ".  It evaluated to " + 
-                                result.getReturnValue() + " when the value of " + 
-                                eval.getExpectedValue() + " with precision of " + 
-                                eval.getPrecision() + " was expected." );
-
+                               failureMessages.add( "\tFailed to evaluate cell " + details.get() + " was expected." );
                            }
                            passed = false;
                            failureCount++;
-                           
+
                            if(eval.requiredToPass()) {
-                               throw new BuildException( "\tFailed to evaluate cell " + 
-                                       result.getCellName() + ".  It evaluated to " + 
-                                       result.getReturnValue() + " when the value of " + 
-                                       eval.getExpectedValue() + " with precision of " + 
-                                       eval.getPrecision() + " was expected." );
+                               throw new BuildException( "\tFailed to evaluate cell " + details.get() + " was expected." );
                            }
                        }
                    } catch( NullPointerException npe ) {
                        // this means the cell reference in the test is bad.
-                       log( "Cell assignment " + eval.getCell() + " in test " + getName() + 
+                       log( "Cell assignment " + eval.getCell() + " in test " + getName() +
                              " appears to point to an empy cell.  Please check the " +
                              " reference in the ant script.", Project.MSG_ERR );
                    }
                }
            }
+
                if(!passed) {
-                       log( "Test named " + name + " failed because " + failureCount + 
-                                        " of " + testCount + " evaluations failed to " + 
-                                        "evaluate correctly.", 
+                       log( "Test named " + name + " failed because " + failureCount +
+                                        " of " + testCount + " evaluations failed to " +
+                                        "evaluate correctly.",
                                         Project.MSG_ERR );
                        if(showFailureDetail && failureMessages.size() > 0 ) {
                                for (String failureMessage : failureMessages) {
@@ -215,7 +204,7 @@ public class ExcelAntTest extends Task{
        }
 
        public boolean didTestPass() {
-               
+
                return passed;
        }
  }
index dfe44d42f7e56a34ae03d1c353f2d0d32b5ed4eb..5f250704dbb6e16bd3b8586cea82ae09c3260841 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 /**
  * This holds the common functionality for all read-only
  *  POI Document classes, i.e. ones which don't support writing.
- *  
+ *
  *  @since POI 3.15 beta 3
  */
 public abstract class POIReadOnlyDocument extends POIDocument {
@@ -39,29 +39,33 @@ public abstract class POIReadOnlyDocument extends POIDocument {
 
     /**
      * Note - writing is not yet supported for this file format, sorry.
-     * 
+     *
      * @throws IllegalStateException If you call the method, as writing is not supported
      */
     @Override
     public void write() {
-        throw new IllegalStateException("Writing is not yet implemented for this Document Format");
+        notImplemented();
     }
     /**
      * Note - writing is not yet supported for this file format, sorry.
-     * 
+     *
      * @throws IllegalStateException If you call the method, as writing is not supported
      */
     @Override
     public void write(File file) {
-        throw new IllegalStateException("Writing is not yet implemented for this Document Format");
+        notImplemented();
     }
     /**
      * Note - writing is not yet supported for this file format, sorry.
-     * 
+     *
      * @throws IllegalStateException If you call the method, as writing is not supported
      */
     @Override
     public void write(OutputStream out) {
+        notImplemented();
+    }
+
+    private static void notImplemented() {
         throw new IllegalStateException("Writing is not yet implemented for this Document Format");
     }
 }
index 32915149f2b963584080022418628f31e7054949..28df6cad4e02aa0f7b04a4c12258ea0ee6c93625 100644 (file)
@@ -24,11 +24,12 @@ import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 
 /**
- * Charset represents the basic set of characters associated with a font (that it can display), and 
+ * Charset represents the basic set of characters associated with a font (that it can display), and
  * corresponds to the ANSI codepage (8-bit or DBCS) of that character set used by a given language.
- * 
+ *
  * @since POI 3.17-beta2
  */
+@SuppressWarnings("java:S1192")
 public enum FontCharset {
     /** Specifies the English character set. */
     ANSI(0x00000000, "Cp1252"),
@@ -80,17 +81,17 @@ public enum FontCharset {
     OEM(0x000000FF, "Cp1252");
 
     private static FontCharset[] _table = new FontCharset[256];
-    
+
     private int nativeId;
     private Charset charset;
 
-    
+
     static {
         for (FontCharset c : values()) {
             _table[c.getNativeId()] = c;
         }
     }
-    
+
     FontCharset(int flag, String javaCharsetName) {
         this.nativeId = flag;
         if (javaCharsetName.length() > 0) {
@@ -113,12 +114,12 @@ public enum FontCharset {
     public Charset getCharset() {
         return charset;
     }
-    
+
     public int getNativeId() {
         return nativeId;
     }
 
     public static FontCharset valueOf(int value){
-        return (value < 0 || value >= _table.length) ? null :_table[value];
+        return (value < 0 || value >= _table.length) ? null : _table[value];
     }
 }
\ No newline at end of file
index 61454769ec85f1010323f745bb929fb2a16ec71e..61d6566c66be043519067104b39673712ef7321c 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.hpsf;
 import java.util.HashMap;
 import java.util.Map;
 
+@SuppressWarnings("java:S1192")
 public enum ClassIDPredefined {
     /** OLE 1.0 package manager */
     OLE_V1_PACKAGE       ("{0003000C-0000-0000-C000-000000000046}", ".bin", null),
index d53d37aa6767a250ed40773bfa3272df273c1165..bc7cc9cc840b5daccea3a69e1f08b3b1993a878a 100644 (file)
@@ -24,7 +24,6 @@ import java.util.List;
 
 import org.apache.poi.hssf.model.HSSFFormulaParser;
 import org.apache.poi.hssf.record.FormulaRecord;
-import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RecordFactory;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.formula.ptg.ExpPtg;
@@ -51,8 +50,8 @@ public class FormulaViewer
 
     /**
      * Method run
-     * 
-     * @throws IOException if the file contained errors 
+     *
+     * @throws IOException if the file contained errors
      */
     public void run() throws IOException {
         try (POIFSFileSystem fs = new POIFSFileSystem(new File(file), true)) {
@@ -71,61 +70,36 @@ public class FormulaViewer
             }
         }
     }
-    
+
     private void listFormula(FormulaRecord record) {
-        String sep="~";
         Ptg[] tokens= record.getParsedExpression();
-        Ptg token;
         int numptgs = tokens.length;
-        String numArg;
-            token = tokens[numptgs-1];
-            if (token instanceof FuncPtg) {
-                numArg = String.valueOf(numptgs-1);
-            } else { 
-               numArg = String.valueOf(-1);
-            }
-            
-            StringBuilder buf = new StringBuilder();
-            
-            if (token instanceof ExpPtg) return;
-            buf.append(token.toFormulaString());
-            buf.append(sep);
-            switch (token.getPtgClass()) {
-                case Ptg.CLASS_REF :
-                    buf.append("REF");
-                    break;
-                case Ptg.CLASS_VALUE :
-                    buf.append("VALUE");
-                    break;
-                case Ptg.CLASS_ARRAY :
-                    buf.append("ARRAY");
-                    break;
-                default:
-                    throwInvalidRVAToken(token);
-            }
-            
-            buf.append(sep);
-            if (numptgs>1) {
-                token = tokens[numptgs-2];
-                switch (token.getPtgClass()) {
-                    case Ptg.CLASS_REF :
-                        buf.append("REF");
-                        break;
-                    case Ptg.CLASS_VALUE :
-                        buf.append("VALUE");
-                        break;
-                    case Ptg.CLASS_ARRAY :
-                        buf.append("ARRAY");
-                        break;
-                    default:
-                        throwInvalidRVAToken(token);
-                }
-            }else {
-                buf.append("VALUE");
-            }
-            buf.append(sep);
-            buf.append(numArg);
-            System.out.println(buf);
+        final Ptg lastToken = tokens[numptgs-1];
+
+        if (lastToken instanceof ExpPtg) return;
+
+        String buf = String.join("~",
+            lastToken.toFormulaString(),
+            mapToken(lastToken),
+            (numptgs > 1 ? mapToken(tokens[numptgs - 2]) : "VALUE"),
+            String.valueOf(lastToken instanceof FuncPtg ? numptgs-1 : -1)
+        );
+
+        System.out.println(buf);
+    }
+
+    private static String mapToken(Ptg token) {
+        switch (token.getPtgClass()) {
+            case Ptg.CLASS_REF :
+                return "REF";
+            case Ptg.CLASS_VALUE :
+                return "VALUE";
+            case Ptg.CLASS_ARRAY :
+                return "ARRAY";
+            default:
+                throwInvalidRVAToken(token);
+                return "";
+        }
     }
 
     /**
@@ -167,15 +141,15 @@ public class FormulaViewer
                     throwInvalidRVAToken(token);
             }
             buf.append(' ');
-        } 
+        }
         return buf.toString();
     }
-    
+
     private static void throwInvalidRVAToken(Ptg token) {
         throw new IllegalStateException("Invalid RVA type (" + token.getPtgClass() + "). This should never happen.");
     }
-    
-    
+
+
     private static String composeFormula(FormulaRecord record)
     {
        return  HSSFFormulaParser.toFormulaString(null, record.getParsedExpression());
@@ -191,7 +165,7 @@ public class FormulaViewer
     {
         this.file = file;
     }
-    
+
     public void setList(boolean list) {
         this.list=list;
     }