Skip to content

Commit d6d59fc

Browse files
committed
[#757] Add validator that detects the cyclic imports. Change API for printBF
1 parent a10a461 commit d6d59fc

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

dmn-core/src/main/java/com/gs/dmn/Graph.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.gs.dmn.runtime.Pair;
1616

1717
import java.io.IOException;
18-
import java.io.StringWriter;
1918
import java.io.Writer;
2019
import java.util.*;
2120
import java.util.function.Function;
@@ -156,18 +155,18 @@ public void printNodes(Writer writer, Function<T, String> nodeInfo) throws IOExc
156155
}
157156
}
158157

159-
public void printBF(T rootNode, StringWriter writer, Function<T, String> nodeInfo) {
158+
public void printBF(T rootNode, Writer writer, Function<T, String> nodeInfo) throws IOException {
160159
printBF(rootNode, writer, nodeInfo, x -> true);
161160
}
162161

163-
public void printBF(T rootNode, StringWriter writer, Function<T, String> nodeInfo, Predicate<T> filter) {
162+
public void printBF(T rootNode, Writer writer, Function<T, String> nodeInfo, Predicate<T> filter) throws IOException {
164163
Set<T> visited = new LinkedHashSet<>();
165164
if (filter.test(rootNode)) {
166165
printBF(rootNode, writer, nodeInfo, filter, 0, visited);
167166
}
168167
}
169168

170-
private void printBF(T node, StringWriter writer, Function<T, String> nodeInfo, Predicate<T> filter, int level, Set<T> visited) {
169+
private void printBF(T node, Writer writer, Function<T, String> nodeInfo, Predicate<T> filter, int level, Set<T> visited) throws IOException {
171170
String indent = "\t".repeat(level);
172171
writer.write(indent + nodeInfo.apply(node) + "\n");
173172
if (!visited.contains(node)) {

dmn-core/src/test/java/com/gs/dmn/GraphTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ void testPrintNodes() throws IOException {
148148
StringWriter writer = new StringWriter();
149149
graph.printNodes(writer, this::nodeInfo);
150150
String expectedNodes = "1\n2\n3\n4\n";
151-
assertEquals(expectedNodes, writer.getBuffer().toString());
151+
assertEquals(expectedNodes, writer.toString());
152152
}
153153

154154
@Test
155-
void testPrintTree() {
155+
void testPrintTree() throws IOException {
156156
Graph<Integer> graph = new Graph<>();
157157
graph.addEdge(1, 2);
158158
graph.addEdge(2, 3);
@@ -171,7 +171,7 @@ void testPrintTree() {
171171
\t\t\t4
172172
\t\t\t\t2
173173
""";
174-
assertEquals(expectedNodes, writer.getBuffer().toString());
174+
assertEquals(expectedNodes, writer.toString());
175175
}
176176

177177
private String nodeInfo(Integer node) {

0 commit comments

Comments
 (0)