]> source.dussan.org Git - poi.git/commitdiff
sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Tue, 29 Sep 2015 08:31:15 +0000 (08:31 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Tue, 29 Sep 2015 08:31:15 +0000 (08:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705814 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
src/java/org/apache/poi/hpsf/Section.java
src/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureData.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
src/scratchpad/src/org/apache/poi/hssf/converter/AbstractExcelConverter.java
src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToFoConverter.java
src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlConverter.java

index 23779d3059c315ce0346ca2d74e756ff57964b3a..e15b4ec0be87736a24c946996b14f10af5a84481 100644 (file)
@@ -185,15 +185,10 @@ public class XLSX2CSV {
                     //  with a special style or format 
                     int styleIndex = Integer.parseInt(cellStyleStr);
                     XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
-                    if (style == null && stylesTable.getNumCellStyles() > 0) {
-                        style = stylesTable.getStyleAt(0);
-                    }
-                    if (style != null) {
-                        this.formatIndex = style.getDataFormat();
-                        this.formatString = style.getDataFormatString();
-                        if (this.formatString == null) {
-                            this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
-                        }
+                    this.formatIndex = style.getDataFormat();
+                    this.formatString = style.getDataFormatString();
+                    if (this.formatString == null) {
+                        this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex);
                     }
                 }
             }
index 3c8e5b7ce8e433b109f785ccbbd152d2f69f8493..eeed53e4c31988cbfc175d174e30601029ca9103 100644 (file)
@@ -447,12 +447,12 @@ public class Section
     public String getPIDString(final long pid)
     {
         String s = null;
-        if (dictionary != null)
+        if (dictionary != null) {
             s = dictionary.get(Long.valueOf(pid));
-        if (s == null)
+        }
+        if (s == null) {
             s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid);
-        if (s == null)
-            s = SectionIDMap.UNDEFINED;
+        }
         return s;
     }
 
index 42571f1c2b8433c069b53e7631d8e515d97316e3..b270182a0fb3b947141b0750d06e8609bc7ac5e5 100644 (file)
@@ -358,18 +358,11 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
                                                                                        }
                                                                                        break;
                                                                                case HSSFCell.CELL_TYPE_NUMERIC:
-                                                                                  HSSFCellStyle style = cell.getCellStyle();
-                                                                                  if(style == null) {
-                                                                                     text.append( cell.getNumericCellValue() );
-                                                                                  } else {
-                                        text.append(
-                                              _formatter.formatRawCellContents(
-                                                    cell.getNumericCellValue(),
-                                                    style.getDataFormat(),
-                                                    style.getDataFormatString()
-                                              )
-                                        );
-                                                                                  }
+                                                                                       HSSFCellStyle style = cell.getCellStyle();
+                                                                                       double nVal = cell.getNumericCellValue();
+                                                                                       short df = style.getDataFormat();
+                                                                                       String dfs = style.getDataFormatString();
+                                                                                       text.append(_formatter.formatRawCellContents(nVal, df, dfs));
                                                                                        break;
                                                                                case HSSFCell.CELL_TYPE_BOOLEAN:
                                                                                        text.append(cell.getBooleanCellValue());
index c38d027ba2b823c2a51014bea38724e0c5925477..5cb8d6f3330af327ab4267ab17511667a482508c 100644 (file)
@@ -107,9 +107,6 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
      */
     public String getFileName() {
         String name = getPackagePart().getPartName().getName();
-        if (name == null) {
-            return null;
-        }
         return name.substring(name.lastIndexOf('/') + 1);
     }
 
index 06dec8da55bdf27ee924c92143e296afa35492cc..ba819ce63477bd3360fa98195d8d803eadd1da4d 100644 (file)
@@ -259,8 +259,7 @@ public final class XSSFCell implements Cell {
      */
     @Override
     public String getStringCellValue() {
-        XSSFRichTextString str = getRichStringCellValue();
-        return str == null ? null : str.getString();
+        return getRichStringCellValue().getString();
     }
 
     /**
index 0085fddb64ba220e5e0db668e16cdbe9d94b583e..549ae813de780ed4a88e62c4d5e71922522c8a7c 100644 (file)
@@ -112,9 +112,6 @@ public class XWPFPictureData extends POIXMLDocumentPart {
      */
     public String getFileName() {
         String name = getPackagePart().getPartName().getName();
-        if (name == null) {
-            return null;
-        }
         return name.substring(name.lastIndexOf('/') + 1);
     }
 \r
index fc1302f0aad5e4643b221747b688c44a49067d73..fd4c3dc03d1f213434e57523f662993d0445ba72 100644 (file)
@@ -139,14 +139,10 @@ public abstract class AbstractExcelConverter
                 break;
             case HSSFCell.CELL_TYPE_NUMERIC:
                 HSSFCellStyle style = cell.getCellStyle();
-                if ( style == null )
-                {
-                    return false;
-                }
-
-                value = ( _formatter.formatRawCellContents(
-                        cell.getNumericCellValue(), style.getDataFormat(),
-                        style.getDataFormatString() ) );
+                double nval = cell.getNumericCellValue();
+                short df = style.getDataFormat();
+                String dfs = style.getDataFormatString();
+                value = _formatter.formatRawCellContents(nval, df, dfs);
                 break;
             case HSSFCell.CELL_TYPE_BOOLEAN:
                 value = String.valueOf( cell.getBooleanCellValue() );
index 3cce5eebc1f1ca0c82033319a605585aba7eb3a8..f5ba5f1ea028c1a3f035bec0e6d96b0837447aec 100644 (file)
@@ -228,13 +228,9 @@ public class ExcelToFoConverter extends AbstractExcelConverter
                 break;
             case HSSFCell.CELL_TYPE_NUMERIC:
                 double nValue = cell.getNumericCellValue();
-                if ( cellStyle == null ) {
-                    value = Double.toString( nValue );
-                } else {
-                    short df = cellStyle.getDataFormat();
-                    String dfs = cellStyle.getDataFormatString();
-                    value = _formatter.formatRawCellContents(nValue, df, dfs );
-                }
+                short df = cellStyle.getDataFormat();
+                String dfs = cellStyle.getDataFormatString();
+                value = _formatter.formatRawCellContents(nValue, df, dfs );
                 break;
             case HSSFCell.CELL_TYPE_BOOLEAN:
                 value = Boolean.toString( cell.getBooleanCellValue() );
@@ -270,7 +266,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter
         }
 
         final boolean noText = ExcelToHtmlUtils.isEmpty( value );
-        final boolean wrapInDivs = !noText && (cellStyle == null || !cellStyle.getWrapText());
+        final boolean wrapInDivs = !noText && !cellStyle.getWrapText();
 
         final boolean emptyStyle = isEmptyStyle( cellStyle );
         if ( !emptyStyle && noText ) {
index 1805b156653d8cf319a79e4f433b246418732621..b16a961fbfa9e92860f715351351d4874ef3a101 100644 (file)
@@ -313,13 +313,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
                 break;
             case HSSFCell.CELL_TYPE_NUMERIC:
                 double nValue = cell.getNumericCellValue();
-                if ( cellStyle == null ) {
-                    value = Double.toString(nValue);
-                } else {
-                    short df = cellStyle.getDataFormat();
-                    String dfs = cellStyle.getDataFormatString();
-                    value = _formatter.formatRawCellContents(nValue, df, dfs);
-                }
+                short df = cellStyle.getDataFormat();
+                String dfs = cellStyle.getDataFormatString();
+                value = _formatter.formatRawCellContents(nValue, df, dfs);
                 break;
             case HSSFCell.CELL_TYPE_BOOLEAN:
                 value = String.valueOf( cell.getBooleanCellValue() );
@@ -355,10 +351,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
         }
 
         final boolean noText = ExcelToHtmlUtils.isEmpty( value );
-        final boolean wrapInDivs = !noText && isUseDivsToSpan()
-                && (cellStyle == null || !cellStyle.getWrapText());
+        final boolean wrapInDivs = !noText && isUseDivsToSpan() && !cellStyle.getWrapText();
 
-        if ( cellStyle != null && cellStyle.getIndex() != 0 )
+        if ( cellStyle.getIndex() != 0 )
         {
             @SuppressWarnings("resource")
             HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook();
@@ -418,9 +413,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
             innerDivStyle.append( "overflow:hidden;max-height:" );
             innerDivStyle.append( normalHeightPt );
             innerDivStyle.append( "pt;white-space:nowrap;" );
-            if (cellStyle != null) {
-                ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() );
-            }
+            ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() );
             htmlDocumentFacade.addStyleClass( outerDiv, cssClassPrefixDiv,
                     innerDivStyle.toString() );
 
@@ -433,7 +426,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
             tableCellElement.appendChild( text );
         }
 
-        return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle == null || cellStyle.getIndex() == 0);
+        return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle.getIndex() == 0);
     }
 
     protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns,