33import org .jetbrains .annotations .NotNull ;
44import org .jetbrains .annotations .Nullable ;
55
6- import java .util .ArrayList ;
7- import java .util .Iterator ;
8- import java .util .List ;
9- import java .util .Objects ;
6+ import java .util .*;
107import java .util .function .Consumer ;
8+ import java .util .function .Predicate ;
119import java .util .stream .Stream ;
1210
1311/**
@@ -39,7 +37,7 @@ public boolean equals(Object object) {
3937
4038 @ Override
4139 public String toString () {
42- return Json .write (this , Json . Formatting . INLINE_PRETTY );
40+ return Json .write (this , JsonFormatting . INLINE );
4341 }
4442
4543 @ Override
@@ -95,6 +93,54 @@ public boolean has(Element element) {
9593 return this .elements .contains (element );
9694 }
9795
96+ public boolean has (String value ) {
97+ return this .has (Element .string (value ));
98+ }
99+
100+ public boolean has (Number value ) {
101+ return this .has (Element .number (value ));
102+ }
103+
104+ public boolean has (Boolean value ) {
105+ return this .has (Element .bool (value ));
106+ }
107+
108+ public void each (Consumer <Element > consumer ) {
109+ if (consumer == null ) {
110+ throw new IllegalArgumentException ("Consumer cannot be null!" );
111+ }
112+
113+ this .elements .forEach (consumer );
114+ }
115+
116+ public boolean all (Predicate <Element > predicate ) {
117+ if (predicate == null ) {
118+ throw new IllegalArgumentException ("Predicate cannot be null!" );
119+ }
120+
121+ for (var element : this .elements ) {
122+ if (!predicate .test (element )) {
123+ return false ;
124+ }
125+ }
126+
127+ return true ;
128+ }
129+
130+ public boolean any (Predicate <Element > predicate ) {
131+ if (predicate == null ) {
132+ throw new IllegalArgumentException ("Predicate cannot be null!" );
133+ }
134+
135+ for (var element : this .elements ) {
136+ if (predicate .test (element )) {
137+ return true ;
138+ }
139+ }
140+
141+ return false ;
142+ }
143+
98144 public ArrayElement append (Element element ) {
99145 if (element == null ) throw new IllegalArgumentException ("Element cannot be null!" );
100146 return this .copy (list -> list .add (element ));
@@ -112,6 +158,23 @@ public ArrayElement append(String element) {
112158 return this .append (Element .string (element ));
113159 }
114160
161+ public ArrayElement set (int index , Element element ) {
162+ if (element == null ) throw new IllegalArgumentException ("Element cannot be null!" );
163+ return this .copy (list -> list .set (index , element ));
164+ }
165+
166+ public ArrayElement set (int index , boolean element ) {
167+ return this .set (index , Element .bool (element ));
168+ }
169+
170+ public ArrayElement set (int index , Number element ) {
171+ return this .set (index , Element .number (element ));
172+ }
173+
174+ public ArrayElement set (int index , String element ) {
175+ return this .set (index , Element .string (element ));
176+ }
177+
115178 public ArrayElement insert (int index , Element element ) {
116179 if (element == null ) throw new IllegalArgumentException ("Element cannot be null!" );
117180 return this .copy (list -> list .add (index , element ));
@@ -129,30 +192,34 @@ public ArrayElement insert(int index, String element) {
129192 return this .insert (index , Element .string (element ));
130193 }
131194
132- public ArrayElement removeAt (int index ) {
195+ public ArrayElement remove (int index ) {
133196 return this .copy (list -> list .remove (index ));
134197 }
135198
136- public ArrayElement remove (Element element ) {
199+ public ArrayElement removeValue (Element element ) {
137200 return this .copy (list -> list .remove (element ));
138201 }
139202
140- public ArrayElement remove (boolean element ) {
141- return this .remove (Element .bool (element ));
203+ public ArrayElement removeValue (boolean element ) {
204+ return this .removeValue (Element .bool (element ));
142205 }
143206
144- public ArrayElement remove (Number element ) {
145- return this .remove (Element .number (element ));
207+ public ArrayElement removeValue (Number element ) {
208+ return this .removeValue (Element .number (element ));
146209 }
147210
148- public ArrayElement remove (String element ) {
149- return this .remove (Element .string (element ));
211+ public ArrayElement removeValue (String element ) {
212+ return this .removeValue (Element .string (element ));
150213 }
151214
152215 public ArrayElement clear () {
153216 return this .copy (List ::clear );
154217 }
155218
219+ public ArrayElement reverse () {
220+ return this .copy (Collections ::reverse );
221+ }
222+
156223 public ArrayElement copy (Consumer <List <Element >> mutator ) {
157224 if (mutator == null ) throw new IllegalArgumentException ("Mutator cannot be null!" );
158225 var list = new ArrayList <>(this .elements );
0 commit comments