diff --git a/core/src/processing/data/JSONArray.java b/core/src/processing/data/JSONArray.java index 2823dcdf3..f6157e23a 100644 --- a/core/src/processing/data/JSONArray.java +++ b/core/src/processing/data/JSONArray.java @@ -42,6 +42,7 @@ of this software and associated documentation files (the "Software"), to deal import java.io.Writer; import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Iterator; import processing.core.PApplet; @@ -561,6 +562,111 @@ public JSONObject getJSONObject(int index, JSONObject defaultValue) { } + public Iterable booleanValues() { + return () -> new Iterator<>() { + int index = -1; + + public Boolean next() { + return getBoolean(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable intValues() { + return () -> new Iterator<>() { + int index = -1; + + public Integer next() { + return getInt(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable longValues() { + return () -> new Iterator<>() { + int index = -1; + + public Long next() { + return getLong(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable floatValues() { + return () -> new Iterator<>() { + int index = -1; + + public Float next() { + return getFloat(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable doubleValues() { + return () -> new Iterator<>() { + int index = -1; + + public Double next() { + return getDouble(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable arrayValues() { + return () -> new Iterator<>() { + int index = -1; + + public JSONArray next() { + return getJSONArray(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + + public Iterable objectValues() { + return () -> new Iterator<>() { + int index = -1; + + public JSONObject next() { + return getJSONObject(++index); + } + + public boolean hasNext() { + return index+1 < size(); + } + }; + } + + /** Use toStringArray() instead. */ @Deprecated public String[] getStringArray() { diff --git a/core/todo.txt b/core/todo.txt index 6d2d592f2..5c888546e 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,6 +1,7 @@ 1294 (4.3.1) X difference in text position with processing 4.3, JAVA2D vs P2D X https://github.com/processing/processing4/issues/768 +X add iterators to JSONArray contribs @@ -13,6 +14,9 @@ X https://github.com/processing/processing4/pull/776 X Fix `PShape.getSpecular()`, `getEmissive()`, and `getShininess()` from @hx2A X https://github.com/processing/processing4/issues/781 X https://github.com/processing/processing4/pull/782 +_ Fix hash of keyEvent being added to pressedKeys +_ https://github.com/processing/processing4/issues/779 +_ https://github.com/processing/processing4/pull/786 _ JNA version of getting resolution