Add support for java.util.Collection to utils.foreach()
This commit is contained in:
parent
89b2dca496
commit
777fb9ce5b
2 changed files with 7 additions and 5 deletions
|
@ -1065,7 +1065,7 @@ Miscellaneous utility functions and classes to help with programming.
|
||||||
utils.foreach() function
|
utils.foreach() function
|
||||||
========================
|
========================
|
||||||
The utils.foreach() function is a utility function for iterating over
|
The utils.foreach() function is a utility function for iterating over
|
||||||
an array of objects and processing each one in turn. Where
|
an array of objects (or a java.util.Collection of objects) and processing each object in turn. Where
|
||||||
utils.foreach() differs from other similar functions found in
|
utils.foreach() differs from other similar functions found in
|
||||||
javascript libraries, is that utils.foreach can process the array
|
javascript libraries, is that utils.foreach can process the array
|
||||||
immediately or can process it *nicely* by processing one item at a
|
immediately or can process it *nicely* by processing one item at a
|
||||||
|
@ -1079,7 +1079,7 @@ package for scheduling processing of arrays.
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
|
||||||
* array : The array to be processed
|
* array : The array to be processed - It can be a javascript array, a java array or java.util.Collection
|
||||||
* callback : The function to be called to process each item in the
|
* callback : The function to be called to process each item in the
|
||||||
array. The callback function should have the following signature
|
array. The callback function should have the following signature
|
||||||
`callback(item, index, object, array)`. That is the callback will
|
`callback(item, index, object, array)`. That is the callback will
|
||||||
|
|
|
@ -25,7 +25,7 @@ var utils = utils || {
|
||||||
utils.foreach() function
|
utils.foreach() function
|
||||||
========================
|
========================
|
||||||
The utils.foreach() function is a utility function for iterating over
|
The utils.foreach() function is a utility function for iterating over
|
||||||
an array of objects and processing each one in turn. Where
|
an array of objects (or a java.util.Collection of objects) and processing each object in turn. Where
|
||||||
utils.foreach() differs from other similar functions found in
|
utils.foreach() differs from other similar functions found in
|
||||||
javascript libraries, is that utils.foreach can process the array
|
javascript libraries, is that utils.foreach can process the array
|
||||||
immediately or can process it *nicely* by processing one item at a
|
immediately or can process it *nicely* by processing one item at a
|
||||||
|
@ -39,7 +39,7 @@ package for scheduling processing of arrays.
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
|
||||||
* array : The array to be processed
|
* array : The array to be processed - It can be a javascript array, a java array or java.util.Collection
|
||||||
* callback : The function to be called to process each item in the
|
* callback : The function to be called to process each item in the
|
||||||
array. The callback function should have the following signature
|
array. The callback function should have the following signature
|
||||||
`callback(item, index, object, array)`. That is the callback will
|
`callback(item, index, object, array)`. That is the callback will
|
||||||
|
@ -97,7 +97,9 @@ without hogging CPU usage...
|
||||||
foreach (a, processItem, null, 10, onDone);
|
foreach (a, processItem, null, 10, onDone);
|
||||||
|
|
||||||
***/
|
***/
|
||||||
foreach: function(array, callback, object, delay, onCompletion){
|
foreach: function(array, callback, object, delay, onCompletion) {
|
||||||
|
if (array instanceof java.util.Collection)
|
||||||
|
array = array.toArray();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var len = array.length;
|
var len = array.length;
|
||||||
if (delay){
|
if (delay){
|
||||||
|
|
Reference in a new issue