Skip to content

Commit

Permalink
Remove unnecessary try catch blocks
Browse files Browse the repository at this point in the history
For invalid graphs throw UnsupportedConfigurationException instead
of IllegalArgumentException
  • Loading branch information
Eddykasp committed Oct 12, 2023
1 parent 21ba60a commit 973ff09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.elk.alg.yconstree.p4absolute.AbsoluteXPlacerStrategy;
import org.eclipse.elk.alg.yconstree.p5edgerouting.EdgerouterStrategy;
import org.eclipse.elk.core.AbstractLayoutProvider;
import org.eclipse.elk.core.UnsupportedConfigurationException;
import org.eclipse.elk.core.alg.AlgorithmAssembler;
import org.eclipse.elk.core.alg.ILayoutProcessor;
import org.eclipse.elk.core.util.IElkProgressMonitor;
Expand All @@ -40,14 +41,14 @@ public void layout(final ElkNode graph, final IElkProgressMonitor progressMonito
ElkNode root = YconstreeUtil.findRoot(graph);
graph.setProperty(InternalProperties.ROOT_NODE, root);
if (root == null) {
throw new IllegalArgumentException("The given graph is not a tree!");
throw new UnsupportedConfigurationException("The given graph is not a tree!");
}

for (ElkNode child : graph.getChildren()) {
int numberOfParents;
numberOfParents = child.getIncomingEdges().size();
if (numberOfParents > 1) {
throw new IllegalArgumentException("The given graph is not an acyclic tree!");
throw new UnsupportedConfigurationException("The given graph is not an acyclic tree!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ public class NodeYPlacer implements ILayoutPhase<YconstreeLayoutPhases, ElkNode>

@Override
public void process(final ElkNode graph, final IElkProgressMonitor progressMonitor) {
//elkGraph.setX(0.0);

myProgressMonitor = progressMonitor;
myProgressMonitor.begin("YPlacer", 1);

try {
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);
setYLevels(parent, 0.0);
}
} catch (Exception e) {
// TODO Auto-generated catch block
// Handle this exception properly
e.printStackTrace();

if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);
setYLevels(parent, 0.0);
}

myProgressMonitor.done();
Expand All @@ -58,7 +53,6 @@ private void setYLevels(final ElkNode node, double minHeight) {
// TODO figure out what below todo means and whether it is still relevant
// TODO: Y-Level_Constraints, remove different heightlevels.
if (node.hasProperty(YconstreeOptions.VERTICAL_CONSTRAINT)) {
myProgressMonitor.log("hier hab ich einen Constraint");
minHeight = node.getProperty(YconstreeOptions.VERTICAL_CONSTRAINT);
}
node.setY(minHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,16 @@ public void process(final ElkNode graph, final IElkProgressMonitor progressMonit

spacingNodeNode = graph.getProperty(CoreOptions.SPACING_NODE_NODE);

try {
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

String strategy = graph.getProperty(YconstreeOptions.LAYOUT_STRATEGY);
if (strategy == null || strategy.equals("straight")) { //TODO use enum instead of string for strategy
yConsTreeStep(parent);
} else {
alternativeYConsTreeStep(parent);
}

if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

String strategy = graph.getProperty(YconstreeOptions.LAYOUT_STRATEGY);
if (strategy == null || strategy.equals("straight")) { //TODO use enum instead of string for strategy
yConsTreeStep(parent);
} else {
alternativeYConsTreeStep(parent);
}
} catch (Exception e) {
// TODO properly handle exceptions
// TODO Auto-generated catch block
e.printStackTrace();

}

myProgressMonitor.done();
Expand Down Expand Up @@ -379,7 +373,7 @@ private void alternativeYConsTreeStep(final ElkNode graph) {
*/
private void sortSubTrees(final List<ElkNode> children) {

// fist, we sort the SubTrees by the Y-coordinate of their root.
// first, we sort the SubTrees by the Y-coordinate of their root.
Collections.sort(children, new NodeComparator());

// now we need to put them in a V-shape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,17 @@ public void process(final ElkNode graph, final IElkProgressMonitor progressMonit
myProgressMonitor = progressMonitor;
myProgressMonitor.begin("AbsolutPlacer", 1);

try {
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

// first, move the root
parent.setX(parent.getX() - findMinimalX(parent));
// a little offset
parent.setX(parent.getX() + 10.0); // TODO remove magic number
// now we update the whole tree to absolute X
absoluteTreeCoords(parent);
}
} catch (Exception e) {
// TODO properly handle exception
// TODO Auto-generated catch block
e.printStackTrace();
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

// first, move the root
parent.setX(parent.getX() - findMinimalX(parent));
// a little offset
parent.setX(parent.getX() + 10.0); // TODO remove magic number
// now we update the whole tree to absolute X
absoluteTreeCoords(parent);
}

myProgressMonitor.done();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ public void process(final ElkNode graph, final IElkProgressMonitor progressMonit
myProgressMonitor = progressMonitor;
myProgressMonitor.begin("EdgeRouter", 1);

try {
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

routeEdges(parent);
setCanvas(graph);
}
} catch (Exception e) {
// TODO properly handle exceptions
// TODO Auto-generated catch block
e.printStackTrace();
if (!graph.getChildren().isEmpty()) {
ElkNode parent = graph.getProperty(InternalProperties.ROOT_NODE);

routeEdges(parent);
setCanvas(graph);
}

myProgressMonitor.done();
}

Expand Down

0 comments on commit 973ff09

Please sign in to comment.