From 47bff8194214f8d5a7cc1333552c240be1ea2cab Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Thu, 4 Apr 2019 00:51:10 +0200 Subject: [PATCH] Split methods --- src/main/java/grafos/CFG.java | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/grafos/CFG.java b/src/main/java/grafos/CFG.java index 10f2a02..16ac2cb 100644 --- a/src/main/java/grafos/CFG.java +++ b/src/main/java/grafos/CFG.java @@ -123,22 +123,21 @@ public class CFG { return res; } - private String node2str(Node s) { - if (s == beginNode) - return "Start"; - if (s == endNode) - return "Stop"; - int index = -1; - for (int i = 0; i < nodes.size(); i++) { - if (nodes.get(i) == s) { - index = i; - break; - } - } - if (index == -1) - throw new RuntimeException("Internal error, can't find node"); - return "\"(" + (index + 1) + ", " + s.getRange().get().begin.line + ") " - + s.toString().replace("\"", "\\\"") + "\""; + private String node2str(Node n) { + if (n == beginNode) return "Start"; + if (n == endNode) return "Stop"; + return String.format("\"(%d, %d) %s\"", indexOfNode(n) + 1, n.getRange().get().begin.line, escape(n.toString())); + } + + private int indexOfNode(Node n) { + for (int i = 0; i < nodes.size(); i++) + if (nodes.get(i) == n) + return i; + throw new RuntimeException("Internal error, can't find node in list"); + } + + private String escape(String s) { + return s.replace("\"", "\\\""); } private static int clusterId = 0;