poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1845434 - in /poi/trunk/src: java/org/apache/poi/ss/util/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/helpers/ ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/
Date Thu, 01 Nov 2018 10:29:54 GMT
Author: centic
Date: Thu Nov  1 10:29:54 2018
New Revision: 1845434

URL: http://svn.apache.org/viewvc?rev=1845434&view=rev
Log:
IDE warnings, tried to reproduce Bug 58927, but could not

Modified:
    poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java

Modified: poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java?rev=1845434&r1=1845433&r2=1845434&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/CellReference.java Thu Nov  1 10:29:54 2018
@@ -132,7 +132,7 @@ public class CellReference {
         if (rowRef.length() == 0) {
             _rowIndex = -1;
         } else {
-            // throws NumberFormatException if rowRef is not convertable to an int
+            // throws NumberFormatException if rowRef is not convertible to an int
             _rowIndex = Integer.parseInt(rowRef)-1; // -1 to convert 1-based to zero-based
         }
     }
@@ -336,10 +336,10 @@ public class CellReference {
             if(colStr.toUpperCase(Locale.ROOT).compareTo(lastCol) > 0) {
                 return false;
             }
-        } else {
+        } /*else {
             // apparent column name has less chars than max
             // no need to check range
-        }
+        }*/
         return true;
     }
 
@@ -426,7 +426,7 @@ public class CellReference {
         //   AreaReference.separateAreaRefs()
         //   SheetNameFormatter.format() (inverse)
 
-        StringBuffer sb = new StringBuffer(indexOfSheetNameDelimiter);
+        StringBuilder sb = new StringBuilder(indexOfSheetNameDelimiter);
 
         for(int i=1; i<lastQuotePos; i++) { // Note boundaries - skip outer quotes
             char ch = reference.charAt(i);
@@ -495,11 +495,7 @@ public class CellReference {
 
     @Override
     public String toString() {
-        StringBuffer sb = new StringBuffer(64);
-        sb.append(getClass().getName()).append(" [");
-        sb.append(formatAsString());
-        sb.append("]");
-        return sb.toString();
+        return getClass().getName() + " [" + formatAsString() + "]";
     }
 
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1845434&r1=1845433&r2=1845434&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Thu Nov  1 10:29:54
2018
@@ -147,6 +147,7 @@ import org.openxmlformats.schemas.spread
  * contain text, numbers, dates, and formulas. Cells can also be formatted.
  * </p>
  */
+@SuppressWarnings("deprecation")
 public class XSSFSheet extends POIXMLDocumentPart implements Sheet  {
     private static final POILogger logger = POILogFactory.getLogger(XSSFSheet.class);
 
@@ -472,7 +473,7 @@ public class XSSFSheet extends POIXMLDoc
     /**
      * Verify that candidate region does not intersect with an existing merged region in
this sheet
      *
-     * @param candidateRegion
+     * @param candidateRegion the range of cells to verify
      * @throws IllegalStateException if candidate region intersects an existing merged region
in this sheet (or candidateRegion is already merged in this sheet)
      */
     private void validateMergedRegions(CellRangeAddress candidateRegion) {
@@ -855,8 +856,8 @@ public class XSSFSheet extends POIXMLDoc
     /**
      * Get a Hyperlink in this sheet anchored at row, column
      *
-     * @param row
-     * @param column
+     * @param row The row where the hyperlink is anchored
+     * @param column The column where the hyperlinkn is anchored
      * @return hyperlink if there is a hyperlink anchored at row, column; otherwise returns
null
      */
     @Override
@@ -1480,8 +1481,9 @@ public class XSSFSheet extends POIXMLDoc
      *
      * @param startRowNum the first row number in this sheet to return
      * @param endRowNum the last row number in this sheet to return
-     * @param createRowIfMissing
-     * @return All rows between startRow and endRow, inclusive
+     * @param createRowIfMissing If missing rows should be created.
+     * @return All rows between startRow and endRow, inclusive. If createRowIfMissing is
false,
+     *      only previously existing rows are returned, otherwise empty rows are added as
necessary
      * @throws IllegalArgumentException if startRowNum and endRowNum are not in ascending
order
      */
     private List<XSSFRow> getRows(int startRowNum, int endRowNum, boolean createRowIfMissing)
{
@@ -2472,7 +2474,7 @@ public class XSSFSheet extends POIXMLDoc
      * 'Collapsed' state is stored in a single column col info record
      * immediately after the outline group
      *
-     * @param idx
+     * @param idx The column-index to check
      * @return a boolean represented if the column is collapsed
      */
     private boolean isColumnGroupCollapsed(int idx) {
@@ -3052,7 +3054,7 @@ public class XSSFSheet extends POIXMLDoc
         rebuildRows();
     }
 
-    private final void rebuildRows() {
+    private void rebuildRows() {
         //rebuild the _rows map
         List<XSSFRow> rowList = new ArrayList<>(_rows.values());
         _rows.clear();
@@ -3114,25 +3116,22 @@ public class XSSFSheet extends POIXMLDoc
         // then do the actual moving and also adjust comments/rowHeight
         // we need to sort it in a way so the shifting does not mess up the structures,
         // i.e. when shifting down, start from down and go up, when shifting up, vice-versa
-        SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<>(new Comparator<XSSFComment>()
{
-            @Override
-            public int compare(XSSFComment o1, XSSFComment o2) {
-                int row1 = o1.getRow();
-                int row2 = o2.getRow();
-
-                if (row1 == row2) {
-                    // ordering is not important when row is equal, but don't return zero
to still
-                    // get multiple comments per row into the map
-                    return o1.hashCode() - o2.hashCode();
-                }
+        SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<>((o1,
o2) -> {
+            int row1 = o1.getRow();
+            int row2 = o2.getRow();
+
+            if (row1 == row2) {
+                // ordering is not important when row is equal, but don't return zero to
still
+                // get multiple comments per row into the map
+                return o1.hashCode() - o2.hashCode();
+            }
 
-                // when shifting down, sort higher row-values first
-                if (n > 0) {
-                    return row1 < row2 ? 1 : -1;
-                } else {
-                    // sort lower-row values first when shifting up
-                    return row1 > row2 ? 1 : -1;
-                }
+            // when shifting down, sort higher row-values first
+            if (n > 0) {
+                return row1 < row2 ? 1 : -1;
+            } else {
+                // sort lower-row values first when shifting up
+                return row1 > row2 ? 1 : -1;
             }
         });
 
@@ -3211,25 +3210,22 @@ public class XSSFSheet extends POIXMLDoc
         // then do the actual moving and also adjust comments/rowHeight
         // we need to sort it in a way so the shifting does not mess up the structures, 
         // i.e. when shifting down, start from down and go up, when shifting up, vice-versa
-        SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<>(new Comparator<XSSFComment>()
{
-            @Override
-            public int compare(XSSFComment o1, XSSFComment o2) {
-                int column1 = o1.getColumn();
-                int column2 = o2.getColumn();
-
-                if (column1 == column2) {
-                    // ordering is not important when row is equal, but don't return zero
to still 
-                    // get multiple comments per row into the map
-                    return o1.hashCode() - o2.hashCode();
-                }
+        SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<>((o1,
o2) -> {
+            int column1 = o1.getColumn();
+            int column2 = o2.getColumn();
+
+            if (column1 == column2) {
+                // ordering is not important when row is equal, but don't return zero to
still
+                // get multiple comments per row into the map
+                return o1.hashCode() - o2.hashCode();
+            }
 
-                // when shifting down, sort higher row-values first
-                if (n > 0) {
-                    return column1 < column2 ? 1 : -1;
-                } else {
-                    // sort lower-row values first when shifting up
-                    return column1 > column2 ? 1 : -1;
-                }
+            // when shifting down, sort higher row-values first
+            if (n > 0) {
+                return column1 < column2 ? 1 : -1;
+            } else {
+                // sort lower-row values first when shifting up
+                return column1 > column2 ? 1 : -1;
             }
         });
 
@@ -4096,7 +4092,7 @@ public class XSSFSheet extends POIXMLDoc
      * Creates a new Table, and associates it with this Sheet.
      *
      * @param tableArea
-     *            the area that the table should cover, should not be {@null}
+     *            the area that the table should cover, should not be null
      * @return the created table
      * @since 4.0.0
      */
@@ -4421,18 +4417,15 @@ public class XSSFSheet extends POIXMLDoc
                     + "defined source sheet " + sourceSheet.getSheetName() + ".");
         }
 
-        return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator()
{
-            @Override
-            public void configureReference(CTWorksheetSource wsSource) {
-                final String[] firstCell = source.getFirstCell().getCellRefParts();
-                final String firstRow = firstCell[1];
-                final String firstCol = firstCell[2];
-                final String[] lastCell = source.getLastCell().getCellRefParts();
-                final String lastRow = lastCell[1];
-                final String lastCol = lastCell[2];
-                final String ref = firstCol+firstRow+':'+lastCol+lastRow; //or just source.formatAsString()
-                wsSource.setRef(ref);
-            }
+        return createPivotTable(position, sourceSheet, wsSource -> {
+            final String[] firstCell = source.getFirstCell().getCellRefParts();
+            final String firstRow = firstCell[1];
+            final String firstCol = firstCell[2];
+            final String[] lastCell = source.getLastCell().getCellRefParts();
+            final String lastRow = lastCell[1];
+            final String lastCol = lastCell[2];
+            final String ref = firstCol+firstRow+':'+lastCol+lastRow; //or just source.formatAsString()
+            wsSource.setRef(ref);
         });
     }
 
@@ -4494,12 +4487,7 @@ public class XSSFSheet extends POIXMLDoc
                     + "defined source sheet " + sourceSheet.getSheetName() + ".");
         }
 
-        return createPivotTable(position, sourceSheet, new PivotTableReferenceConfigurator()
{
-            @Override
-            public void configureReference(CTWorksheetSource wsSource) {
-                wsSource.setName(source.getNameName());
-            }
-        });
+        return createPivotTable(position, sourceSheet, wsSource -> wsSource.setName(source.getNameName()));
     }
 
     /**
@@ -4523,12 +4511,7 @@ public class XSSFSheet extends POIXMLDoc
      */
     @Beta
     public XSSFPivotTable createPivotTable(final Table source, CellReference position) {
-        return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()),
new PivotTableReferenceConfigurator() {
-            @Override
-            public void configureReference(CTWorksheetSource wsSource) {
-                wsSource.setName(source.getName());
-            }
-        });
+        return createPivotTable(position, getWorkbook().getSheet(source.getSheetName()),
wsSource -> wsSource.setName(source.getName()));
     }
 
     /**
@@ -4621,7 +4604,7 @@ public class XSSFSheet extends POIXMLDoc
 
     /**
      *  when a cell with a 'master' shared formula is removed,  the next cell in the range
becomes the master
-     * @param cell 
+     * @param cell The cell that is removed
      * @param evalWb BaseXSSFEvaluationWorkbook in use, if one exists
      */
     protected void onDeleteFormula(XSSFCell cell, BaseXSSFEvaluationWorkbook evalWb){

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java?rev=1845434&r1=1845433&r2=1845434&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java Thu Nov
 1 10:29:54 2018
@@ -50,7 +50,7 @@ public class ColumnHelper {
         TreeSet<CTCol> trackedCols = new TreeSet<>(CTColComparator.BY_MIN_MAX);
         CTCols newCols = CTCols.Factory.newInstance();
         CTCols[] colsArray = worksheet.getColsArray();
-        int i = 0;
+        int i;
         for (i = 0; i < colsArray.length; i++) {
             CTCols cols = colsArray[i];
             for (CTCol col : cols.getColList()) {
@@ -61,7 +61,7 @@ public class ColumnHelper {
             worksheet.removeCols(y);
         }
         
-        newCols.setColArray(trackedCols.toArray(new CTCol[trackedCols.size()]));
+        newCols.setColArray(trackedCols.toArray(new CTCol[0]));
         worksheet.addNewCols();
         worksheet.setColsArray(0, newCols);
     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java?rev=1845434&r1=1845433&r2=1845434&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
Thu Nov  1 10:29:54 2018
@@ -25,6 +25,9 @@ import static org.junit.Assert.assertTru
 
 import java.io.IOException;
 
+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.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -192,14 +195,14 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsExactOverlap() throws Exception {
+    public void testAddCleanColIntoColsExactOverlap() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1);
         assertEquals(1, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true);
     }
 
     @Test
-    public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception {
+    public void testAddCleanColIntoColsOverlapsOverhangingBothSides() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);
         assertEquals(3, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -208,7 +211,7 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
+    public void testAddCleanColIntoColsOverlapsCompletelyNested() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
         assertEquals(3, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
@@ -217,7 +220,7 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws
Exception {
+    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
         assertEquals(2, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -225,7 +228,7 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws
Exception {
+    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
         assertEquals(2, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 2, true, true);
@@ -233,7 +236,7 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception
{
+    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
         assertEquals(3, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
@@ -242,7 +245,7 @@ public final class TestColumnHelper {
     }
 
     @Test
-    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception
{
+    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() {
         CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
         assertEquals(3, cols.sizeOfColArray());
         assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
@@ -402,4 +405,36 @@ public final class TestColumnHelper {
         }
         return count;
     }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testColumnsCollapsed() {
+        Workbook wb = new XSSFWorkbook();
+        Sheet sheet = wb.createSheet("test");
+        Row row = sheet.createRow(0);
+        row.createCell(0);
+        row.createCell(1);
+        row.createCell(2);
+
+        sheet.setColumnWidth(0, 10);
+        sheet.setColumnWidth(1, 10);
+        sheet.setColumnWidth(2, 10);
+
+        sheet.groupColumn(0, 1);
+        sheet.setColumnGroupCollapsed(0, true);
+
+        CTCols ctCols = ((XSSFSheet) sheet).getCTWorksheet().getColsArray()[0];
+        assertEquals(3, ctCols.sizeOfColArray());
+        assertTrue(ctCols.getColArray(0).isSetCollapsed());
+        assertTrue(ctCols.getColArray(1).isSetCollapsed());
+        assertTrue(ctCols.getColArray(2).isSetCollapsed());
+
+        ColumnHelper helper = new ColumnHelper(CTWorksheet.Factory.newInstance());
+        helper.setColumnAttributes(ctCols.getColArray(1), ctCols.getColArray(2));
+
+        ctCols = ((XSSFSheet) sheet).getCTWorksheet().getColsArray()[0];
+        assertTrue(ctCols.getColArray(0).isSetCollapsed());
+        assertTrue(ctCols.getColArray(1).isSetCollapsed());
+        assertTrue(ctCols.getColArray(2).isSetCollapsed());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message