Created
October 12, 2018 13:00
-
-
Save dr0i/a66ba0014057a5e3c4b863f70f4d6212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RecursionStream { | |
public static void main(String... args) { | |
getAllJsonNodes(node)// | |
.peek(p -> System.out.println("endpeek" + p)) | |
.forEach(p -> System.out.println("end" + cnt + ":" + p.toString())); | |
} | |
private Stream<JsonNode> getAllJsonNodes(JsonNode node) { | |
cnt++; | |
Iterable<Entry<String, JsonNode>> iterable = () -> node.fields(); | |
return StreamSupport.stream(iterable.spliterator(), false) | |
.filter(e -> e.getValue().getNodeType().equals(JsonNodeType.OBJECT))// | |
.peek(p -> System.out.println("cnt" + cnt + ":" + p))// | |
.flatMap(m -> getAllJsonNodes(m.getValue())); | |
} | |
} |
Though without the terminalOperation "forEach" it wouldn't start to begin with.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"endpeek" and "end" is never printed, why is this?