aboutsummaryrefslogtreecommitdiffstats
path: root/poi-scratchpad/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-12-29 13:08:56 +0000
committerPJ Fanning <fanningpj@apache.org>2021-12-29 13:08:56 +0000
commit6784dd81c2abc907e98e49450f39e9475ffb09b0 (patch)
tree9a8ca4114fe58f09cd8a4e91beecd0d23b67766a /poi-scratchpad/src
parent79a1e6b1e90c613958f91739f15c5f8512f7ee0b (diff)
downloadpoi-6784dd81c2abc907e98e49450f39e9475ffb09b0.tar.gz
poi-6784dd81c2abc907e98e49450f39e9475ffb09b0.zip
update some code based on sonar issues
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896504 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad/src')
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
index cd5f61fdaf..899b053ddc 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -205,6 +206,12 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
final Rectangle2D b = getBoundsInPoints();
return new Dimension2DDouble(abs(b.getWidth()), abs(b.getHeight()));
}
+
+ /**
+ * @param ctx
+ * @param graphicsBounds
+ * @throws IllegalStateException if the draw fails
+ */
public void draw(Graphics2D ctx, Rectangle2D graphicsBounds) {
final Shape clip = ctx.getClip();
final AffineTransform at = ctx.getTransform();
@@ -232,8 +239,13 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
? winBounds
: emfBounds;
} else {
- b = Stream.of(emfBounds, winBounds, viewBounds).
- min(comparingDouble(r -> diff(r, recBounds))).get();
+ Optional<Rectangle2D> result = Stream.of(emfBounds, winBounds, viewBounds).
+ min(comparingDouble(r -> diff(r, recBounds)));
+ if (result.isPresent()) {
+ b = result.get();
+ } else {
+ throw new IllegalStateException("Failed to create Rectangle2D for drawing");
+ }
}
ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
@@ -245,7 +257,7 @@ public class HemfPicture implements Iterable<HemfRecord>, GenericRecord {
HemfGraphics g = new HemfGraphics(ctx, b);
- int idx=0;
+ int idx = 0;
for (HemfRecord r : getRecords()) {
try {
g.draw(r);