This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new b010c58532 update instanceof usage (#1130)
b010c58532 is described below
commit b010c58532c9f64bb7a82b31f02d758f52a6f74d
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Jun 11 12:22:44 2026 +0100
update instanceof usage (#1130)
---
.../util/ZipInputStreamZipEntrySource.java | 6 ++--
.../poi/xddf/usermodel/XDDFLineProperties.java | 28 ++++++++--------
.../poi/xddf/usermodel/XDDFShapeProperties.java | 24 ++++++-------
.../xddf/usermodel/text/XDDFBodyProperties.java | 12 +++----
.../text/XDDFParagraphBulletProperties.java | 16 ++++-----
.../poi/xddf/usermodel/text/XDDFRunProperties.java | 24 ++++++-------
.../poi/xddf/usermodel/text/XDDFTextParagraph.java | 12 +++----
.../org/apache/poi/xdgf/usermodel/XDGFMasters.java | 13 ++++----
.../org/apache/poi/xdgf/usermodel/XDGFPages.java | 14 ++++----
.../xdgf/usermodel/section/GeometrySection.java | 8 ++---
.../apache/poi/xslf/draw/SVGRenderExtension.java | 4 +--
.../apache/poi/xslf/usermodel/XMLSlideShow.java | 24 ++++++-------
.../org/apache/poi/xslf/util/DummyGraphics2d.java | 12 +++----
.../java/org/apache/poi/xslf/util/EMFHandler.java | 4 +--
.../java/org/apache/poi/xslf/util/PPTHandler.java | 2 +-
.../extractor/XSSFEventBasedExcelExtractor.java | 4 +--
.../poi/xssf/extractor/XSSFExcelExtractor.java | 6 ++--
.../apache/poi/xssf/extractor/XSSFExportToXml.java | 3 +-
.../org/apache/poi/xssf/model/CommentsTable.java | 6 ++--
.../apache/poi/xssf/model/SharedStringsTable.java | 5 +--
.../xssf/usermodel/BaseXSSFFormulaEvaluator.java | 4 +--
.../org/apache/poi/xssf/usermodel/XSSFComment.java | 9 ++---
.../org/apache/poi/xssf/usermodel/XSSFFont.java | 39 +++++++++++-----------
.../poi/xssf/usermodel/XSSFFormulaEvaluator.java | 6 ++--
.../apache/poi/xssf/usermodel/XSSFWorkbook.java | 28 ++++++++--------
.../xssf/usermodel/extensions/XSSFCellFill.java | 24 ++++++-------
.../xssf/usermodel/helpers/XSSFFormulaUtils.java | 9 ++---
27 files changed, 171 insertions(+), 175 deletions(-)
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
index 5eb1124fde..2e4265e4bb 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
@@ -137,8 +137,10 @@ public class ZipInputStreamZipEntrySource implements
ZipEntrySource {
@Override
public InputStream getInputStream(ZipArchiveEntry zipEntry) throws
IOException {
- assert (zipEntry instanceof ZipArchiveFakeEntry);
- return ((ZipArchiveFakeEntry)zipEntry).getInputStream();
+ if (zipEntry instanceof ZipArchiveFakeEntry zipFakeEntry) {
+ return zipFakeEntry.getInputStream();
+ }
+ throw new IllegalArgumentException("This implementation only supports
ZipArchiveFakeEntry");
}
@Override
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLineProperties.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLineProperties.java
index 07de8efa63..aa411e67f6 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLineProperties.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFLineProperties.java
@@ -223,14 +223,14 @@ public class XDDFLineProperties {
if (properties == null) {
return;
}
- if (properties instanceof XDDFGradientFillProperties) {
- props.setGradFill(((XDDFGradientFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFNoFillProperties) {
- props.setNoFill(((XDDFNoFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFPatternFillProperties) {
- props.setPattFill(((XDDFPatternFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFSolidFillProperties) {
- props.setSolidFill(((XDDFSolidFillProperties)
properties).getXmlObject());
+ if (properties instanceof XDDFGradientFillProperties xprops) {
+ props.setGradFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFNoFillProperties xprops) {
+ props.setNoFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFPatternFillProperties xprops) {
+ props.setPattFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFSolidFillProperties xprops) {
+ props.setSolidFill(xprops.getXmlObject());
}
}
@@ -259,12 +259,12 @@ public class XDDFLineProperties {
if (properties == null) {
return;
}
- if (properties instanceof XDDFLineJoinBevelProperties) {
- props.setBevel(((XDDFLineJoinBevelProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFLineJoinMiterProperties) {
- props.setMiter(((XDDFLineJoinMiterProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFLineJoinRoundProperties) {
- props.setRound(((XDDFLineJoinRoundProperties)
properties).getXmlObject());
+ if (properties instanceof XDDFLineJoinBevelProperties xprops) {
+ props.setBevel(xprops.getXmlObject());
+ } else if (properties instanceof XDDFLineJoinMiterProperties xprops) {
+ props.setMiter(xprops.getXmlObject());
+ } else if (properties instanceof XDDFLineJoinRoundProperties xprops) {
+ props.setRound(xprops.getXmlObject());
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFShapeProperties.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFShapeProperties.java
index 9182f26ba8..312a232a96 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFShapeProperties.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/XDDFShapeProperties.java
@@ -97,18 +97,18 @@ public class XDDFShapeProperties {
if (properties == null) {
return;
}
- if (properties instanceof XDDFGradientFillProperties) {
- props.setGradFill(((XDDFGradientFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFGroupFillProperties) {
- props.setGrpFill(((XDDFGroupFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFNoFillProperties) {
- props.setNoFill(((XDDFNoFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFPatternFillProperties) {
- props.setPattFill(((XDDFPatternFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFPictureFillProperties) {
- props.setBlipFill(((XDDFPictureFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFSolidFillProperties) {
- props.setSolidFill(((XDDFSolidFillProperties)
properties).getXmlObject());
+ if (properties instanceof XDDFGradientFillProperties xprops) {
+ props.setGradFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFGroupFillProperties xprops) {
+ props.setGrpFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFNoFillProperties xprops) {
+ props.setNoFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFPatternFillProperties xprops) {
+ props.setPattFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFPictureFillProperties xprops) {
+ props.setBlipFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFSolidFillProperties xprops) {
+ props.setSolidFill(xprops.getXmlObject());
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
index de7de30ef8..db4570c682 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFBodyProperties.java
@@ -95,12 +95,12 @@ public class XDDFBodyProperties {
if (props.isSetSpAutoFit()) {
props.unsetSpAutoFit();
}
- if (autofit instanceof XDDFNoAutoFit) {
- props.setNoAutofit(((XDDFNoAutoFit) autofit).getXmlObject());
- } else if (autofit instanceof XDDFNormalAutoFit) {
- props.setNormAutofit(((XDDFNormalAutoFit) autofit).getXmlObject());
- } else if (autofit instanceof XDDFShapeAutoFit) {
- props.setSpAutoFit(((XDDFShapeAutoFit) autofit).getXmlObject());
+ if (autofit instanceof XDDFNoAutoFit xddfNoAutoFit) {
+ props.setNoAutofit(xddfNoAutoFit.getXmlObject());
+ } else if (autofit instanceof XDDFNormalAutoFit xddfNormalAutoFit) {
+ props.setNormAutofit(xddfNormalAutoFit.getXmlObject());
+ } else if (autofit instanceof XDDFShapeAutoFit xddfShapeAutoFit) {
+ props.setSpAutoFit(xddfShapeAutoFit.getXmlObject());
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java
index 3e3249d3bd..4441f6bf65 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFParagraphBulletProperties.java
@@ -60,14 +60,14 @@ public class XDDFParagraphBulletProperties {
props.unsetBuNone();
}
if (style != null) {
- if (style instanceof XDDFBulletStyleAutoNumbered) {
- props.setBuAutoNum(((XDDFBulletStyleAutoNumbered)
style).getXmlObject());
- } else if (style instanceof XDDFBulletStyleCharacter) {
- props.setBuChar(((XDDFBulletStyleCharacter)
style).getXmlObject());
- } else if (style instanceof XDDFBulletStyleNone) {
- props.setBuNone(((XDDFBulletStyleNone) style).getXmlObject());
- } else if (style instanceof XDDFBulletStylePicture) {
- props.setBuBlip(((XDDFBulletStylePicture)
style).getXmlObject());
+ if (style instanceof XDDFBulletStyleAutoNumbered xstyle) {
+ props.setBuAutoNum(xstyle.getXmlObject());
+ } else if (style instanceof XDDFBulletStyleCharacter xstyle) {
+ props.setBuChar(xstyle.getXmlObject());
+ } else if (style instanceof XDDFBulletStyleNone xstyle) {
+ props.setBuNone(xstyle.getXmlObject());
+ } else if (style instanceof XDDFBulletStylePicture xstyle) {
+ props.setBuBlip(xstyle.getXmlObject());
}
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java
index 9bceb83967..6fb38a0260 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFRunProperties.java
@@ -120,18 +120,18 @@ public class XDDFRunProperties {
if (properties == null) {
return;
}
- if (properties instanceof XDDFGradientFillProperties) {
- props.setGradFill(((XDDFGradientFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFGroupFillProperties) {
- props.setGrpFill(((XDDFGroupFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFNoFillProperties) {
- props.setNoFill(((XDDFNoFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFPatternFillProperties) {
- props.setPattFill(((XDDFPatternFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFPictureFillProperties) {
- props.setBlipFill(((XDDFPictureFillProperties)
properties).getXmlObject());
- } else if (properties instanceof XDDFSolidFillProperties) {
- props.setSolidFill(((XDDFSolidFillProperties)
properties).getXmlObject());
+ if (properties instanceof XDDFGradientFillProperties xprops) {
+ props.setGradFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFGroupFillProperties xprops) {
+ props.setGrpFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFNoFillProperties xprops) {
+ props.setNoFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFPatternFillProperties xprops) {
+ props.setPattFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFPictureFillProperties xprops) {
+ props.setBlipFill(xprops.getXmlObject());
+ } else if (properties instanceof XDDFSolidFillProperties xprops) {
+ props.setSolidFill(xprops.getXmlObject());
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
index c910328421..eb50b0829e 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
@@ -64,12 +64,12 @@ public class XDDFTextParagraph implements
Iterable<XDDFTextRun> {
this._runs = new ArrayList<>(count);
for (XmlObject xo : paragraph.selectChildren(QNameSet.ALL)) {
- if (xo instanceof CTTextLineBreak) {
- _runs.add(new XDDFTextRun((CTTextLineBreak) xo, this));
- } else if (xo instanceof CTTextField) {
- _runs.add(new XDDFTextRun((CTTextField) xo, this));
- } else if (xo instanceof CTRegularTextRun) {
- _runs.add(new XDDFTextRun((CTRegularTextRun) xo, this));
+ if (xo instanceof CTTextLineBreak ctTextLineBreak) {
+ _runs.add(new XDDFTextRun(ctTextLineBreak, this));
+ } else if (xo instanceof CTTextField ctTextField) {
+ _runs.add(new XDDFTextRun(ctTextField, this));
+ } else if (xo instanceof CTRegularTextRun ctRegularTextRun) {
+ _runs.add(new XDDFTextRun(ctRegularTextRun, this));
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
index 07c6cd8784..f1e53cfb60 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFMasters.java
@@ -87,15 +87,14 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
throw new POIXMLException("Master relationship for " +
relId + " not found");
}
- if (!(part instanceof XDGFMasterContents)) {
+
+ if (part instanceof XDGFMasterContents contents) {
+ contents.onDocumentRead();
+ XDGFMaster master = new XDGFMaster(settings, contents,
_document);
+ _masters.put(master.getID(), master);
+ } else {
throw new POIXMLException("Unexpected masters relationship
for " + relId + ": " + part);
}
-
- XDGFMasterContents contents = (XDGFMasterContents)part;
- contents.onDocumentRead();
-
- XDGFMaster master = new XDGFMaster(settings, contents,
_document);
- _masters.put(master.getID(), master);
}
} catch (POIXMLException e) {
throw XDGFException.wrap(this, e);
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
index 43232c05c8..b8b1e18b9c 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFPages.java
@@ -81,15 +81,13 @@ public class XDGFPages extends XDGFXMLDocumentPart {
if (pageContentsPart == null)
throw new POIXMLException("PageSettings relationship for "
+ relId + " not found");
- if (!(pageContentsPart instanceof XDGFPageContents))
+ if (pageContentsPart instanceof XDGFPageContents contents) {
+ XDGFPage page = new XDGFPage(pageSettings, contents,
_document, this);
+ contents.onDocumentRead();
+ _pages.add(page);
+ } else {
throw new POIXMLException("Unexpected pages relationship
for " + relId + ": " + pageContentsPart);
-
- XDGFPageContents contents = (XDGFPageContents)pageContentsPart;
- XDGFPage page = new XDGFPage(pageSettings, contents,
_document, this);
-
- contents.onDocumentRead();
-
- _pages.add(page);
+ }
}
} catch (POIXMLException e) {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java
b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java
index 75e9b60365..68b10cd597 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/GeometrySection.java
@@ -111,10 +111,10 @@ public class GeometrySection extends XDGFSection {
// special cases
GeometryRow first = rows.hasNext() ? rows.next() : null;
- if (first instanceof Ellipse) {
- return ((Ellipse)first).getPath();
- } else if (first instanceof InfiniteLine) {
- return ((InfiniteLine)first).getPath();
+ if (first instanceof Ellipse ellipse) {
+ return ellipse.getPath();
+ } else if (first instanceof InfiniteLine infiniteLine) {
+ return infiniteLine.getPath();
} else if (first instanceof SplineStart) {
throw new POIXMLException("SplineStart must be preceded by another
type");
} else {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
index a2e60f1b13..c71b7fc130 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/SVGRenderExtension.java
@@ -278,8 +278,8 @@ public class SVGRenderExtension extends
DefaultExtensionHandler {
// TODO: the rotation handling is incomplete and the scale handling is
missing
// see DrawTexturePaint on how to do it for AWT
- if (!fill.isRotatedWithShape() && slShape instanceof SimpleShape) {
- double rot = ((SimpleShape<?,?>)slShape).getRotation();
+ if (!fill.isRotatedWithShape() && slShape instanceof SimpleShape
simpleShape) {
+ double rot = simpleShape.getRotation();
if (rot != 0) {
setAttribute(genCtx, patternDef,
null, SVG_PATTERN_TRANSFORM_ATTRIBUTE, "rotate(" +
genCtx.doubleString(-rot) + ")");
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index 3d804894e6..5257320ab5 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -192,21 +192,21 @@ public class XMLSlideShow extends POIXMLDocument
Map<String, XSLFChart> chartMap = new HashMap<>();
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
- if (p instanceof XSLFSlide) {
- shIdMap.put(rp.getRelationship().getId(), (XSLFSlide) p);
+ if (p instanceof XSLFSlide xslfSlide) {
+ shIdMap.put(rp.getRelationship().getId(), xslfSlide);
for (POIXMLDocumentPart c : p.getRelations()) {
- if (c instanceof XSLFChart) {
-
chartMap.put(c.getPackagePart().getPartName().getName(), (XSLFChart) c);
+ if (c instanceof XSLFChart xslfChart) {
+
chartMap.put(c.getPackagePart().getPartName().getName(), xslfChart);
}
}
- } else if (p instanceof XSLFSlideMaster) {
- masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
- } else if (p instanceof XSLFTableStyles) {
- _tableStyles = (XSLFTableStyles) p;
- } else if (p instanceof XSLFNotesMaster) {
- _notesMaster = (XSLFNotesMaster) p;
- } else if (p instanceof XSLFCommentAuthors) {
- _commentAuthors = (XSLFCommentAuthors) p;
+ } else if (p instanceof XSLFSlideMaster xslfSlideMaster) {
+ masterMap.put(getRelationId(p), xslfSlideMaster);
+ } else if (p instanceof XSLFTableStyles xslfTableStyles) {
+ _tableStyles = xslfTableStyles;
+ } else if (p instanceof XSLFNotesMaster xslfNotesMaster) {
+ _notesMaster = xslfNotesMaster;
+ } else if (p instanceof XSLFCommentAuthors xslfCommentAuthors)
{
+ _commentAuthors = xslfCommentAuthors;
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyGraphics2d.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyGraphics2d.java
index 1dfbc4c009..3876fd13a5 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyGraphics2d.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/DummyGraphics2d.java
@@ -374,8 +374,7 @@ public class DummyGraphics2d extends Graphics2D {
@Override
public void setStroke(Stroke s) {
String l;
- if (s instanceof BasicStroke) {
- BasicStroke bs = (BasicStroke)s;
+ if (s instanceof BasicStroke bs) {
String cap = new String[]{"BUTT","ROUND","SQUARE"}[bs.getEndCap()];
String join = new
String[]{"MITER","ROUND","BEVEL"}[bs.getLineJoin()];
l = "g.setStroke(new BasicStroke(" + bs.getLineWidth() + "f,
BasicStroke.CAP_" + cap + ", BasicStroke.JOIN_" + join + ", " +
@@ -716,17 +715,16 @@ public class DummyGraphics2d extends Graphics2D {
if (attr == null) {
return "null";
}
- if (attr instanceof Font) {
- Font f = (Font)attr;
+ if (attr instanceof Font f) {
final String[] STYLE = { "Font.PLAIN", "Font.BOLD", "Font.ITALIC",
"Font.BOLD | Font.ITALIC" };
return "new Font(\"" + f.getFamily(Locale.ROOT) + "\"," +
STYLE[f.getStyle()] + "," + f.getSize() + ")";
}
- if (attr instanceof Color) {
- return String.format(Locale.ROOT, "new Color(0x%08X)",
((Color)attr).getRGB());
+ if (attr instanceof Color c) {
+ return String.format(Locale.ROOT, "new Color(0x%08X)", c.getRGB());
}
for (int i=0; i<ATTRS.length; i+=2) {
if (attr == ATTRS[i]) {
- return (String)ATTRS[i+1];
+ return ATTRS[i+1].toString();
}
}
return "\""+ attr +"\"";
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/EMFHandler.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/EMFHandler.java
index 761c819612..f25aa09eb1 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/EMFHandler.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/EMFHandler.java
@@ -108,8 +108,8 @@ class EMFHandler extends MFProxy {
@Override
public Iterable<EmbeddedPart> getEmbeddings(int slideNo) {
- return (imgr instanceof EmbeddedExtractor)
- ? ((EmbeddedExtractor) imgr).getEmbeddings()
+ return (imgr instanceof EmbeddedExtractor embeddedExtractor)
+ ? embeddedExtractor.getEmbeddings()
: Collections.emptyList();
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTHandler.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTHandler.java
index 48de2bd69d..8cbe85c950 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTHandler.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/util/PPTHandler.java
@@ -146,7 +146,7 @@ class PPTHandler extends MFProxy {
@Override
public GenericRecord getRoot() {
- return (ppt instanceof GenericRecord) ? (GenericRecord)ppt : null;
+ return (ppt instanceof GenericRecord genericRecord) ? genericRecord :
null;
}
private Stream<Integer> range(Matcher m) {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
index 3bef53b8ae..a1663fa5e0 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
@@ -300,8 +300,8 @@ public class XSSFEventBasedExcelExtractor
return;
}
for (XSSFShape shape : shapes) {
- if (shape instanceof XSSFSimpleShape) {
- String sText = ((XSSFSimpleShape) shape).getText();
+ if (shape instanceof XSSFSimpleShape simpleShape) {
+ String sText = simpleShape.getText();
if (sText != null && !sText.isEmpty()) {
text.append(sText).append('\n');
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
index 855c5ee3ba..151e7d6da4 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
@@ -189,9 +189,9 @@ public class XSSFExcelExtractor
if (includeTextBoxes){
XSSFDrawing drawing = sheet.getDrawingPatriarch();
if (drawing != null) {
- for (XSSFShape shape : drawing.getShapes()){
- if (shape instanceof XSSFSimpleShape){
- String boxText =
((XSSFSimpleShape)shape).getText();
+ for (XSSFShape shape : drawing.getShapes()) {
+ if (shape instanceof XSSFSimpleShape simpleShape) {
+ String boxText = simpleShape.getText();
if (!boxText.isEmpty()){
text.append(boxText);
text.append('\n');
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
index 4ebdf83fac..2490e58167 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java
@@ -306,8 +306,7 @@ public class XSSFExportToXml implements Comparator<String>{
default:
}
- if (node instanceof Element) {
- Element currentElement = (Element) node;
+ if (node instanceof Element currentElement) {
currentElement.setTextContent(value);
} else {
node.setNodeValue(value);
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
index f449d5951c..53af2b24c0 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java
@@ -217,7 +217,7 @@ public class CommentsTable extends POIXMLDocumentPart
implements Comments {
public XSSFComment createNewComment(ClientAnchor clientAnchor) {
XSSFVMLDrawing vml = getVMLDrawing(sheet, true);
CTShape vmlShape = vml == null ? null : vml.newCommentShape();
- if (vmlShape != null && clientAnchor instanceof XSSFClientAnchor &&
((XSSFClientAnchor)clientAnchor).isSet()) {
+ if (vmlShape != null && clientAnchor instanceof XSSFClientAnchor
xssfClientAnchor && xssfClientAnchor.isSet()) {
// convert offsets from emus to pixels since we get a
// DrawingML-anchor
// but create a VML Drawing
@@ -323,8 +323,8 @@ public class CommentsTable extends POIXMLDocumentPart
implements Comments {
private XSSFVMLDrawing getVMLDrawing(Sheet sheet, boolean autocreate) {
if (vmlDrawing == null) {
- if (sheet instanceof OoxmlSheetExtensions) {
- vmlDrawing =
((OoxmlSheetExtensions)sheet).getVMLDrawing(autocreate);
+ if (sheet instanceof OoxmlSheetExtensions ooxmlSheetExtensions) {
+ vmlDrawing = ooxmlSheetExtensions.getVMLDrawing(autocreate);
}
}
return vmlDrawing;
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/SharedStringsTable.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/SharedStringsTable.java
index 57af5bbf09..8eca6c710d 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/SharedStringsTable.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/SharedStringsTable.java
@@ -217,10 +217,11 @@ public class SharedStringsTable extends
POIXMLDocumentPart implements SharedStri
* @return index the index of added entry
*/
public int addSharedStringItem(RichTextString string) {
- if(!(string instanceof XSSFRichTextString)){
+ if (string instanceof XSSFRichTextString richTextString) {
+ return addEntry(richTextString.getCTRst());
+ } else {
throw new IllegalArgumentException("Only XSSFRichTextString
argument is supported");
}
- return addEntry(((XSSFRichTextString) string).getCTRst());
}
/**
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
index b5674ada8e..588359c913 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
@@ -163,11 +163,11 @@ public abstract class BaseXSSFFormulaEvaluator extends
BaseFormulaEvaluator {
@Override
protected void setCellType(Cell cell, CellType cellType) {
- if (cell instanceof XSSFCell) {
+ if (cell instanceof XSSFCell xssfCell) {
EvaluationWorkbook evaluationWorkbook = getEvaluationWorkbook();
BaseXSSFEvaluationWorkbook xewb =
BaseXSSFEvaluationWorkbook.class.isAssignableFrom(evaluationWorkbook.getClass())
? (BaseXSSFEvaluationWorkbook) evaluationWorkbook : null;
- ((XSSFCell) cell).setCellType(cellType, xewb);
+ xssfCell.setCellType(cellType, xewb);
} else {
// could be an SXSSFCell
cell.setCellType(cellType);
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java
index 2c573892df..db137689e8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFComment.java
@@ -230,12 +230,13 @@ public class XSSFComment implements Comment {
*/
@Override
public void setString(RichTextString string) {
- if(!(string instanceof XSSFRichTextString)){
+ if(string instanceof XSSFRichTextString richTextString) {
+ _str = richTextString;
+ _comment.setText(_str.getCTRst());
+ _comments.commentUpdated(this);
+ } else {
throw new IllegalArgumentException("Only XSSFRichTextString
argument is supported");
}
- _str = (XSSFRichTextString)string;
- _comment.setText(_str.getCTRst());
- _comments.commentUpdated(this);
}
public void setString(String string) {
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java
index e4ba7e0bbd..f2bc4fa6b8 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFont.java
@@ -643,25 +643,26 @@ public class XSSFFont implements Font {
return _ctFont.toString().hashCode();
}
- public boolean equals(Object o){
- if(!(o instanceof XSSFFont)) return false;
-
- XSSFFont cf = (XSSFFont)o;
-
- // BUG 60845
- return Objects.equals(this.getItalic(), cf.getItalic())
- && Objects.equals(this.getBold(), cf.getBold())
- && Objects.equals(this.getStrikeout(),
cf.getStrikeout())
- && Objects.equals(this.getCharSet(), cf.getCharSet())
- && Objects.equals(this.getColor(), cf.getColor())
- && Objects.equals(this.getFamily(), cf.getFamily())
- && Objects.equals(this.getFontHeight(),
cf.getFontHeight())
- && Objects.equals(this.getFontName(), cf.getFontName())
- && Objects.equals(this.getScheme(), cf.getScheme())
- && Objects.equals(this.getThemeColor(),
cf.getThemeColor())
- && Objects.equals(this.getTypeOffset(),
cf.getTypeOffset())
- && Objects.equals(this.getUnderline(),
cf.getUnderline())
- && Objects.equals(this.getXSSFColor(),
cf.getXSSFColor());
+ public boolean equals(Object o) {
+ if (o instanceof XSSFFont cf) {
+ // BUG 60845
+ return Objects.equals(this.getItalic(), cf.getItalic())
+ && Objects.equals(this.getBold(), cf.getBold())
+ && Objects.equals(this.getStrikeout(), cf.getStrikeout())
+ && Objects.equals(this.getCharSet(), cf.getCharSet())
+ && Objects.equals(this.getColor(), cf.getColor())
+ && Objects.equals(this.getFamily(), cf.getFamily())
+ && Objects.equals(this.getFontHeight(), cf.getFontHeight())
+ && Objects.equals(this.getFontName(), cf.getFontName())
+ && Objects.equals(this.getScheme(), cf.getScheme())
+ && Objects.equals(this.getThemeColor(), cf.getThemeColor())
+ && Objects.equals(this.getTypeOffset(), cf.getTypeOffset())
+ && Objects.equals(this.getUnderline(), cf.getUnderline())
+ && Objects.equals(this.getXSSFColor(), cf.getXSSFColor());
+
+ } else {
+ return false;
+ }
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
index 6a6e6e1a52..be85c4d61a 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
@@ -105,11 +105,11 @@ public final class XSSFFormulaEvaluator extends
BaseXSSFFormulaEvaluator {
*/
@Override
protected EvaluationCell toEvaluationCell(Cell cell) {
- if (!(cell instanceof XSSFCell)){
+ if (cell instanceof XSSFCell xssfCell) {
+ return new XSSFEvaluationCell(xssfCell);
+ } else {
throw new IllegalArgumentException("Unexpected type of cell: " +
cell.getClass() + "." +
" Only XSSFCells can be evaluated.");
}
-
- return new XSSFEvaluationCell((XSSFCell)cell);
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 4aec062781..533352ea90 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -417,20 +417,20 @@ public class XSSFWorkbook extends POIXMLDocument
implements Workbook, Date1904Su
Map<String, ExternalLinksTable> elIdMap = new HashMap<>();
for(RelationPart rp : getRelationParts()){
POIXMLDocumentPart p = rp.getDocumentPart();
- if(p instanceof SharedStringsTable) {
- sharedStringSource = (SharedStringsTable)p;
- } else if(p instanceof StylesTable) {
- stylesSource = (StylesTable)p;
- } else if(p instanceof ThemesTable) {
- theme = (ThemesTable)p;
- } else if(p instanceof CalculationChain) {
- calcChain = (CalculationChain)p;
- } else if(p instanceof MapInfo) {
- mapInfo = (MapInfo)p;
- } else if (p instanceof XSSFSheet) {
- shIdMap.put(rp.getRelationship().getId(), (XSSFSheet)p);
- } else if (p instanceof ExternalLinksTable) {
- elIdMap.put(rp.getRelationship().getId(),
(ExternalLinksTable)p);
+ if(p instanceof SharedStringsTable sharedStringsTable) {
+ this.sharedStringSource = sharedStringsTable;
+ } else if(p instanceof StylesTable stylesTable) {
+ this.stylesSource = stylesTable;
+ } else if(p instanceof ThemesTable themesTable) {
+ theme = themesTable;
+ } else if(p instanceof CalculationChain calculationChain) {
+ this.calcChain = calculationChain;
+ } else if(p instanceof MapInfo info) {
+ this.mapInfo = info;
+ } else if (p instanceof XSSFSheet xssfSheet) {
+ shIdMap.put(rp.getRelationship().getId(), xssfSheet);
+ } else if (p instanceof ExternalLinksTable externalLinksTable)
{
+ elIdMap.put(rp.getRelationship().getId(),
externalLinksTable);
}
}
boolean packageReadOnly = (getPackage().getPackageAccess() ==
PackageAccess.READ);
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
index dc93a429b0..bd6b274a28 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellFill.java
@@ -173,17 +173,17 @@ public final class XSSFCellFill {
}
public boolean equals(Object o) {
- if (!(o instanceof XSSFCellFill)) return false;
-
- XSSFCellFill cf = (XSSFCellFill) o;
-
- // bug 60845
- // Do not compare the representing strings but the properties
- // Reason:
- // The strings are different if the XMLObject is a fragment (e.g.
the ones from cloneStyle)
- // even if they are in fact representing the same style
- return Objects.equals(this.getFillBackgroundColor(),
cf.getFillBackgroundColor())
- && Objects.equals(this.getFillForegroundColor(),
cf.getFillForegroundColor())
- && Objects.equals(this.getPatternType(), cf.getPatternType());
+ if (o instanceof XSSFCellFill cf) {
+ // bug 60845
+ // Do not compare the representing strings but the properties
+ // Reason:
+ // The strings are different if the XMLObject is a fragment
(e.g. the ones from cloneStyle)
+ // even if they are in fact representing the same style
+ return Objects.equals(this.getFillBackgroundColor(),
cf.getFillBackgroundColor())
+ && Objects.equals(this.getFillForegroundColor(),
cf.getFillForegroundColor())
+ && Objects.equals(this.getPatternType(),
cf.getPatternType());
+ } else {
+ return false;
+ }
}
}
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
index 36ed86d912..257989408f 100644
---
a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
+++
b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
@@ -88,8 +88,7 @@ public final class XSSFFormulaUtils {
// update charts
List<POIXMLDocumentPart> rels =
_wb.getSheetAt(sheetIndex).getRelations();
for (POIXMLDocumentPart r : rels) {
- if (r instanceof XSSFDrawing) {
- XSSFDrawing dg = (XSSFDrawing) r;
+ if (r instanceof XSSFDrawing dg) {
for (XSSFChart chart : dg.getCharts()) {
Node dom = chart.getCTChartSpace().getDomNode();
updateDomSheetReference(dom, oldName, newName);
@@ -143,15 +142,13 @@ public final class XSSFFormulaUtils {
}
private void updatePtg(Ptg ptg, String oldName, String newName) {
- if (ptg instanceof Pxg) {
- Pxg pxg = (Pxg)ptg;
+ if (ptg instanceof Pxg pxg) {
if (pxg.getExternalWorkbookNumber() < 1) {
if (pxg.getSheetName() != null &&
pxg.getSheetName().equals(oldName)) {
pxg.setSheetName(newName);
}
- if (pxg instanceof Pxg3D) {
- Pxg3D pxg3D = (Pxg3D)pxg;
+ if (pxg instanceof Pxg3D pxg3D) {
if (pxg3D.getLastSheetName() != null &&
pxg3D.getLastSheetName().equals(oldName)) {
pxg3D.setLastSheetName(newName);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]