Remove unused import, IntelliJ warnings, duplicated code, improve some exception-texts

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1786429 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-03-10 20:13:39 +00:00
parent 566ec2d487
commit aafdbdfdd7
5 changed files with 67 additions and 75 deletions

View File

@ -17,7 +17,6 @@
package org.apache.poi.sl.draw; package org.apache.poi.sl.draw;
import java.awt.AlphaComposite;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;

View File

@ -585,20 +585,8 @@ public class DrawTextParagraph implements Drawable {
fallbackFont = font; fallbackFont = font;
} }
} else { } else {
if (fontMap != null) { mappedFont = getFontWithFallback(fontMap, mappedFont);
if (fontMap.containsKey(mappedFont)) { fallbackFont = getFontWithFallback(fallbackMap, 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("*");
}
}
} }
runText = mapFontCharset(runText,mappedFont); runText = mapFontCharset(runText,mappedFont);
@ -688,6 +676,17 @@ public class DrawTextParagraph implements Drawable {
return string; 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 * @return {@code true} if the HSLF implementation is used
*/ */

View File

@ -47,7 +47,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {
public static final FreeRefFunction instance = new WeekNum(); public static final FreeRefFunction instance = new WeekNum();
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) { public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval serialNumVE, ValueEval returnTypeVE) {
double serialNum = 0.0; double serialNum;
try { try {
serialNum = NumericFunction.singleOperandEvaluate(serialNumVE, srcRowIndex, srcColumnIndex); serialNum = NumericFunction.singleOperandEvaluate(serialNumVE, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) { } catch (EvaluationException e) {
@ -56,7 +56,7 @@ public class WeekNum extends Fixed2ArgFunction implements FreeRefFunction {
Calendar serialNumCalendar = LocaleUtil.getLocaleCalendar(); Calendar serialNumCalendar = LocaleUtil.getLocaleCalendar();
serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false)); serialNumCalendar.setTime(DateUtil.getJavaDate(serialNum, false));
int returnType = 0; int returnType;
try { try {
ValueEval ve = OperandResolver.getSingleValue(returnTypeVE, srcRowIndex, srcColumnIndex); ValueEval ve = OperandResolver.getSingleValue(returnTypeVE, srcRowIndex, srcColumnIndex);
returnType = OperandResolver.coerceValueToInt(ve); returnType = OperandResolver.coerceValueToInt(ve);

View File

@ -149,7 +149,7 @@ public final class PackageRelationshipCollection implements
this(); this();
if (container == null) 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 // Check if the specified part is not a relationship part
if (part != null && part.isRelationshipPart()) if (part != null && part.isRelationshipPart())
@ -379,9 +379,7 @@ public final class PackageRelationshipCollection implements
* @return All relationships of the type specified by the filter. * @return All relationships of the type specified by the filter.
*/ */
public PackageRelationshipCollection getRelationships(String typeFilter) { public PackageRelationshipCollection getRelationships(String typeFilter) {
PackageRelationshipCollection coll = new PackageRelationshipCollection( return new PackageRelationshipCollection(this, typeFilter);
this, typeFilter);
return coll;
} }
/** /**

View File

@ -16,17 +16,6 @@
==================================================================== */ ==================================================================== */
package org.apache.poi.xssf.usermodel; 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;
import org.apache.poi.POIXMLDocumentPart.RelationPart; import org.apache.poi.POIXMLDocumentPart.RelationPart;
import org.apache.poi.openxml4j.opc.OPCPackage; 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.main.STTextUnderlineType;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing; 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 { public class TestXSSFDrawing {
@Test @Test
public void testRead() throws IOException { public void testRead() throws IOException {
@ -628,6 +623,7 @@ public class TestXSSFDrawing {
String paraString10 = "Fifth Bullet"; String paraString10 = "Fifth Bullet";
XSSFTextParagraph para = shape.addNewTextParagraph(paraString1); XSSFTextParagraph para = shape.addNewTextParagraph(paraString1);
assertNotNull(para);
para = shape.addNewTextParagraph(paraString2); para = shape.addNewTextParagraph(paraString2);
para.setBullet(true); para.setBullet(true);
@ -639,6 +635,7 @@ public class TestXSSFDrawing {
para.setBullet(true); para.setBullet(true);
para = shape.addNewTextParagraph(paraString5); para = shape.addNewTextParagraph(paraString5);
assertNotNull(para);
para = shape.addNewTextParagraph(paraString6); para = shape.addNewTextParagraph(paraString6);
para.setBullet(ListAutoNumber.ARABIC_PERIOD); para.setBullet(ListAutoNumber.ARABIC_PERIOD);
@ -678,39 +675,38 @@ public class TestXSSFDrawing {
List<XSSFTextParagraph> paras = sshape.getTextParagraphs(); 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 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(); 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;
builder.append(paraString1); assertEquals(builder, sshape.getText());
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());
checkRewrite(wb2); checkRewrite(wb2);
wb2.close(); wb2.close();
@ -727,18 +723,18 @@ public class TestXSSFDrawing {
List<XSSFShape> shapes = drawing.getShapes(); List<XSSFShape> shapes = drawing.getShapes();
XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(0); XSSFSimpleShape textbox = (XSSFSimpleShape) shapes.get(0);
String extracted = textbox.getText(); String extracted = textbox.getText();
StringBuilder sb = new StringBuilder(); String sb =
sb.append("1. content1A\n"); "1. content1A\n" +
sb.append("\t1. content1B\n"); "\t1. content1B\n" +
sb.append("\t2. content2B\n"); "\t2. content2B\n" +
sb.append("\t3. content3B\n"); "\t3. content3B\n" +
sb.append("2. content2A\n"); "2. content2A\n" +
sb.append("\t3. content2BStartAt3\n"); "\t3. content2BStartAt3\n" +
sb.append("\t\n\t\n\t"); "\t\n\t\n\t" +
sb.append("4. content2BStartAt3Incremented\n"); "4. content2BStartAt3Incremented\n" +
sb.append("\t\n\t\n\t\n\t"); "\t\n\t\n\t\n\t";
assertEquals(sb.toString(), extracted); assertEquals(sb, extracted);
checkRewrite(wb); checkRewrite(wb);
wb.close(); wb.close();
} }