diff --git a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java index ee6daceea9f0a727f0f20bb9413af94c1034a84d..7112e01f428d077cf4d1a61c5d3177962d12bab5 100644 --- a/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java +++ b/unl-tools-core/src/main/java/fr/tetras_libre/unltools/unl/Graph.java @@ -97,15 +97,17 @@ public class Graph { return graphNode; } -// public GraphNode getNodesWithinSubgraph(String graphNumber){ -// if (null == graphNumber) throw new IllegalArgumentException("GraphNumber cannot be null"); -// -// var result = this.relations.stream().filter(e -> graphNumber.equals(e.getSubGraphReferenceLabel())).findFirst().get(); -// if (null != result.getNode1()) return result.getNode1(); -// if (null != result.getNode2()) return result.getNode2(); -// -// throw new RuntimeException(String.format("Cannot find any graph node within '%s' subgraph", graphNumber)); -// } + public GraphNode getNodesWithinSubgraph(String graphNumber){ + if (null == graphNumber) throw new IllegalArgumentException("GraphNumber cannot be null"); + + var result = this.relations.stream().filter(e -> graphNumber.equals(e.getSubGraphReferenceLabel())).findFirst(); + if (result.isPresent()) { + if (null != result.get().getNode1()) return result.get().getNode1(); + if (null != result.get().getNode2()) return result.get().getNode2(); + } + + throw new RuntimeException(String.format("Cannot find any graph node within '%s' subgraph", graphNumber)); + } @Override public java.lang.String toString() { diff --git a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java index 5811bb5f776ff4ee51666b678449d51dcf6b24f7..9f06cc75d1ee70d43a808298f42759b720f28b87 100644 --- a/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java +++ b/unl-tools-infrastructure/src/main/java/fr/tetras_libre/unltools/unl/exporters/dot/DotFileGraphExporter.java @@ -70,10 +70,9 @@ public class DotFileGraphExporter implements GraphExporter { * @param scope The current scope name * @param g The graph to export * @throws IOException An I/O error occurred - * @throws NoEntryNodeException Inconsistent nodes reference inside the graph * @see IOException */ - private void WriteCluster(String scope, Graph g) throws IOException, NoEntryNodeException { + private void WriteCluster(String scope, Graph g) throws IOException { writer.append(String.format("subgraph cluster_%s{\n", scope.substring(1))) .append(" color = black;\n") .append(String.format(" label = \"%s\"", scope)); @@ -133,11 +132,10 @@ public class DotFileGraphExporter implements GraphExporter { * * @param graphRelation A GraphRelation inside graph g * @param g The current graphe to export - * @throws NoEntryNodeException One node in graphRelation is not found in g * @throws IOException An I/O error occurred * @see IOException */ - private void write(GraphRelation graphRelation, Graph g) throws NoEntryNodeException, IOException { + private void write(GraphRelation graphRelation, Graph g) throws IOException { GraphNode n1 = graphRelation.getNode1(); GraphNode n2 = graphRelation.getNode2(); @@ -162,16 +160,15 @@ public class DotFileGraphExporter implements GraphExporter { * @param g the global graph * @return if graphNode is SubGraphRelationNode the node number of the referenced node in g, * otherwise the node number of the current node in graphNode - * @throws NoEntryNodeException No corresponding node found in g for the corresponding inside graphNode */ - private String getTextForSubGraphRelationOrGetNodeNumber(GraphNode graphNode, Graph g) throws NoEntryNodeException { + private String getTextForSubGraphRelationOrGetNodeNumber(GraphNode graphNode, Graph g) { if (graphNode instanceof SubGraphReferenceNode) { -// try{ + try{ return Integer.toString(g.getEntryNode(((SubGraphReferenceNode) graphNode).getReferenceNumber()).getNodeNumber()); -// } -// catch (NoEntryNodeException ex){ -// return Integer.toString(g.getNodesWithinSubgraph(((SubGraphReferenceNode) graphNode).getReferenceNumber()).getNodeNumber()); -// } + } + catch (NoEntryNodeException ex){ + return Integer.toString(g.getNodesWithinSubgraph(((SubGraphReferenceNode) graphNode).getReferenceNumber()).getNodeNumber()); + } } else { return Integer.toString(graphNode.getNodeNumber()); }