diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-07-16 10:13:18 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-07-16 10:13:18 +0000 |
commit | 4f54f29a2daa62839d22804d22544e4197cfda75 (patch) | |
tree | 367341b6fac45df026ce3673a421a23567fab957 /poi-ooxml | |
parent | feae2c87490392f2e69212949a1e734e930e7e20 (diff) | |
download | poi-4f54f29a2daa62839d22804d22544e4197cfda75.tar.gz poi-4f54f29a2daa62839d22804d22544e4197cfda75.zip |
[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
Diffstat (limited to 'poi-ooxml')
12 files changed, 223 insertions, 156 deletions
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"); } } } |