@@ -42,6 +42,7 @@ of this software and associated documentation files (the "Software"), to deal
4242import java .io .Writer ;
4343import java .lang .reflect .Array ;
4444import java .util .ArrayList ;
45+ import java .util .Iterator ;
4546
4647import processing .core .PApplet ;
4748
@@ -561,6 +562,111 @@ public JSONObject getJSONObject(int index, JSONObject defaultValue) {
561562 }
562563
563564
565+ public Iterable <Boolean > booleanValues () {
566+ return () -> new Iterator <>() {
567+ int index = -1 ;
568+
569+ public Boolean next () {
570+ return getBoolean (++index );
571+ }
572+
573+ public boolean hasNext () {
574+ return index +1 < size ();
575+ }
576+ };
577+ }
578+
579+
580+ public Iterable <Integer > intValues () {
581+ return () -> new Iterator <>() {
582+ int index = -1 ;
583+
584+ public Integer next () {
585+ return getInt (++index );
586+ }
587+
588+ public boolean hasNext () {
589+ return index +1 < size ();
590+ }
591+ };
592+ }
593+
594+
595+ public Iterable <Long > longValues () {
596+ return () -> new Iterator <>() {
597+ int index = -1 ;
598+
599+ public Long next () {
600+ return getLong (++index );
601+ }
602+
603+ public boolean hasNext () {
604+ return index +1 < size ();
605+ }
606+ };
607+ }
608+
609+
610+ public Iterable <Float > floatValues () {
611+ return () -> new Iterator <>() {
612+ int index = -1 ;
613+
614+ public Float next () {
615+ return getFloat (++index );
616+ }
617+
618+ public boolean hasNext () {
619+ return index +1 < size ();
620+ }
621+ };
622+ }
623+
624+
625+ public Iterable <Double > doubleValues () {
626+ return () -> new Iterator <>() {
627+ int index = -1 ;
628+
629+ public Double next () {
630+ return getDouble (++index );
631+ }
632+
633+ public boolean hasNext () {
634+ return index +1 < size ();
635+ }
636+ };
637+ }
638+
639+
640+ public Iterable <JSONArray > arrayValues () {
641+ return () -> new Iterator <>() {
642+ int index = -1 ;
643+
644+ public JSONArray next () {
645+ return getJSONArray (++index );
646+ }
647+
648+ public boolean hasNext () {
649+ return index +1 < size ();
650+ }
651+ };
652+ }
653+
654+
655+ public Iterable <JSONObject > objectValues () {
656+ return () -> new Iterator <>() {
657+ int index = -1 ;
658+
659+ public JSONObject next () {
660+ return getJSONObject (++index );
661+ }
662+
663+ public boolean hasNext () {
664+ return index +1 < size ();
665+ }
666+ };
667+ }
668+
669+
564670 /** Use toStringArray() instead. */
565671 @ Deprecated
566672 public String [] getStringArray () {
0 commit comments