source: Dev/trunk/src/client/dojox/collections/Queue.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

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