You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by st...@apache.org on 2017/11/10 11:14:52 UTC

johnzon git commit: JOHNZON-139 add preliminary stream support

Repository: johnzon
Updated Branches:
  refs/heads/master 7c6933dcd -> 356c7f587


JOHNZON-139 add preliminary stream support


Project: http://git-wip-us.apache.org/repos/asf/johnzon/repo
Commit: http://git-wip-us.apache.org/repos/asf/johnzon/commit/356c7f58
Tree: http://git-wip-us.apache.org/repos/asf/johnzon/tree/356c7f58
Diff: http://git-wip-us.apache.org/repos/asf/johnzon/diff/356c7f58

Branch: refs/heads/master
Commit: 356c7f587f870fac18ceee84a433234264c42f2c
Parents: 7c6933d
Author: Mark Struberg <st...@apache.org>
Authored: Fri Nov 10 12:13:49 2017 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Nov 10 12:13:49 2017 +0100

----------------------------------------------------------------------
 .../johnzon/core/JohnzonJsonParserImpl.java     | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/johnzon/blob/356c7f58/johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
----------------------------------------------------------------------
diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
index 5939119..5fa051a 100644
--- a/johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
+++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
@@ -17,6 +17,9 @@
 package org.apache.johnzon.core;
 
 
+import java.util.Map;
+import java.util.stream.Stream;
+
 import javax.json.JsonArray;
 import javax.json.JsonObject;
 import javax.json.JsonValue;
@@ -94,4 +97,34 @@ public abstract class JohnzonJsonParserImpl implements JohnzonJsonParser {
         }
     }
 
+    @Override
+    public Stream<JsonValue> getArrayStream() {
+        //X TODO this implementation is very simplistic
+        //X I find it unintuitive what the spec intends here
+        //X we probably need to improve this
+        return getArray().stream();
+    }
+
+    @Override
+    public Stream<Map.Entry<String, JsonValue>> getObjectStream() {
+        //X TODO this implementation is very simplistic
+        //X I find it unintuitive what the spec intends here
+        //X we probably need to improve this
+        return getObject().entrySet().stream();
+    }
+
+    @Override
+    public Stream<JsonValue> getValueStream() {
+        //X TODO this implementation is very simplistic
+        //X I find it unintuitive what the spec intends here
+        //X we probably need to improve this
+        Event current = current();
+        if (current  == Event.START_ARRAY) {
+            return getArrayStream();
+        }
+        if (current  == Event.START_OBJECT) {
+            return getObject().values().stream();
+        }
+        throw new IllegalStateException(current + " doesn't support getValueStream");
+    }
 }