]> source.dussan.org Git - poi.git/commitdiff
Remove unused import, IntelliJ warnings, duplicated code, improve some exception...
authorDominik Stadler <centic@apache.org>
Fri, 10 Mar 2017 20:13:39 +0000 (20:13 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 10 Mar 2017 20:13:39 +0000 (20:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1786429 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
src/java/org/apache/poi/ss/formula/functions/WeekNum.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationshipCollection.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java

index 43818cb5d6418b742b2754d8b6d295a5c1f2dc98..e09054479f1f65d9787777dcd36c0c4c3bb2bbec 100644 (file)
@@ -17,7 +17,6 @@
 
 package org.apache.poi.sl.draw;
 
-import java.awt.AlphaComposite;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
index 6ce2a7f8adff851cce86c7e8e406bd3f2c422983..d978b3c371f8528e11c73cba23427b6b508e8315 100644 (file)
@@ -585,20 +585,8 @@ public class DrawTextParagraph implements Drawable {
                     fallbackFont = font;
                 }
             } else {
-                if (fontMap != null) {
-                    if (fontMap.containsKey(mappedFont)) {
-                        mappedFont = fontMap.get(mappedFont);
-                    } else if (fontMap.containsKey("*")) {
-                        mappedFont = fontMap.get("*");
-                    }
-                }
-                if (fallbackMap != null) {
-                    if (fallbackMap.containsKey(mappedFont)) {
-                        fallbackFont = fallbackMap.get(mappedFont);
-                    } else if (fallbackMap.containsKey("*")) {
-                        fallbackFont = fallbackMap.get("*");
-                    }
-                }
+                mappedFont = getFontWithFallback(fontMap, mappedFont);
+                fallbackFont = getFontWithFallback(fallbackMap, mappedFont);
             }
             
             runText = mapFontCharset(runText,mappedFont);
@@ -688,6 +676,17 @@ public class DrawTextParagraph implements Drawable {
         return string;
     }
 
+    private String getFontWithFallback(Map<String, String> fontMap, String mappedFont) {
+        if (fontMap != null) {
+            if (fontMap.containsKey(mappedFont)) {
+                mappedFont = fontMap.get(mappedFont);
+            } else if (fontMap.containsKey("*")) {
+                mappedFont = fontMap.get("*");
+            }
+        }
+        return mappedFont;
+    }
+
     /**
      * @return {@code true} if the HSLF implementation is used
      */
index 09542312a5485957c4b1fe582cfcee63922d7d1a..3941e5bfe5cfd26e0f8254a5096c9136cef074e5 100644 (file)
@@ -47,7 +47,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {
     public static final FreeRefFunction instance = new WeekNum();
 
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) {
-        double serialNum = 0.0;
+        double serialNum;
         try {
             serialNum = NumericFunction.singleOperandEvaluate(serialNumVE, srcRowIndex, srcColumnIndex);
         } catch (EvaluationException e) {
@@ -56,7 +56,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {
         Calendar serialNumCalendar = LocaleUtil.getLocaleCalendar();
         serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
 
-        int returnType = 0;
+        int returnType;
         try {
             ValueEval ve = OperandResolver.getSingleValue(returnTypeVE, srcRowIndex, srcColumnIndex);
             returnType = OperandResolver.coerceValueToInt(ve);
index 232b38b382fd987bb454c228cafd6002ad18013d..640063802e733eeb9f8176afd2020b6be4b21713 100644 (file)
@@ -149,7 +149,7 @@ public final class PackageRelationshipCollection implements
         this();
 
         if (container == null)
-            throw new IllegalArgumentException("container");
+            throw new IllegalArgumentException("container needs to be specified");
 
         // Check if the specified part is not a relationship part
         if (part != null && part.isRelationshipPart())
@@ -379,9 +379,7 @@ public final class PackageRelationshipCollection implements
      * @return All relationships of the type specified by the filter.
      */
     public PackageRelationshipCollection getRelationships(String typeFilter) {
-        PackageRelationshipCollection coll = new PackageRelationshipCollection(
-                this, typeFilter);
-        return coll;
+        return new PackageRelationshipCollection(this, typeFilter);
     }
 
     /**
index 89bc9597ac8fe111d1d214f706165442b5e33db4..c5b5d6fa4f4f2be9bbca155d33e2597602662784 100644 (file)
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.awt.Color;
-import java.io.IOException;
-import java.util.List;
-
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLDocumentPart.RelationPart;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -42,6 +31,12 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
 import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
 
+import java.awt.Color;
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
 public class TestXSSFDrawing {
     @Test
     public void testRead() throws IOException {
@@ -628,6 +623,7 @@ public class TestXSSFDrawing {
         String paraString10 = "Fifth Bullet";
 
         XSSFTextParagraph para = shape.addNewTextParagraph(paraString1);
+        assertNotNull(para);
         para = shape.addNewTextParagraph(paraString2);
         para.setBullet(true);
 
@@ -639,6 +635,7 @@ public class TestXSSFDrawing {
         para.setBullet(true);
 
         para = shape.addNewTextParagraph(paraString5);
+        assertNotNull(para);
         para = shape.addNewTextParagraph(paraString6);
         para.setBullet(ListAutoNumber.ARABIC_PERIOD);
 
@@ -678,39 +675,38 @@ public class TestXSSFDrawing {
         List<XSSFTextParagraph> paras = sshape.getTextParagraphs();
         assertEquals(12, paras.size());  // this should be 12 as XSSFSimpleShape creates a default paragraph (no text), and then we added to that
 
-        StringBuilder builder = new StringBuilder();
-
-        builder.append(paraString1);
-        builder.append("\n");
-        builder.append("\u2022 ");
-        builder.append(paraString2);
-        builder.append("\n");
-        builder.append("\t\u2022 ");
-        builder.append(paraString3);
-        builder.append("\n");
-        builder.append("\u2022 ");
-        builder.append(paraString4);
-        builder.append("\n");
-        builder.append(paraString5);
-        builder.append("\n");
-        builder.append("1. ");
-        builder.append(paraString6);
-        builder.append("\n");
-        builder.append("\t3. ");
-        builder.append(paraString7);
-        builder.append("\n");
-        builder.append("\t4. ");
-        builder.append(paraString8);
-        builder.append("\n");
-        builder.append("\t");   // should be empty
-        builder.append("\n");
-        builder.append("\t5. ");
-        builder.append(paraString9);
-        builder.append("\n");
-        builder.append("2. ");
-        builder.append(paraString10);
-
-        assertEquals(builder.toString(), sshape.getText());
+        String builder =
+                paraString1 +
+                "\n" +
+                "\u2022 " +
+                paraString2 +
+                "\n" +
+                "\t\u2022 " +
+                paraString3 +
+                "\n" +
+                "\u2022 " +
+                paraString4 +
+                "\n" +
+                paraString5 +
+                "\n" +
+                "1. " +
+                paraString6 +
+                "\n" +
+                "\t3. " +
+                paraString7 +
+                "\n" +
+                "\t4. " +
+                paraString8 +
+                "\n" +
+                "\t" +   // should be empty
+                "\n" +
+                "\t5. " +
+                paraString9 +
+                "\n" +
+                "2. " +
+                paraString10;
+
+        assertEquals(builder, sshape.getText());
 
         checkRewrite(wb2);
         wb2.close();
@@ -727,18 +723,18 @@ public class TestXSSFDrawing {
         List<XSSFShape> shapes = drawing.getShapes();
         XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(0);
         String extracted = textbox.getText();
-        StringBuilder sb = new StringBuilder();
-        sb.append("1. content1A\n");
-        sb.append("\t1. content1B\n");
-        sb.append("\t2. content2B\n");
-        sb.append("\t3. content3B\n");
-        sb.append("2. content2A\n");
-        sb.append("\t3. content2BStartAt3\n");
-        sb.append("\t\n\t\n\t");
-        sb.append("4. content2BStartAt3Incremented\n");
-        sb.append("\t\n\t\n\t\n\t");
-
-        assertEquals(sb.toString(), extracted);
+        String sb =
+                "1. content1A\n" +
+                "\t1. content1B\n" +
+                "\t2. content2B\n" +
+                "\t3. content3B\n" +
+                "2. content2A\n" +
+                "\t3. content2BStartAt3\n" +
+                "\t\n\t\n\t" +
+                "4. content2BStartAt3Incremented\n" +
+                "\t\n\t\n\t\n\t";
+
+        assertEquals(sb, extracted);
         checkRewrite(wb);
         wb.close();
     }