diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-12-20 23:39:40 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-12-20 23:39:40 +0000 |
commit | 6aea287542d921e8813a1735d381d2d5f2d6c60a (patch) | |
tree | 1ab0efb9ed67cd765311f7de777f1daa8c29945f /poi-examples | |
parent | f3b51d41a43e4401f2dcf1f6400a021c9f6bfaf7 (diff) | |
download | poi-6aea287542d921e8813a1735d381d2d5f2d6c60a.tar.gz poi-6aea287542d921e8813a1735d381d2d5f2d6c60a.zip |
some spotbugs issues
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896204 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-examples')
3 files changed, 11 insertions, 18 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/AddDimensionedImage.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/AddDimensionedImage.java index 35ad3b7508..2611b5a6e4 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/AddDimensionedImage.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/AddDimensionedImage.java @@ -860,7 +860,7 @@ public class AddDimensionedImage { * * @version 1.00 5th August 2009. */ - public class ClientAnchorDetail { + public static class ClientAnchorDetail { private int fromIndex; private int toIndex; diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/ExcelComparator.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/ExcelComparator.java index 069aef0ebe..109226889e 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/ExcelComparator.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/ExcelComparator.java @@ -19,12 +19,7 @@ package org.apache.poi.examples.ss; import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Objects; +import java.util.*; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.Cell; @@ -96,7 +91,7 @@ public class ExcelComparator { Cell cell; } - List<String> listOfDifferences = new ArrayList<>(); + private List<String> listOfDifferences = new ArrayList<>(); private final DateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ROOT); @@ -133,7 +128,7 @@ public class ExcelComparator { excelComparator.compareSheetNames(loc1, loc2); excelComparator.compareSheetData(loc1, loc2); - return excelComparator.listOfDifferences; + return Collections.unmodifiableList(excelComparator.listOfDifferences); } /** @@ -248,7 +243,7 @@ public class ExcelComparator { int num2 = (ri2.hasNext()) ? ri2.next().getPhysicalNumberOfCells() : 0; if (num1 != num2) { - String str = String.format(Locale.ROOT, "%s\nworkbook1 -> %s [%d] != workbook2 -> %s [%d]", + String str = String.format(Locale.ROOT, "%s%nworkbook1 -> %s [%d] != workbook2 -> %s [%d]", "Number Of Columns does not Match ::", loc1.sheet.getSheetName(), num1, loc2.sheet.getSheetName(), num2 @@ -274,7 +269,7 @@ public class ExcelComparator { int num2 = loc2.sheet.getPhysicalNumberOfRows(); if (num1 != num2) { - String str = String.format(Locale.ROOT, "%s\nworkbook1 -> %s [%d] != workbook2 -> %s [%d]", + String str = String.format(Locale.ROOT, "%s%nworkbook1 -> %s [%d] != workbook2 -> %s [%d]", "Number Of Rows does not Match ::", loc1.sheet.getSheetName(), num1, loc2.sheet.getSheetName(), num2 @@ -292,7 +287,7 @@ public class ExcelComparator { int num1 = loc1.workbook.getNumberOfSheets(); int num2 = loc2.workbook.getNumberOfSheets(); if (num1 != num2) { - String str = String.format(Locale.ROOT, "%s\nworkbook1 [%d] != workbook2 [%d]", + String str = String.format(Locale.ROOT, "%s%nworkbook1 [%d] != workbook2 [%d]", "Number of Sheets do not match ::", num1, num2 ); @@ -321,7 +316,7 @@ public class ExcelComparator { 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]", + 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 ); listOfDifferences.add(str); @@ -334,7 +329,7 @@ public class ExcelComparator { */ private void addMessage(Locator loc1, Locator loc2, String messageStart, String value1, String value2) { String str = - String.format(Locale.ROOT, "%s\nworkbook1 -> %s -> %s [%s] != workbook2 -> %s -> %s [%s]", + String.format(Locale.ROOT, "%s%nworkbook1 -> %s -> %s [%s] != workbook2 -> %s -> %s [%s]", messageStart, loc1.sheet.getSheetName(), new CellReference(loc1.cell).formatAsString(), value1, loc2.sheet.getSheetName(), new CellReference(loc2.cell).formatAsString(), value2 diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/SSPerformanceTest.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/SSPerformanceTest.java index c041509d45..0c0e440357 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/SSPerformanceTest.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/SSPerformanceTest.java @@ -77,7 +77,7 @@ public final class SSPerformanceTest { runWithArgs(type, rows, cols, saveFile); long timeFinished = System.currentTimeMillis(); - System.out.printf(Locale.ROOT, "Elapsed %.2f seconds for arguments %s\n", ((double)timeFinished - timeStarted) / 1000, Arrays.toString(args)); + System.out.printf(Locale.ROOT, "Elapsed %.2f seconds for arguments %s%n", ((double)timeFinished - timeStarted) / 1000, Arrays.toString(args)); } private static void runWithArgs(String type, int rows, int cols, boolean saveFile) throws IOException { @@ -170,10 +170,8 @@ public final class SSPerformanceTest { } private static void saveFile(Workbook workBook, String fileName) { - try { - FileOutputStream out = new FileOutputStream(fileName); + try (FileOutputStream out = new FileOutputStream(fileName)) { workBook.write(out); - out.close(); } catch (IOException ioe) { System.err.println("Error: failed to write to file \"" + fileName + "\", reason=" + ioe.getMessage()); } |