Avoid use of try-catch as control flow
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package ovh.gasser.newshapes.shapes;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ovh.gasser.newshapes.App;
|
||||
import ovh.gasser.newshapes.attributes.SelectionAttributes;
|
||||
import ovh.gasser.newshapes.ShapeVisitor;
|
||||
import ovh.gasser.newshapes.attributes.SelectionAttributes;
|
||||
import ovh.gasser.newshapes.util.Streamable;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -11,6 +13,7 @@ import java.util.List;
|
||||
import java.util.Spliterator;
|
||||
|
||||
public class SCollection extends AbstractShape implements Streamable<Shape> {
|
||||
private final static Logger logger = LoggerFactory.getLogger(SCollection.class);
|
||||
private final List<Shape> children;
|
||||
|
||||
private SCollection(Shape... shapes) {
|
||||
@@ -25,12 +28,17 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
try {
|
||||
if (children.isEmpty()) {
|
||||
// If the SCollection is empty, set the bounds to fill the window
|
||||
return new Rectangle(App.WIN_SIZE);
|
||||
}
|
||||
|
||||
Rectangle bounds = children.get(0).getBounds();
|
||||
for (Shape s : children) bounds = bounds.union(s.getBounds());
|
||||
return bounds;
|
||||
} catch (IndexOutOfBoundsException e){
|
||||
// If the SCollection is empty, set the bounds to fill the window
|
||||
return new Rectangle(App.WIN_SIZE);
|
||||
logger.error("getBounds(): {}");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user