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 1539088d51 more instanceof changes (#1133)
1539088d51 is described below

commit 1539088d513d4bbafe6516a89db0df65d2885825
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Jun 11 14:46:56 2026 +0100

    more instanceof changes (#1133)
---
 .../apache/poi/xslf/draw/SVGRenderExtension.java   |  2 +-
 .../java/org/apache/poi/sl/draw/DrawFactory.java   | 48 +++++++++---------
 .../org/apache/poi/sl/draw/DrawMasterSheet.java    |  6 +--
 .../java/org/apache/poi/sl/draw/DrawPaint.java     | 17 ++++---
 .../java/org/apache/poi/sl/draw/DrawShape.java     | 58 +++++++++-------------
 .../org/apache/poi/sl/draw/DrawTableShape.java     | 20 ++++----
 .../org/apache/poi/sl/draw/DrawTextParagraph.java  |  4 +-
 .../java/org/apache/poi/sl/draw/DrawTextShape.java |  3 +-
 .../java/org/apache/poi/sl/draw/SLGraphics.java    |  6 +--
 .../java/org/apache/poi/sl/draw/geom/Context.java  |  4 +-
 .../poi/sl/extractor/SlideShowExtractor.java       | 50 +++++++++----------
 .../apache/poi/ss/util/DateFormatConverter.java    | 57 ++++++++-------------
 .../java/org/apache/poi/ss/util/SheetBuilder.java  | 15 +++---
 poi/src/main/java/org/apache/poi/util/IOUtils.java |  3 +-
 14 files changed, 133 insertions(+), 160 deletions(-)

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 c71b7fc130..53ed325050 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,7 +278,7 @@ 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 
simpleShape) {
+        if (!fill.isRotatedWithShape() && slShape instanceof SimpleShape<?,?> 
simpleShape) {
             double rot = simpleShape.getRotation();
             if (rot != 0) {
                 setAttribute(genCtx, patternDef,
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawFactory.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawFactory.java
index 9e17c867c8..d737dfc912 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawFactory.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawFactory.java
@@ -94,30 +94,30 @@ public class DrawFactory {
     }
 
     public Drawable getDrawable(Shape<?,?> shape) {
-        if (shape instanceof TextBox) {
-            return getDrawable((TextBox<?,?>)shape);
-        } else if (shape instanceof FreeformShape) {
-            return getDrawable((FreeformShape<?,?>)shape);
-        } else if (shape instanceof TextShape) {
-            return getDrawable((TextShape<?,?>)shape);
-        } else if (shape instanceof TableShape) {
-            return getDrawable((TableShape<?,?>)shape);
-        } else if (shape instanceof GroupShape) {
-            return getDrawable((GroupShape<?,?>)shape);
-        } else if (shape instanceof PictureShape) {
-            return getDrawable((PictureShape<?,?>)shape);
-        } else if (shape instanceof GraphicalFrame) {
-            return getDrawable((GraphicalFrame<?,?>)shape);
-        } else if (shape instanceof Background) {
-            return getDrawable((Background<?,?>)shape);
-        } else if (shape instanceof ConnectorShape) {
-            return getDrawable((ConnectorShape<?,?>)shape);
-        } else if (shape instanceof Slide) {
-            return getDrawable((Slide<?,?>)shape);
-        } else if (shape instanceof MasterSheet) {
-            return getDrawable((MasterSheet<?,?>)shape);
-        } else if (shape instanceof Sheet) {
-            return getDrawable((Sheet<?,?>)shape);
+        if (shape instanceof TextBox<?,?> tb) {
+            return getDrawable(tb);
+        } else if (shape instanceof FreeformShape<?,?> fs) {
+            return getDrawable(fs);
+        } else if (shape instanceof TextShape<?,?> ts) {
+            return getDrawable(ts);
+        } else if (shape instanceof TableShape<?,?> ts) {
+            return getDrawable(ts);
+        } else if (shape instanceof GroupShape<?,?> gs) {
+            return getDrawable(gs);
+        } else if (shape instanceof PictureShape<?,?> ps) {
+            return getDrawable(ps);
+        } else if (shape instanceof GraphicalFrame<?,?> gf) {
+            return getDrawable(gf);
+        } else if (shape instanceof Background<?,?> bg) {
+            return getDrawable(bg);
+        } else if (shape instanceof ConnectorShape<?,?> cs) {
+            return getDrawable(cs);
+        } else if (shape instanceof Slide<?,?> slide) {
+            return getDrawable(slide);
+        } else if (shape instanceof MasterSheet<?,?> sheet) {
+            return getDrawable(sheet);
+        } else if (shape instanceof Sheet<?,?> sheet) {
+            return getDrawable(sheet);
         } else if 
(shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {
             return new DrawNothing(shape);
         }
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java
index 01ab9dc0b7..9d1339052d 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java
@@ -41,11 +41,11 @@ public class DrawMasterSheet extends DrawSheet {
     @Override
     protected boolean canDraw(Graphics2D graphics, Shape<?,?> shape) {
         Slide<?,?> slide = 
(Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
-        if (shape instanceof SimpleShape) {
+        if (shape instanceof SimpleShape<?,?> ss) {
             // in XSLF, slidenumber and date shapes aren't marked as 
placeholders opposed to HSLF
-            Placeholder ph = ((SimpleShape<?,?>)shape).getPlaceholder();
+            Placeholder ph = ss.getPlaceholder();
             if (ph != null) {
-                return slide.getDisplayPlaceholder((SimpleShape<?, ?>)shape);
+                return slide.getDisplayPlaceholder(ss);
             }
         }
         return slide.getFollowMasterGraphics();
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawPaint.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawPaint.java
index 5ccdf8c2b5..57fc3fca84 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawPaint.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawPaint.java
@@ -134,10 +134,11 @@ public class DrawPaint {
             if (this == o) {
                 return true;
             }
-            if (!(o instanceof SolidPaint)) {
+            if (o instanceof SolidPaint oth) {
+                return Objects.equals(getSolidColor(), oth.getSolidColor());
+            } else {
                 return false;
             }
-            return Objects.equals(getSolidColor(), ((SolidPaint) 
o).getSolidColor());
         }
 
         @Override
@@ -162,12 +163,12 @@ public class DrawPaint {
         if (modifier == PaintModifier.NONE) {
             return TRANSPARENT;
         }
-        if (paint instanceof SolidPaint) {
-            return getSolidPaint((SolidPaint)paint, graphics, modifier);
-        } else if (paint instanceof GradientPaint) {
-            return getGradientPaint((GradientPaint)paint, graphics);
-        } else if (paint instanceof TexturePaint) {
-            return getTexturePaint((TexturePaint)paint, graphics);
+        if (paint instanceof SolidPaint sp) {
+            return getSolidPaint(sp, graphics, modifier);
+        } else if (paint instanceof GradientPaint gp) {
+            return getGradientPaint(gp, graphics);
+        } else if (paint instanceof TexturePaint tp) {
+            return getTexturePaint(tp, graphics);
         }
         return TRANSPARENT;
     }
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawShape.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawShape.java
index e1ab3bf176..4e1cda8d5d 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawShape.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawShape.java
@@ -56,52 +56,42 @@ public class DrawShape implements Drawable {
      */
     @Override
     public void applyTransform(Graphics2D graphics) {
-        if (!(shape instanceof PlaceableShape) || graphics == null) {
-            return;
-        }
-
-        final Rectangle2D anchor = getAnchor(graphics, 
(PlaceableShape<?,?>)shape);
-        if (anchor == null) {
-            return;
-        }
+        if (shape instanceof PlaceableShape<?,?> ps && graphics != null) {
+            final Rectangle2D anchor = getAnchor(graphics, ps);
+            if (anchor == null) {
+                return;
+            }
 
-        if (isHSLF(shape)) {
-            flipHorizontal(graphics, anchor);
-            flipVertical(graphics, anchor);
-            rotate(graphics, anchor);
-        } else {
-            rotate(graphics, anchor);
-            flipHorizontal(graphics, anchor);
-            flipVertical(graphics, anchor);
+            if (isHSLF(shape)) {
+                flipHorizontal(ps, graphics, anchor);
+                flipVertical(ps, graphics, anchor);
+                rotate(ps, graphics, anchor);
+            } else {
+                rotate(ps, graphics, anchor);
+                flipHorizontal(ps, graphics, anchor);
+                flipVertical(ps, graphics, anchor);
+            }
         }
     }
 
-    private void flipHorizontal(Graphics2D graphics, Rectangle2D anchor) {
-        assert(shape instanceof PlaceableShape && anchor != null);
-        if (((PlaceableShape<?,?>)shape).getFlipHorizontal()) {
-            graphics.translate(anchor.getX() + anchor.getWidth(), 
anchor.getY());
-            graphics.scale(-1, 1);
-            graphics.translate(-anchor.getX(), -anchor.getY());
-        }
+    private static void flipHorizontal(PlaceableShape<?,?> ps, Graphics2D 
graphics, Rectangle2D anchor) {
+        graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
+        graphics.scale(-1, 1);
+        graphics.translate(-anchor.getX(), -anchor.getY());
     }
 
-    private void flipVertical(Graphics2D graphics, Rectangle2D anchor) {
-        assert(shape instanceof PlaceableShape && anchor != null);
-        if (((PlaceableShape<?,?>)shape).getFlipVertical()) {
-            graphics.translate(anchor.getX(), anchor.getY() + 
anchor.getHeight());
-            graphics.scale(1, -1);
-            graphics.translate(-anchor.getX(), -anchor.getY());
-        }
+    private static void flipVertical(PlaceableShape<?,?> ps, Graphics2D 
graphics, Rectangle2D anchor) {
+        graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
+        graphics.scale(1, -1);
+        graphics.translate(-anchor.getX(), -anchor.getY());
     }
 
-    private void rotate(Graphics2D graphics, Rectangle2D anchor) {
-        assert(shape instanceof PlaceableShape && anchor != null);
-        double rotation = ((PlaceableShape<?,?>)shape).getRotation();
+    private static void rotate(PlaceableShape<?,?> ps, Graphics2D graphics, 
Rectangle2D anchor) {
+        double rotation = ps.getRotation();
         if (rotation != 0.) {
             // PowerPoint rotates shapes relative to the geometric center
             graphics.rotate(Math.toRadians(rotation), anchor.getCenterX(), 
anchor.getCenterY());
         }
-
     }
 
     private static double safeScale(double dim1, double dim2) {
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawTableShape.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawTableShape.java
index 1974f0d9a7..d8791b2d5b 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawTableShape.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawTableShape.java
@@ -46,9 +46,9 @@ public class DrawTableShape extends DrawShape {
     }
 
     protected Drawable getGroupShape(Graphics2D graphics) {
-        if (shape instanceof GroupShape) {
+        if (shape instanceof GroupShape<?,?> gs) {
             DrawFactory df = DrawFactory.getInstance(graphics);
-            return df.getDrawable((GroupShape<?,?>)shape);
+            return df.getDrawable(gs);
         }
         return null;
     }
@@ -242,14 +242,14 @@ public class DrawTableShape extends DrawShape {
                     cell.removeBorder(be);
                 } else {
                     for (Object o : args) {
-                        if (o instanceof Double) {
-                            cell.setBorderWidth(be, (Double)o);
-                        } else if (o instanceof Color) {
-                            cell.setBorderColor(be, (Color)o);
-                        } else if (o instanceof LineDash) {
-                            cell.setBorderDash(be, (LineDash)o);
-                        } else if (o instanceof LineCompound) {
-                            cell.setBorderCompound(be, (LineCompound)o);
+                        if (o instanceof Double d) {
+                            cell.setBorderWidth(be, d);
+                        } else if (o instanceof Color c) {
+                            cell.setBorderColor(be, c);
+                        } else if (o instanceof LineDash ld) {
+                            cell.setBorderDash(be, ld);
+                        } else if (o instanceof LineCompound lc) {
+                            cell.setBorderCompound(be, lc);
                         }
                     }
                 }
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java
index bed9dec44c..ce47b45f66 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java
@@ -613,9 +613,9 @@ public class DrawTextParagraph implements Drawable {
 
             att.put(TextAttribute.FOREGROUND, fgPaint);
 
-            if (run instanceof HighlightColorSupport) {
+            if (run instanceof HighlightColorSupport hcs) {
                 // Highlight color is only supported in XSLF (PPTX) text runs.
-                final PaintStyle highlightPaintStyle = 
((HighlightColorSupport)run).getHighlightColor();
+                final PaintStyle highlightPaintStyle = hcs.getHighlightColor();
                 if (highlightPaintStyle != null) {
                     final Paint bgPaint = dp.getPaint(graphics, 
highlightPaintStyle);
                     att.put(TextAttribute.BACKGROUND, bgPaint);
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/DrawTextShape.java 
b/poi/src/main/java/org/apache/poi/sl/draw/DrawTextShape.java
index d8d23b5676..6894895b0e 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/DrawTextShape.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/DrawTextShape.java
@@ -62,8 +62,7 @@ public class DrawTextShape extends DrawSimpleShape {
         boolean vertFlip = s.getFlipVertical();
         boolean horzFlip = s.getFlipHorizontal();
         ShapeContainer<?,?> sc = s.getParent();
-        while (sc instanceof PlaceableShape) {
-            PlaceableShape<?,?> ps = (PlaceableShape<?,?>)sc;
+        while (sc instanceof PlaceableShape<?,?> ps) {
             vertFlip ^= ps.getFlipVertical();
             horzFlip ^= ps.getFlipHorizontal();
             sc = ps.getParent();
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java 
b/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java
index 2d5c294565..fafac6c19f 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/SLGraphics.java
@@ -185,7 +185,7 @@ public class SLGraphics extends Graphics2D implements 
Cloneable {
         if(paint == null) return;
 
         this._paint = paint;
-        if (paint instanceof Color) _foreground = (Color)paint;
+        if (paint instanceof Color c) _foreground = c;
     }
 
     /**
@@ -234,8 +234,8 @@ public class SLGraphics extends Graphics2D implements 
Cloneable {
         p.setPath(path);
         p.setFillColor(null);
         applyStroke(p);
-        if (_paint instanceof Color) {
-            p.setStrokeStyle((Color)_paint);
+        if (_paint instanceof Color c) {
+            p.setStrokeStyle(c);
         }
     }
 
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java 
b/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java
index 2b7c571475..cb66206c94 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java
@@ -65,8 +65,8 @@ public class Context {
 
     public double evaluate(Formula fmla){
         double result = fmla.evaluate(this);
-        if (fmla instanceof GuideIf) {
-            String key = ((GuideIf)fmla).getName();
+        if (fmla instanceof GuideIf guideIf) {
+            String key = guideIf.getName();
             if (key != null) {
                 _ctx.put(key, result);
             }
diff --git 
a/poi/src/main/java/org/apache/poi/sl/extractor/SlideShowExtractor.java 
b/poi/src/main/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
index 5735434d30..5fe11234ee 100644
--- a/poi/src/main/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
+++ b/poi/src/main/java/org/apache/poi/sl/extractor/SlideShowExtractor.java
@@ -220,28 +220,26 @@ public class SlideShowExtractor<
 
         // write header texts and determine footer text
         for (Shape<S, P> s : m) {
-            if (!(s instanceof TextShape)) {
-                continue;
-            }
-            final TextShape<S, P> ts = (TextShape<S, P>) s;
-            final PlaceholderDetails pd = ts.getPlaceholderDetails();
-            if (pd == null || !pd.isVisible() || pd.getPlaceholder() == null) {
-                continue;
-            }
-            switch (pd.getPlaceholder()) {
-                case HEADER:
-                    printTextParagraphs(ts.getTextParagraphs(), consumer);
-                    break;
-                case FOOTER:
-                    printTextParagraphs(ts.getTextParagraphs(), footerCon);
-                    break;
-                case SLIDE_NUMBER:
-                    printTextParagraphs(ts.getTextParagraphs(), footerCon, 
"\n", SlideShowExtractor::replaceSlideNumber);
-                    break;
-                case DATETIME:
-                    // currently not supported
-                default:
-                    break;
+            if (s instanceof TextShape<S, P> ts) {
+                final PlaceholderDetails pd = ts.getPlaceholderDetails();
+                if (pd == null || !pd.isVisible() || pd.getPlaceholder() == 
null) {
+                    continue;
+                }
+                switch (pd.getPlaceholder()) {
+                    case HEADER:
+                        printTextParagraphs(ts.getTextParagraphs(), consumer);
+                        break;
+                    case FOOTER:
+                        printTextParagraphs(ts.getTextParagraphs(), footerCon);
+                        break;
+                    case SLIDE_NUMBER:
+                        printTextParagraphs(ts.getTextParagraphs(), footerCon, 
"\n", SlideShowExtractor::replaceSlideNumber);
+                        break;
+                    case DATETIME:
+                        // currently not supported
+                    default:
+                        break;
+                }
             }
         }
     }
@@ -265,10 +263,10 @@ public class SlideShowExtractor<
     @SuppressWarnings("unchecked")
     private void printShapeText(final ShapeContainer<S,P> container, final 
Consumer<String> consumer) {
         for (Shape<S,P> shape : container) {
-            if (shape instanceof TextShape) {
-                
printTextParagraphs(((TextShape<S,P>)shape).getTextParagraphs(), consumer);
-            } else if (shape instanceof TableShape) {
-                printShapeText((TableShape<S,P>)shape, consumer);
+            if (shape instanceof TextShape<S,P> ts) {
+                printTextParagraphs(ts.getTextParagraphs(), consumer);
+            } else if (shape instanceof TableShape<S,P> ts) {
+                printShapeText(ts, consumer);
             } else if (shape instanceof ShapeContainer) {
                 printShapeText((ShapeContainer<S,P>)shape, consumer);
             }
diff --git a/poi/src/main/java/org/apache/poi/ss/util/DateFormatConverter.java 
b/poi/src/main/java/org/apache/poi/ss/util/DateFormatConverter.java
index 60d2578f5e..de2a3e48d2 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/DateFormatConverter.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/DateFormatConverter.java
@@ -163,8 +163,10 @@ public final class DateFormatConverter  {
     }
 
     public static String convert( Locale locale, DateFormat df ) {
-        String ptrn = ((SimpleDateFormat)df).toPattern();
-        return convert(locale, ptrn);
+        if (df instanceof SimpleDateFormat sdf) {
+            return convert(locale, sdf.toPattern());
+        }
+        throw new IllegalArgumentException("Unsupported DateFormat class: " + 
df.getClass().getName());
     }
 
     public static String convert( Locale locale, String format ) {
@@ -190,20 +192,15 @@ public final class DateFormatConverter  {
 
     public static String getJavaDatePattern(int style, Locale locale) {
         DateFormat df = DateFormat.getDateInstance(style, locale);
-        if( df instanceof SimpleDateFormat ) {
-            return ((SimpleDateFormat)df).toPattern();
+        if( df instanceof SimpleDateFormat sdf) {
+            return sdf.toPattern();
         } else {
-            switch( style ) {
-            case DateFormat.SHORT:
-                return "d/MM/yy";
-            case DateFormat.LONG:
-                return "MMMM d, yyyy";
-            case DateFormat.FULL:
-                return "dddd, MMMM d, yyyy";
-            default:
-            case DateFormat.MEDIUM:
-                return "MMM d, yyyy";
-            }
+            return switch (style) {
+                case DateFormat.SHORT -> "d/MM/yy";
+                case DateFormat.LONG -> "MMMM d, yyyy";
+                case DateFormat.FULL -> "dddd, MMMM d, yyyy";
+                default -> "MMM d, yyyy";
+            };
         }
     }
 
@@ -212,15 +209,10 @@ public final class DateFormatConverter  {
         if( df instanceof SimpleDateFormat ) {
             return ((SimpleDateFormat)df).toPattern();
         } else {
-            switch( style ) {
-            case DateFormat.SHORT:
-                return "h:mm a";
-            default:
-            case DateFormat.MEDIUM:
-            case DateFormat.LONG:
-            case DateFormat.FULL:
-                return "h:mm:ss a";
-            }
+            return switch (style) {
+                case DateFormat.SHORT -> "h:mm a";
+                default -> "h:mm:ss a";
+            };
         }
     }
 
@@ -229,17 +221,12 @@ public final class DateFormatConverter  {
         if( df instanceof SimpleDateFormat ) {
             return ((SimpleDateFormat)df).toPattern();
         } else {
-            switch( style ) {
-            case DateFormat.SHORT:
-                return "M/d/yy h:mm a";
-            case DateFormat.LONG:
-                return "MMMM d, yyyy h:mm:ss a";
-            case DateFormat.FULL:
-                return "dddd, MMMM d, yyyy h:mm:ss a";
-            default:
-            case DateFormat.MEDIUM:
-                return "MMM d, yyyy h:mm:ss a";
-            }
+            return switch (style) {
+                case DateFormat.SHORT -> "M/d/yy h:mm a";
+                case DateFormat.LONG -> "MMMM d, yyyy h:mm:ss a";
+                case DateFormat.FULL -> "dddd, MMMM d, yyyy h:mm:ss a";
+                default -> "MMM d, yyyy h:mm:ss a";
+            };
         }
     }
 
diff --git a/poi/src/main/java/org/apache/poi/ss/util/SheetBuilder.java 
b/poi/src/main/java/org/apache/poi/ss/util/SheetBuilder.java
index 1801dedb3f..df14b61592 100644
--- a/poi/src/main/java/org/apache/poi/ss/util/SheetBuilder.java
+++ b/poi/src/main/java/org/apache/poi/ss/util/SheetBuilder.java
@@ -124,13 +124,13 @@ public class SheetBuilder {
             return;
         }
 
-        if (value instanceof Number) {
-            double doubleValue = ((Number) value).doubleValue();
+        if (value instanceof Number num) {
+            double doubleValue = num.doubleValue();
             cell.setCellValue(doubleValue);
-        } else if (value instanceof Date) {
-            cell.setCellValue((Date) value);
-        } else if (value instanceof Calendar) {
-            cell.setCellValue((Calendar) value);
+        } else if (value instanceof Date d) {
+            cell.setCellValue(d);
+        } else if (value instanceof Calendar c) {
+            cell.setCellValue(c);
         } else if (isFormulaDefinition(value)) {
             cell.setCellFormula(getFormula(value));
         } else {
@@ -139,8 +139,7 @@ public class SheetBuilder {
     }
 
     private boolean isFormulaDefinition(Object obj) {
-        if (obj instanceof String) {
-            String str = (String) obj;
+        if (obj instanceof String str) {
             return str.length() >= 2 && str.charAt(0) == '=';
         } else {
             return false;
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java 
b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 652fcbd19c..744fc4317a 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -161,8 +161,7 @@ public final class IOUtils {
                 bos.write(new byte[limit-readBytes]);
             }
             byte[] peekedBytes = bos.toByteArray();
-            if(stream instanceof PushbackInputStream) {
-                PushbackInputStream pin = (PushbackInputStream)stream;
+            if(stream instanceof PushbackInputStream pin) {
                 pin.unread(peekedBytes, 0, readBytes);
             } else {
                 stream.reset();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to