Sonar fixes - String literals should not be duplicated

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876163 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-04-05 20:50:40 +00:00
parent d842136464
commit 65ccec11cb
13 changed files with 160 additions and 161 deletions

View 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 {

View 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 = {

View 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 {
/**

View File

@ -80,6 +80,7 @@ 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 ::";

View File

@ -17,14 +17,25 @@
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 {

View 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) {

View File

@ -17,14 +17,25 @@
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",

View 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;

View 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;
@ -35,6 +36,7 @@ import org.apache.tools.ant.Task;
* @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
*
*/
@SuppressWarnings("unused")
public class ExcelAntTest extends Task{
private LinkedList<ExcelAntEvaluateCell> evaluators;
@ -107,19 +109,13 @@ public class ExcelAntTest extends Task{
}
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;
}
@ -163,33 +159,26 @@ public class ExcelAntTest extends Task{
try {
eval.execute();
ExcelAntEvaluationResult result = eval.getResult();
if( result.didTestPass() &&
!result.evaluationCompleteWithError()) {
if(showSuccessDetails) {
log("Succeeded when evaluating " +
Supplier<String> details = () ->
result.getCellName() + ". It evaluated to " +
result.getReturnValue() + " when the value of " +
eval.getExpectedValue() + " with precision of " +
eval.getPrecision(), Project.MSG_INFO );
eval.getPrecision();
if( result.didTestPass() && !result.evaluationCompleteWithError()) {
if(showSuccessDetails) {
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 ) {

View File

@ -44,7 +44,7 @@ public abstract class POIReadOnlyDocument extends POIDocument {
*/
@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.
@ -53,7 +53,7 @@ public abstract class POIReadOnlyDocument extends POIDocument {
*/
@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.
@ -62,6 +62,10 @@ public abstract class POIReadOnlyDocument extends POIDocument {
*/
@Override
public void write(OutputStream out) {
notImplemented();
}
private static void notImplemented() {
throw new IllegalStateException("Writing is not yet implemented for this Document Format");
}
}

View File

@ -29,6 +29,7 @@ import org.apache.poi.util.POILogger;
*
* @since POI 3.17-beta2
*/
@SuppressWarnings("java:S1192")
public enum FontCharset {
/** Specifies the English character set. */
ANSI(0x00000000, "Cp1252"),

View 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),

View 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;
@ -73,61 +72,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);
}
final Ptg lastToken = tokens[numptgs-1];
StringBuilder buf = new StringBuilder();
if (lastToken instanceof ExpPtg) return;
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);
}
String buf = String.join("~",
lastToken.toFormulaString(),
mapToken(lastToken),
(numptgs > 1 ? mapToken(tokens[numptgs - 2]) : "VALUE"),
String.valueOf(lastToken instanceof FuncPtg ? numptgs-1 : -1)
);
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);
}
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 "";
}
}
/**
* Method parseFormulaRecord
*