@@ -95,14 +95,15 @@ public with sharing class CollectionFunctions {
95
95
if (children == null ) {
96
96
return new List <Object >();
97
97
}
98
- if (! (children instanceof List < Object > )) {
98
+ if (! (children instanceof Iterable < Object > )) {
99
99
throw new FunctionExecutionException (
100
- ' Error executing "MAP" function: the first argument must evaluate to a list .'
100
+ ' Error executing "MAP" function: the first argument must evaluate to an iterable .'
101
101
);
102
102
}
103
103
104
+ List <Object > childrenAsList = CollectionUtils .toObjectList ((Iterable <Object >) children );
105
+
104
106
// If the list of children is empty, return early
105
- List <Object > childrenAsList = (List <Object >) children ;
106
107
if (childrenAsList .isEmpty ()) {
107
108
return new List <Object >();
108
109
}
@@ -147,14 +148,14 @@ public with sharing class CollectionFunctions {
147
148
if (children == null ) {
148
149
return new List <Object >();
149
150
}
150
- if (! (children instanceof List < Object > )) {
151
+ if (! (children instanceof Iterable < Object > )) {
151
152
throw new FunctionExecutionException (
152
- ' Error executing "WHERE" function: the first argument must evaluate to a list .'
153
+ ' Error executing "WHERE" function: the first argument must evaluate to an iterable .'
153
154
);
154
155
}
155
156
156
157
// If the list of children is empty, return early
157
- List <Object > childrenAsList = ( List <Object >) children ;
158
+ List <Object > childrenAsList = CollectionUtils . toObjectList (( Iterable <Object >) children ) ;
158
159
if (childrenAsList .isEmpty ()) {
159
160
return new List <Object >();
160
161
}
@@ -207,13 +208,13 @@ public with sharing class CollectionFunctions {
207
208
Object listOfNumbers = evaluate (arguments .get (0 ));
208
209
209
210
// Verify that all elements in the list are numbers
210
- if (! (listOfNumbers instanceof List < Object > )) {
211
+ if (! (listOfNumbers instanceof Iterable < Object > )) {
211
212
throw new FunctionExecutionException (
212
- ' Error executing "AVERAGE" function: the argument must evaluate to a list of numbers.'
213
+ ' Error executing "AVERAGE" function: the argument must evaluate to an iterable of numbers.'
213
214
);
214
215
}
215
216
216
- List <Object > listOfNumbersAsList = ( List <Object >) listOfNumbers ;
217
+ List <Object > listOfNumbersAsList = CollectionUtils . toObjectList (( Iterable <Object >) listOfNumbers ) ;
217
218
// Sanitize nulls
218
219
List <Object > sanitizedList = new List <Object >();
219
220
for (Object maybeNull : listOfNumbersAsList ) {
@@ -254,14 +255,14 @@ public with sharing class CollectionFunctions {
254
255
public override Object call (List <Expr > arguments ) {
255
256
Object listOfValues = evaluate (arguments .get (0 ));
256
257
// Must be a list or a map
257
- if (! (listOfValues instanceof List < Object > ) && ! (listOfValues instanceof Map < Object , Object > )) {
258
+ if (! (listOfValues instanceof Iterable < Object > ) && ! (listOfValues instanceof Map < Object , Object > )) {
258
259
throw new FunctionExecutionException (
259
- ' Error executing "SIZE" function: the argument must evaluate to a list or a map.'
260
+ ' Error executing "SIZE" function: the argument must evaluate to an iterable or a map.'
260
261
);
261
262
}
262
263
263
- if (listOfValues instanceof List < Object > ) {
264
- return (( List <Object >) listOfValues ).size ();
264
+ if (listOfValues instanceof Iterable < Object > ) {
265
+ return CollectionUtils . toObjectList (( Iterable <Object >) listOfValues ).size ();
265
266
} else {
266
267
return ((Map <Object , Object >) listOfValues ).size ();
267
268
}
@@ -283,14 +284,14 @@ public with sharing class CollectionFunctions {
283
284
public override Object call (List <Expr > arguments ) {
284
285
// The argument must either be a list or a map
285
286
Object value = evaluate (arguments .get (0 ));
286
- if (! (value instanceof List < Object > ) && ! (value instanceof Map < Object , Object > )) {
287
+ if (! (value instanceof Iterable < Object > ) && ! (value instanceof Map < Object , Object > )) {
287
288
throw new FunctionExecutionException (
288
- ' Error executing "ISEMPTY" function: the argument must evaluate to a list or a map.'
289
+ ' Error executing "ISEMPTY" function: the argument must evaluate to an iterable or a map.'
289
290
);
290
291
}
291
292
292
- if (value instanceof List < Object > ) {
293
- return (( List <Object >) value ).isEmpty ();
293
+ if (value instanceof Iterable < Object > ) {
294
+ return CollectionUtils . toObjectList (( Iterable <Object >) value ).isEmpty ();
294
295
} else {
295
296
return ((Map <Object , Object >) value ).isEmpty ();
296
297
}
@@ -312,12 +313,12 @@ public with sharing class CollectionFunctions {
312
313
public override Object call (List <Expr > arguments ) {
313
314
Object listObj = evaluate (arguments .get (0 )) ?? new List <Object >();
314
315
Object item = evaluate (arguments .get (1 ));
315
- if (! (listObj instanceof List < Object > )) {
316
+ if (! (listObj instanceof Iterable < Object > )) {
316
317
throw new FunctionExecutionException (
317
- ' Error executing "APPEND" function: the first argument must evaluate to a list .'
318
+ ' Error executing "APPEND" function: the first argument must evaluate to an iterable .'
318
319
);
319
320
}
320
- List <Object > result = new List < Object >(( List <Object >) listObj );
321
+ List <Object > result = CollectionUtils . toObjectList (( Iterable <Object >) listObj );
321
322
result .add (item );
322
323
return result ;
323
324
}
@@ -451,9 +452,9 @@ public with sharing class CollectionFunctions {
451
452
public override Object call (List <Expr > arguments ) {
452
453
// First argument is a list
453
454
Object listObj = evaluate (arguments .get (0 ));
454
- if (! (listObj instanceof List < Object > )) {
455
+ if (! (listObj instanceof Iterable < Object > )) {
455
456
throw new FunctionExecutionException (
456
- ' Error executing "SORT" function: the first argument must evaluate to a list .'
457
+ ' Error executing "SORT" function: the first argument must evaluate to an iterable .'
457
458
);
458
459
}
459
460
@@ -497,7 +498,7 @@ public with sharing class CollectionFunctions {
497
498
}
498
499
499
500
// If the list is empty, return early
500
- List <Object > listVal = ( List <Object >) listObj ;
501
+ List <Object > listVal = CollectionUtils . toObjectList (( Iterable <Object >) listObj ) ;
501
502
if (listVal .isEmpty ()) {
502
503
return listVal ;
503
504
}
@@ -701,9 +702,9 @@ public with sharing class CollectionFunctions {
701
702
public override Object call (List <Expr > arguments ) {
702
703
// First argument is a list
703
704
Object listObj = evaluate (arguments .get (0 ));
704
- if (! (listObj instanceof List < Object > )) {
705
+ if (! (listObj instanceof Iterable < Object > )) {
705
706
throw new FunctionExecutionException (
706
- ' Error executing "REDUCE" function: the first argument must evaluate to a list .'
707
+ ' Error executing "REDUCE" function: the first argument must evaluate to an iterable .'
707
708
);
708
709
}
709
710
@@ -714,7 +715,7 @@ public with sharing class CollectionFunctions {
714
715
Object initialValue = evaluate (arguments .get (2 ));
715
716
716
717
// If the list is empty, return early
717
- List <Object > listVal = ( List <Object >) listObj ;
718
+ List <Object > listVal = CollectionUtils . toObjectList (( Iterable <Object >) listObj ) ;
718
719
if (listVal .isEmpty ()) {
719
720
return initialValue ;
720
721
}
@@ -835,17 +836,17 @@ public with sharing class CollectionFunctions {
835
836
public override Object call (List <Expr > arguments ) {
836
837
// First argument is a list
837
838
Object listObj = evaluate (arguments .get (0 ));
838
- if (! (listObj instanceof List < Object > )) {
839
+ if (! (listObj instanceof Iterable < Object > )) {
839
840
throw new FunctionExecutionException (
840
- ' Error executing "ANY" function: the first argument must evaluate to a list .'
841
+ ' Error executing "ANY" function: the first argument must evaluate to an iterable .'
841
842
);
842
843
}
843
844
844
845
// Second argument is an expression
845
846
Expr expr = arguments .get (1 );
846
847
847
848
// If the list is empty, return early
848
- List <Object > listVal = ( List <Object >) listObj ;
849
+ List <Object > listVal = CollectionUtils . toObjectList (( Iterable <Object >) listObj ) ;
849
850
if (listVal .isEmpty ()) {
850
851
return false ;
851
852
}
@@ -887,14 +888,14 @@ public with sharing class CollectionFunctions {
887
888
public override Object call (List <Expr > arguments ) {
888
889
// First argument is a list
889
890
Object listObj = evaluate (arguments .get (0 ));
890
- if (! (listObj instanceof List < Object > )) {
891
+ if (! (listObj instanceof Iterable < Object > )) {
891
892
throw new FunctionExecutionException (
892
- ' Error executing "SUM" function: the first argument must evaluate to a list .'
893
+ ' Error executing "SUM" function: the first argument must evaluate to an iterable .'
893
894
);
894
895
}
895
896
896
897
// If the list is empty, return early
897
- List <Object > listVal = ( List <Object >) listObj ;
898
+ List <Object > listVal = CollectionUtils . toObjectList (( Iterable <Object >) listObj ) ;
898
899
if (listVal .isEmpty ()) {
899
900
return 0 ;
900
901
}
@@ -928,17 +929,17 @@ public with sharing class CollectionFunctions {
928
929
public override Object call (List <Expr > arguments ) {
929
930
// First argument is a list
930
931
Object listObj = evaluate (arguments .get (0 ));
931
- if (! (listObj instanceof List < Object > )) {
932
+ if (! (listObj instanceof Iterable < Object > )) {
932
933
throw new FunctionExecutionException (
933
- ' Error executing "EVERY" function: the first argument must evaluate to a list .'
934
+ ' Error executing "EVERY" function: the first argument must evaluate to an iterable .'
934
935
);
935
936
}
936
937
937
938
// Second argument is an expression
938
939
Expr expr = arguments .get (1 );
939
940
940
941
// If the list is empty, return early
941
- List <Object > listVal = ( List <Object >) listObj ;
942
+ List <Object > listVal = CollectionUtils . toObjectList (( Iterable <Object >) listObj ) ;
942
943
if (listVal .isEmpty ()) {
943
944
return false ;
944
945
}
0 commit comments