diff options
author | Dominik Stadler <centic@apache.org> | 2019-12-14 13:10:12 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2019-12-14 13:10:12 +0000 |
commit | 57b0576f63fffcbc55afc58e3e9d186d2d8c4e72 (patch) | |
tree | 526b31670569a1071223c717a81b2f56e500ea11 /src/ooxml | |
parent | 4c034f0e202ab6c3a56a2c30716d2c56f9be3311 (diff) | |
download | poi-57b0576f63fffcbc55afc58e3e9d186d2d8c4e72.tar.gz poi-57b0576f63fffcbc55afc58e3e9d186d2d8c4e72.zip |
Adjust some JavaDoc and fix some IDE warnings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871505 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
7 files changed, 41 insertions, 28 deletions
diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java b/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java index dbdd5c0a14..d972476d63 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java @@ -35,6 +35,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.MessageDigest; import java.security.SecureRandom; @@ -381,7 +382,7 @@ public class AgileEncryptor extends Encryptor implements Cloneable { xo.setSaveNoXmlDecl(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { - bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes("UTF-8")); + bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes(StandardCharsets.UTF_8)); ed.save(bos, xo); bos.writeTo(os); } catch (IOException e) { diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index c7dbc40afe..2139111f5d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -915,13 +915,13 @@ public class SXSSFSheet implements Sheet * Sets desktop window pane display area, when the * file is first opened in a viewer. * - * @param toprow the top row to show in desktop window pane - * @param leftcol the left column to show in desktop window pane + * @param topRow the top row to show in desktop window pane + * @param leftCol the left column to show in desktop window pane */ @Override - public void showInPane(int toprow, int leftcol) + public void showInPane(int topRow, int leftCol) { - _sh.showInPane(toprow, leftcol); + _sh.showInPane(topRow, leftCol); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index 30a9c4ec62..560dae8c23 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -29,6 +29,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; @@ -103,7 +104,7 @@ public class SheetDataWriter implements Closeable { throw e; } return new BufferedWriter( - new OutputStreamWriter(decorated, "UTF-8")); + new OutputStreamWriter(decorated, StandardCharsets.UTF_8)); } /** @@ -113,7 +114,7 @@ public class SheetDataWriter implements Closeable { * * @param fos the stream to decorate * @return a decorated stream - * @throws IOException + * @throws IOException if decorating the stream fails * @see #decorateInputStream(FileInputStream) */ protected OutputStream decorateOutputStream(FileOutputStream fos) throws IOException { @@ -154,7 +155,7 @@ public class SheetDataWriter implements Closeable { * * @param fis the stream to decorate * @return a decorated stream - * @throws IOException + * @throws IOException if decorating the stream fails * @see #decorateOutputStream(FileOutputStream) */ protected InputStream decorateInputStream(FileInputStream fis) throws IOException { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index cc29353371..dcbe55cbd2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -267,6 +267,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { for (CTRow row : worksheetParam.getSheetData().getRowArray()) { XSSFRow r = new XSSFRow(row, this); // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rownumI = Integer.valueOf(r.getRowNum()); // NOSONAR _rows.put(rownumI, r); } @@ -756,6 +757,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public XSSFRow createRow(int rownum) { // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rownumI = Integer.valueOf(rownum); // NOSONAR CTRow ctRow; XSSFRow prev = _rows.get(rownumI); @@ -1073,7 +1075,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public boolean isDisplayZeros(){ final CTSheetView dsv = getDefaultSheetView(false); - return (dsv != null) ? dsv.getShowZeros() : true; + return (dsv == null) || dsv.getShowZeros(); } /** @@ -1380,7 +1382,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { if (pane.isSetTopLeftCell()) { final CellReference cellRef = new CellReference(pane.getTopLeftCell()); row = (short)cellRef.getRow(); - col = (short)cellRef.getCol(); + col = cellRef.getCol(); } final short x = (short)pane.getXSplit(); @@ -1477,6 +1479,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public XSSFRow getRow(int rownum) { // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rownumI = Integer.valueOf(rownum); // NOSONAR return _rows.get(rownumI); } @@ -1509,7 +1512,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } else { // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer startI = Integer.valueOf(startRowNum); // NOSONAR + //noinspection UnnecessaryBoxing final Integer endI = Integer.valueOf(endRowNum+1); // NOSONAR final Collection<XSSFRow> inclusive = _rows.subMap(startI, endI).values(); rows.addAll(inclusive); @@ -1774,7 +1779,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public boolean isDisplayFormulas() { final CTSheetView dsv = getDefaultSheetView(false); - return (dsv != null) ? dsv.getShowFormulas() : false; + return dsv != null && dsv.getShowFormulas(); } /** @@ -1787,7 +1792,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public boolean isDisplayGridlines() { final CTSheetView dsv = getDefaultSheetView(false); - return (dsv != null) ? dsv.getShowGridLines() : true; + return (dsv == null) || dsv.getShowGridLines(); } /** @@ -1820,7 +1825,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public boolean isDisplayRowColHeadings() { final CTSheetView dsv = getDefaultSheetView(false); - return (dsv != null) ? dsv.getShowRowColHeaders() : true; + return (dsv == null) || dsv.getShowRowColHeaders(); } /** @@ -2017,8 +2022,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { row.removeCell(cell); } - // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory final int rowNum = row.getRowNum(); + // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rowNumI = Integer.valueOf(rowNum); // NOSONAR // this is not the physical row number! final int idx = _rows.headMap(rowNumI).size(); @@ -2272,8 +2278,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } private void unsetCollapsed(Boolean collapsed, CTCol ci) { - if (collapsed != null && collapsed.booleanValue()) { - ci.setCollapsed(collapsed); + if (collapsed != null && collapsed) { + ci.setCollapsed(true); } else { ci.unsetCollapsed(); } @@ -3067,6 +3073,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { _rows.clear(); for(XSSFRow r : rowList) { // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR _rows.put(rownumI, r); } @@ -3082,6 +3089,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { if (shouldRemoveRow(startRow, endRow, n, rownum)) { // remove row from worksheet.getSheetData row array // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory + //noinspection UnnecessaryBoxing final Integer rownumI = Integer.valueOf(row.getRowNum()); // NOSONAR int idx = _rows.headMap(rownumI).size(); worksheet.getSheetData().removeRow(idx); @@ -3266,12 +3274,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { * Location of the top left visible cell Location of the top left visible cell in the bottom right * pane (when in Left-to-Right mode). * - * @param toprow the top row to show in desktop window pane - * @param leftcol the left column to show in desktop window pane + * @param topRow the top row to show in desktop window pane + * @param leftCol the left column to show in desktop window pane */ @Override - public void showInPane(int toprow, int leftcol) { - final CellReference cellReference = new CellReference(toprow, leftcol); + public void showInPane(int topRow, int leftCol) { + final CellReference cellReference = new CellReference(topRow, leftCol); final String cellRef = cellReference.formatAsString(); final CTPane pane = getPane(true); assert(pane != null); @@ -3357,7 +3365,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { @Override public boolean isSelected() { final CTSheetView dsv = getDefaultSheetView(false); - return (dsv != null) ? dsv.getTabSelected() : false; + return dsv != null && dsv.getTabSelected(); } /** @@ -3516,8 +3524,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { if (n > 0 && rownum > endRow) { return true; } - else if (n < 0 && rownum < startRow) { - return true; + else { + return n < 0 && rownum < startRow; } } return false; @@ -4711,7 +4719,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { break; } } - return (coo == null) ? null : coo; + return coo; } finally { cur.dispose(); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java index 2e4de97ebe..27645c55af 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java @@ -20,6 +20,7 @@ package org.apache.poi.xssf.model; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -252,7 +253,7 @@ public final class TestSharedStringsTable extends TestCase { List<String> strs = new ArrayList<>(); POIDataSamples samples = POIDataSamples.getSpreadSheetInstance(); BufferedReader br = new BufferedReader( - new InputStreamReader(samples.openResourceAsStream(filename), "UTF-8")); + new InputStreamReader(samples.openResourceAsStream(filename), StandardCharsets.UTF_8)); String s; while ((s = br.readLine()) != null) { if (s.trim().length() > 0) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSheetDataWriter.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSheetDataWriter.java index dc1b7a1d65..f2c3d85f6f 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSheetDataWriter.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSheetDataWriter.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import org.apache.poi.util.IOUtils; import org.junit.Test; @@ -63,7 +64,7 @@ public final class TestSheetDataWriter { FileInputStream is = new FileInputStream(file); String text; try { - text = new String(IOUtils.toByteArray(is), "UTF-8"); + text = new String(IOUtils.toByteArray(is), StandardCharsets.UTF_8); } finally { is.close(); } @@ -82,7 +83,7 @@ public final class TestSheetDataWriter { FileInputStream is = new FileInputStream(file); String text; try { - text = new String(IOUtils.toByteArray(is), "UTF-8"); + text = new String(IOUtils.toByteArray(is), StandardCharsets.UTF_8); } finally { is.close(); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 652644b7ca..b0a5474040 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -33,6 +33,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -697,7 +698,7 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook { sheetBack.commit(); - String str = new String(IOUtils.toByteArray(sheetBack.getPackagePart().getInputStream()), "UTF-8"); + String str = new String(IOUtils.toByteArray(sheetBack.getPackagePart().getInputStream()), StandardCharsets.UTF_8); assertEquals(1, countMatches(str, "<worksheet")); } |