summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/RoseTree.java
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-01 10:38:08 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-06-01 10:38:08 +1000
commitedfce37bc21699042baf14ad6d172d3187fe530c (patch)
tree7e3379e7a0f2a1c5ba203bea72f468941ca13dad /src/main/java/au/id/zancanaro/RoseTree.java
parent7e1182355d54f0dc8461ce7df7c4aca8c40d2a92 (diff)
Add @DataSource, allow printing of RoseTrees, other small changes to generators
Diffstat (limited to 'src/main/java/au/id/zancanaro/RoseTree.java')
-rw-r--r--src/main/java/au/id/zancanaro/RoseTree.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/au/id/zancanaro/RoseTree.java b/src/main/java/au/id/zancanaro/RoseTree.java
index 6ba5c1c..458d441 100644
--- a/src/main/java/au/id/zancanaro/RoseTree.java
+++ b/src/main/java/au/id/zancanaro/RoseTree.java
@@ -1,7 +1,7 @@
package au.id.zancanaro;
-import java.io.OutputStream;
-import java.util.Arrays;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import java.util.Iterator;
import java.util.function.Function;
@@ -84,4 +84,20 @@ public class RoseTree<T> {
throw new IllegalArgumentException("Current value doesn't match predicate: whoops!");
}
}
+
+ @SuppressWarnings("unused")
+ public void print(Writer output) throws IOException {
+ print(output, Object::toString);
+ }
+
+ @SuppressWarnings("unused")
+ public void print(Writer output, Function<T, String> toString) throws IOException {
+ output.write(toString.apply(this.getValue()));
+ output.write('[');
+ for (RoseTree<T> child : children) {
+ child.print(output, toString);
+ }
+ output.write(']');
+ output.flush();
+ }
}