mirror of
https://github.com/processing/processing4.git
synced 2026-01-25 01:11:06 +01:00
iterators for JSONArray types
This commit is contained in:
@@ -42,6 +42,7 @@ import java.io.StringWriter;
|
||||
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 class JSONArray {
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Boolean> booleanValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public Boolean next() {
|
||||
return getBoolean(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Integer> intValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public Integer next() {
|
||||
return getInt(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Long> longValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public Long next() {
|
||||
return getLong(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Float> floatValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public Float next() {
|
||||
return getFloat(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Double> doubleValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public Double next() {
|
||||
return getDouble(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<JSONArray> arrayValues() {
|
||||
return () -> new Iterator<>() {
|
||||
int index = -1;
|
||||
|
||||
public JSONArray next() {
|
||||
return getJSONArray(++index);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return index+1 < size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Iterable<JSONObject> 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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user