Commit ca8dbc11 authored by SR-Lut3t1um's avatar SR-Lut3t1um

minimal optimization

parent df616657
Pipeline #89177 passed with stages
in 2 minutes and 54 seconds
......@@ -7,7 +7,7 @@ public class Latex {
public static String serializeAutomaton(Automaton obj) {
StringBuilder sb = new StringBuilder("\\begin{tikzpicture}");
for (State state : obj.getStates()) {
sb.append(serializeState(state, obj.getStart()));
serializeState(state, obj.getStart(), sb);
}
sb.append("\n \\path[->] ");
for (State state : obj.getStates()) {
......@@ -17,8 +17,8 @@ public class Latex {
return sb.toString();
}
private static String serializeState(State state, State initial) {
StringBuilder sb = new StringBuilder("\n \\node[state");
private static void serializeState(State state, State initial, StringBuilder sb) {
sb.append("\n \\node[state");
if (state == initial) sb.append(",initial");
if (state.isAccepting()) sb.append(",accepting");
sb.append("] (")
......@@ -30,7 +30,6 @@ public class Latex {
.append(") {$")
.append(state.getName())
.append("$};");
return sb.toString();
}
private static void serializeStateTransitions(State state, StringBuilder sb) {
......@@ -47,7 +46,8 @@ public class Latex {
}
}
public static Object deSerialzeObject(String latex) {
public static Object deSerializeObject(String latex) {
// @toDo
return null;
}
}
......@@ -22,14 +22,13 @@ public class AutomatonResourceTest {
ArrayList<String> alphabet = new ArrayList<>();
alphabet.add("a");
Automaton a = new Automaton("test", new User("Test"), alphabet);
a.addState(new State("q1", 0, 0, 0, true));
a.addState(new State("q2", 1, 2, 0, true));
a.addState(new State("q1", 0, 0, 0, false));
a.addState(new State("q2", 1, 2, 0, false));
a.addState(new State("q3", 2, 4, 0, true));
a.addPath(a.getStates().get(0), 0, a.getStates().get(1));
System.out.println(Latex.serializeAutomaton(a));
assert ("\\begin{tikzpicture}\n"
+ " \\node[state,initial,accepting] (0) at (0,0) {$q1$};\n"
+ " \\node[state,accepting] (1) at (2,0) {$q2$};\n"
+ " \\node[state,initial] (0) at (0,0) {$q1$};\n"
+ " \\node[state] (1) at (2,0) {$q2$};\n"
+ " \\node[state,accepting] (2) at (4,0) {$q3$};\n"
+ " \\path[->] \n"
+ " (0) edge node [above] [align=center] {$a$} (1); \n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment