| 2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.collections.Queue"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.collections.Queue"] = true;
|
|
|
3 |
dojo.provide("dojox.collections.Queue");
|
|
|
4 |
dojo.require("dojox.collections._base");
|
|
|
5 |
|
|
|
6 |
dojox.collections.Queue=function(/* array? */arr){
|
|
|
7 |
// summary
|
|
|
8 |
// return an object of type dojox.collections.Queue
|
|
|
9 |
var q=[];
|
|
|
10 |
if (arr){
|
|
|
11 |
q=q.concat(arr);
|
|
|
12 |
}
|
|
|
13 |
this.count=q.length;
|
|
|
14 |
this.clear=function(){
|
|
|
15 |
// summary
|
|
|
16 |
// clears the internal collection
|
|
|
17 |
q=[];
|
|
|
18 |
this.count=q.length;
|
|
|
19 |
};
|
|
|
20 |
this.clone=function(){
|
|
|
21 |
// summary
|
|
|
22 |
// creates a new Queue based on this one
|
|
|
23 |
return new dojox.collections.Queue(q); // dojox.collections.Queue
|
|
|
24 |
};
|
|
|
25 |
this.contains=function(/* object */ o){
|
|
|
26 |
// summary
|
|
|
27 |
// Check to see if the passed object is an element in this queue
|
|
|
28 |
for(var i=0; i<q.length; i++){
|
|
|
29 |
if (q[i]==o){
|
|
|
30 |
return true; // bool
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
return false; // bool
|
|
|
34 |
};
|
|
|
35 |
this.copyTo=function(/* array */ arr, /* int */ i){
|
|
|
36 |
// summary
|
|
|
37 |
// Copy the contents of this queue into the passed array at index i.
|
|
|
38 |
arr.splice(i,0,q);
|
|
|
39 |
};
|
|
|
40 |
this.dequeue=function(){
|
|
|
41 |
// summary
|
|
|
42 |
// shift the first element off the queue and return it
|
|
|
43 |
var r=q.shift();
|
|
|
44 |
this.count=q.length;
|
|
|
45 |
return r; // object
|
|
|
46 |
};
|
|
|
47 |
this.enqueue=function(/* object */ o){
|
|
|
48 |
// summary
|
|
|
49 |
// put the passed object at the end of the queue
|
|
|
50 |
this.count=q.push(o);
|
|
|
51 |
};
|
|
|
52 |
this.forEach=function(/* function */ fn, /* object? */ scope){
|
|
|
53 |
// summary
|
|
|
54 |
// functional iterator, following the mozilla spec.
|
|
|
55 |
dojo.forEach(q, fn, scope);
|
|
|
56 |
};
|
|
|
57 |
this.getIterator=function(){
|
|
|
58 |
// summary
|
|
|
59 |
// get an Iterator based on this queue.
|
|
|
60 |
return new dojox.collections.Iterator(q); // dojox.collections.Iterator
|
|
|
61 |
};
|
|
|
62 |
this.peek=function(){
|
|
|
63 |
// summary
|
|
|
64 |
// get the next element in the queue without altering the queue.
|
|
|
65 |
return q[0];
|
|
|
66 |
};
|
|
|
67 |
this.toArray=function(){
|
|
|
68 |
// summary
|
|
|
69 |
// return an array based on the internal array of the queue.
|
|
|
70 |
return [].concat(q);
|
|
|
71 |
};
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
}
|