Avoid use of try-catch as control flow
This commit is contained in:
parent
51885d8c53
commit
5be59b37f0
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Controller {
|
||||
private final Logger logger = LoggerFactory.getLogger(ShapesView.class);
|
||||
private final static Logger logger = LoggerFactory.getLogger(ShapesView.class);
|
||||
private final ShapesView view;
|
||||
private final Shape model;
|
||||
private Selection selection;
|
||||
@ -46,7 +46,7 @@ public class Controller {
|
||||
s -> {
|
||||
if (selection != null) resetSelection();
|
||||
selection = new Selection(s, true);
|
||||
this.logger.debug("Selecting {}", selection.shape);
|
||||
logger.debug("Selecting {}", selection.shape);
|
||||
},
|
||||
() -> {
|
||||
if (selection != null) resetSelection();
|
||||
@ -56,7 +56,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
private void resetSelection() {
|
||||
this.logger.debug("Un-selecting {}", selection.shape);
|
||||
logger.debug("Un-selecting {}", selection.shape);
|
||||
selection.unselect();
|
||||
selection = null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user