Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.collections.Queue");
14
dojo.require("dojo.collections.Collections");
15
dojo.collections.Queue = function (arr) {
16
	var q = [];
17
	if (arr) {
18
		q = q.concat(arr);
19
	}
20
	this.count = q.length;
21
	this.clear = function () {
22
		q = [];
23
		this.count = q.length;
24
	};
25
	this.clone = function () {
26
		return new dojo.collections.Queue(q);
27
	};
28
	this.contains = function (o) {
29
		for (var i = 0; i < q.length; i++) {
30
			if (q[i] == o) {
31
				return true;
32
			}
33
		}
34
		return false;
35
	};
36
	this.copyTo = function (arr, i) {
37
		arr.splice(i, 0, q);
38
	};
39
	this.dequeue = function () {
40
		var r = q.shift();
41
		this.count = q.length;
42
		return r;
43
	};
44
	this.enqueue = function (o) {
45
		this.count = q.push(o);
46
	};
47
	this.forEach = function (fn, scope) {
48
		var s = scope || dj_global;
49
		if (Array.forEach) {
50
			Array.forEach(q, fn, s);
51
		} else {
52
			for (var i = 0; i < q.length; i++) {
53
				fn.call(s, q[i], i, q);
54
			}
55
		}
56
	};
57
	this.getIterator = function () {
58
		return new dojo.collections.Iterator(q);
59
	};
60
	this.peek = function () {
61
		return q[0];
62
	};
63
	this.toArray = function () {
64
		return [].concat(q);
65
	};
66
};
67