johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [johnzon] rmannibucau commented on a change in pull request #74: True object and array streaming
Date Sat, 10 Jul 2021 07:05:32 GMT

rmannibucau commented on a change in pull request #74:
URL: https://github.com/apache/johnzon/pull/74#discussion_r667302376



##########
File path: johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
##########
@@ -134,18 +140,57 @@ public void skipArray() {
 
     @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();
+        Event current = current();
+        if (current != Event.START_ARRAY) {
+            throw new IllegalStateException(current + " doesn't support getArrayStream()");
+        }
+
+        Spliterator<JsonValue> arraySpliterator = new Spliterators.AbstractSpliterator<JsonValue>(

Review comment:
       What about making it an inner private class reused in both locations (private static
class)?
   

##########
File path: johnzon-core/src/main/java/org/apache/johnzon/core/JohnzonJsonParserImpl.java
##########
@@ -134,18 +140,57 @@ public void skipArray() {
 
     @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();
+        Event current = current();
+        if (current != Event.START_ARRAY) {
+            throw new IllegalStateException(current + " doesn't support getArrayStream()");
+        }
+
+        Spliterator<JsonValue> arraySpliterator = new Spliterators.AbstractSpliterator<JsonValue>(
+                Long.MAX_VALUE, Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.ORDERED)
{
+
+            @Override
+            public boolean tryAdvance(Consumer<? super JsonValue> action) {
+                Event next = next();
+
+                if (next == Event.END_ARRAY) {
+                    return false;
+                } else {

Review comment:
       no need of else since first branch "returns"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@johnzon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message