From 4f54f29a2daa62839d22804d22544e4197cfda75 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 16 Jul 2022 10:13:18 +0000 Subject: [PATCH] [github-345] Use switch instead of if. Thanks to XenoAmess. This closes #345 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902772 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/examples/ss/LoadEmbedded.java | 145 ++++++++++-------- .../xssf/usermodel/EmbeddedObjects.java | 50 +++--- .../poi/openxml4j/opc/ContentTypes.java | 32 ++-- .../usermodel/section/geometry/ArcTo.java | 22 +-- .../usermodel/section/geometry/Ellipse.java | 37 +++-- .../section/geometry/EllipticalArcTo.java | 37 +++-- .../section/geometry/InfiniteLine.java | 27 ++-- .../usermodel/section/geometry/NURBSTo.java | 42 +++-- .../section/geometry/PolyLineTo.java | 22 +-- .../section/geometry/RelCubBezTo.java | 37 +++-- .../section/geometry/RelEllipticalArcTo.java | 37 +++-- .../section/geometry/RelQuadBezTo.java | 27 ++-- .../section/geometry/SplineKnot.java | 22 +-- .../section/geometry/SplineStart.java | 37 +++-- .../org/apache/poi/hwpf/dev/RecordUtil.java | 17 +- 15 files changed, 344 insertions(+), 247 deletions(-) diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/LoadEmbedded.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/LoadEmbedded.java index 68ea9229ef..8eabd2ced9 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/LoadEmbedded.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/LoadEmbedded.java @@ -68,79 +68,96 @@ public final class LoadEmbedded { for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) { //the OLE2 Class Name of the object String oleName = obj.getOLE2ClassName(); - if (oleName.equals("Worksheet")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false); - embeddedWorkbook.close(); - } else if (oleName.equals("Document")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - HWPFDocument embeddedWordDocument = new HWPFDocument(dn); - embeddedWordDocument.close(); - } else if (oleName.equals("Presentation")) { - DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - SlideShow embeddedSlieShow = new HSLFSlideShow(dn); - embeddedSlieShow.close(); - } else { - if(obj.hasDirectoryEntry()){ - // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is + switch (oleName) { + case "Worksheet": { DirectoryNode dn = (DirectoryNode) obj.getDirectory(); - for (Entry entry : dn) { - //System.out.println(oleName + "." + entry.getName()); - } - } else { - // There is no DirectoryEntry - // Recover the object's data from the HSSFObjectData instance. - byte[] objectData = obj.getObjectData(); + HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, false); + embeddedWorkbook.close(); + break; + } + case "Document": { + DirectoryNode dn = (DirectoryNode) obj.getDirectory(); + HWPFDocument embeddedWordDocument = new HWPFDocument(dn); + embeddedWordDocument.close(); + break; + } + case "Presentation": { + DirectoryNode dn = (DirectoryNode) obj.getDirectory(); + SlideShow embeddedSlieShow = new HSLFSlideShow(dn); + embeddedSlieShow.close(); + break; } + default: + if (obj.hasDirectoryEntry()) { + // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is + DirectoryNode dn = (DirectoryNode) obj.getDirectory(); + for (Entry entry : dn) { + //System.out.println(oleName + "." + entry.getName()); + } + } else { + // There is no DirectoryEntry + // Recover the object's data from the HSSFObjectData instance. + byte[] objectData = obj.getObjectData(); + } + break; } } } - public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException { + public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, + OpenXML4JException, XmlException { for (PackagePart pPart : workbook.getAllEmbeddedParts()) { String contentType = pPart.getContentType(); - if (contentType.equals("application/vnd.ms-excel")) { - // Excel Workbook - either binary or OpenXML - try (InputStream stream = pPart.getInputStream()) { - HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream); - embeddedWorkbook.close(); - } - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { - // Excel Workbook - OpenXML file format - try (InputStream stream = pPart.getInputStream()) { - XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream); - embeddedWorkbook.close(); - } - } else if (contentType.equals("application/msword")) { - // Word Document - binary (OLE2CDF) file format - try (InputStream stream = pPart.getInputStream()) { - HWPFDocument document = new HWPFDocument(stream); - document.close(); - } - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { - // Word Document - OpenXML file format - try (InputStream stream = pPart.getInputStream()) { - XWPFDocument document = new XWPFDocument(stream); - document.close(); - } - } else if (contentType.equals("application/vnd.ms-powerpoint")) { - // PowerPoint Document - binary file format - try (InputStream stream = pPart.getInputStream()) { - HSLFSlideShow slideShow = new HSLFSlideShow(stream); - slideShow.close(); - } - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) { - // PowerPoint Document - OpenXML file format - try (InputStream stream = pPart.getInputStream()) { - XMLSlideShow slideShow = new XMLSlideShow(stream); - slideShow.close(); - } - } else { - // Any other type of embedded object. - System.out.println("Unknown Embedded Document: " + contentType); - try (InputStream inputStream = pPart.getInputStream()) { + switch (contentType) { + case "application/vnd.ms-excel": + // Excel Workbook - either binary or OpenXML + try (InputStream stream = pPart.getInputStream()) { + HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(stream); + embeddedWorkbook.close(); + } + break; + case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + // Excel Workbook - OpenXML file format + try (InputStream stream = pPart.getInputStream()) { + XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(stream); + embeddedWorkbook.close(); + } + break; + case "application/msword": + // Word Document - binary (OLE2CDF) file format + try (InputStream stream = pPart.getInputStream()) { + HWPFDocument document = new HWPFDocument(stream); + document.close(); + } + break; + case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + // Word Document - OpenXML file format + try (InputStream stream = pPart.getInputStream()) { + XWPFDocument document = new XWPFDocument(stream); + document.close(); + } + break; + case "application/vnd.ms-powerpoint": + // PowerPoint Document - binary file format + try (InputStream stream = pPart.getInputStream()) { + HSLFSlideShow slideShow = new HSLFSlideShow(stream); + slideShow.close(); + } + break; + case "application/vnd.openxmlformats-officedocument.presentationml.presentation": + // PowerPoint Document - OpenXML file format + try (InputStream stream = pPart.getInputStream()) { + XMLSlideShow slideShow = new XMLSlideShow(stream); + slideShow.close(); + } + break; + default: + // Any other type of embedded object. + System.out.println("Unknown Embedded Document: " + contentType); + try (InputStream inputStream = pPart.getInputStream()) { - } + } + break; } } } diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/EmbeddedObjects.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/EmbeddedObjects.java index b4af95c5ae..93f12a0d76 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/EmbeddedObjects.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/EmbeddedObjects.java @@ -37,27 +37,35 @@ public class EmbeddedObjects { String contentType = pPart.getContentType(); try (InputStream is = pPart.getInputStream()) { Closeable document; - if (contentType.equals("application/vnd.ms-excel")) { - // Excel Workbook - either binary or OpenXML - document = new HSSFWorkbook(is); - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { - // Excel Workbook - OpenXML file format - document = new XSSFWorkbook(is); - } else if (contentType.equals("application/msword")) { - // Word Document - binary (OLE2CDF) file format - document = new HWPFDocument(is); - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) { - // Word Document - OpenXML file format - document = new XWPFDocument(is); - } else if (contentType.equals("application/vnd.ms-powerpoint")) { - // PowerPoint Document - binary file format - document = new HSLFSlideShow(is); - } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) { - // PowerPoint Document - OpenXML file format - document = new XMLSlideShow(is); - } else { - // Any other type of embedded object. - document = is; + switch (contentType) { + case "application/vnd.ms-excel": + // Excel Workbook - either binary or OpenXML + document = new HSSFWorkbook(is); + break; + case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + // Excel Workbook - OpenXML file format + document = new XSSFWorkbook(is); + break; + case "application/msword": + // Word Document - binary (OLE2CDF) file format + document = new HWPFDocument(is); + break; + case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + // Word Document - OpenXML file format + document = new XWPFDocument(is); + break; + case "application/vnd.ms-powerpoint": + // PowerPoint Document - binary file format + document = new HSLFSlideShow(is); + break; + case "application/vnd.openxmlformats-officedocument.presentationml.presentation": + // PowerPoint Document - OpenXML file format + document = new XMLSlideShow(is); + break; + default: + // Any other type of embedded object. + document = is; + break; } document.close(); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ContentTypes.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ContentTypes.java index bda08f6445..12dcdb1b12 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ContentTypes.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ContentTypes.java @@ -111,20 +111,22 @@ public final class ContentTypes { public static String getContentTypeFromFileExtension(String filename) { String extension = filename.substring(filename.lastIndexOf('.') + 1) .toLowerCase(Locale.ROOT); - if (extension.equals(EXTENSION_JPG_1) - || extension.equals(EXTENSION_JPG_2)) - return IMAGE_JPEG; - else if (extension.equals(EXTENSION_GIF)) - return IMAGE_GIF; - else if (extension.equals(EXTENSION_PICT)) - return IMAGE_PICT; - else if (extension.equals(EXTENSION_PNG)) - return IMAGE_PNG; - else if (extension.equals(EXTENSION_TIFF)) - return IMAGE_TIFF; - else if (extension.equals(EXTENSION_XML)) - return XML; - else - return null; + switch (extension) { + case EXTENSION_JPG_1: + case EXTENSION_JPG_2: + return IMAGE_JPEG; + case EXTENSION_GIF: + return IMAGE_GIF; + case EXTENSION_PICT: + return IMAGE_PICT; + case EXTENSION_PNG: + return IMAGE_PNG; + case EXTENSION_TIFF: + return IMAGE_TIFF; + case EXTENSION_XML: + return XML; + default: + return null; + } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/ArcTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/ArcTo.java index aa07938b3e..a991815c4a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/ArcTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/ArcTo.java @@ -53,15 +53,19 @@ public class ArcTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in ArcTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in ArcTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/Ellipse.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/Ellipse.java index 8f509f9607..703a24b499 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/Ellipse.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/Ellipse.java @@ -59,21 +59,28 @@ public class Ellipse implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in Ellipse row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in Ellipse row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java index 2ec09f6b6b..dcce505f64 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/EllipticalArcTo.java @@ -71,21 +71,28 @@ public class EllipticalArcTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in EllipticalArcTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in EllipticalArcTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/InfiniteLine.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/InfiniteLine.java index c7383f3cc2..894bcb3665 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/InfiniteLine.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/InfiniteLine.java @@ -61,17 +61,22 @@ public class InfiniteLine implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in InfiniteLine row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in InfiniteLine row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/NURBSTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/NURBSTo.java index 1b9f0f9556..e3d6f59eb8 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/NURBSTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/NURBSTo.java @@ -68,23 +68,31 @@ public class NURBSTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("E")) { - e = cell.getV(); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in NURBS row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseDoubleValue(cell); + break; + case "E": + e = cell.getV(); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in NURBS row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java index b64518138b..70d652bda9 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java @@ -50,15 +50,19 @@ public class PolyLineTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = cell.getV(); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in ArcTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = cell.getV(); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in ArcTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelCubBezTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelCubBezTo.java index 847dce06b7..3e1d294387 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelCubBezTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelCubBezTo.java @@ -66,21 +66,28 @@ public class RelCubBezTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in RelCubBezTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in RelCubBezTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelEllipticalArcTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelEllipticalArcTo.java index 9e11bb31a6..229896d01a 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelEllipticalArcTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelEllipticalArcTo.java @@ -63,21 +63,28 @@ public class RelEllipticalArcTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in RelEllipticalArcTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in RelEllipticalArcTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java index e6037279ea..b512716120 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/RelQuadBezTo.java @@ -62,17 +62,22 @@ public class RelQuadBezTo implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in RelQuadBezTo row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in RelQuadBezTo row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java index bd006ac60e..0e0bfccade 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineKnot.java @@ -53,15 +53,19 @@ public class SplineKnot implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in SplineKnot row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in SplineKnot row"); } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java index c6e0332d6c..8e3cf92934 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/SplineStart.java @@ -61,21 +61,28 @@ public class SplineStart implements GeometryRow { for (CellType cell : row.getCellArray()) { String cellName = cell.getN(); - if (cellName.equals("X")) { - x = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("Y")) { - y = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("A")) { - a = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("B")) { - b = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("C")) { - c = XDGFCell.parseDoubleValue(cell); - } else if (cellName.equals("D")) { - d = XDGFCell.parseIntegerValue(cell); - } else { - throw new POIXMLException("Invalid cell '" + cellName - + "' in SplineStart row"); + switch (cellName) { + case "X": + x = XDGFCell.parseDoubleValue(cell); + break; + case "Y": + y = XDGFCell.parseDoubleValue(cell); + break; + case "A": + a = XDGFCell.parseDoubleValue(cell); + break; + case "B": + b = XDGFCell.parseDoubleValue(cell); + break; + case "C": + c = XDGFCell.parseDoubleValue(cell); + break; + case "D": + d = XDGFCell.parseIntegerValue(cell); + break; + default: + throw new POIXMLException("Invalid cell '" + cellName + + "' in SplineStart row"); } } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java index cd11e5d879..6c401cc512 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java @@ -107,12 +107,17 @@ public class RecordUtil byte numBits = 0; int mask = (int) Long.parseLong( bitMask.substring( 2 ), 16 ); - if ( parentType.equals( "byte" ) ) - parentSize = 8; - else if ( parentType.equals( "short" ) ) - parentSize = 16; - else if ( parentType.equals( "int" ) ) - parentSize = 32; + switch (parentType) { + case "byte": + parentSize = 8; + break; + case "short": + parentSize = 16; + break; + case "int": + parentSize = 32; + break; + } for ( int x = 0; x < parentSize; x++ ) { -- 2.39.5