Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.collections.Queue");
12
dojo.require("dojo.collections.Collections");
13
dojo.collections.Queue = function (arr) {
14
	var q = [];
15
	if (arr) {
16
		q = q.concat(arr);
17
	}
18
	this.count = q.length;
19
	this.clear = function () {
20
		q = [];
21
		this.count = q.length;
22
	};
23
	this.clone = function () {
24
		return new dojo.collections.Queue(q);
25
	};
26
	this.contains = function (o) {
27
		for (var i = 0; i < q.length; i++) {
28
			if (q[i] == o) {
29
				return true;
30
			}
31
		}
32
		return false;
33
	};
34
	this.copyTo = function (arr, i) {
35
		arr.splice(i, 0, q);
36
	};
37
	this.dequeue = function () {
38
		var r = q.shift();
39
		this.count = q.length;
40
		return r;
41
	};
42
	this.enqueue = function (o) {
43
		this.count = q.push(o);
44
	};
45
	this.forEach = function (fn, scope) {
46
		var s = scope || dj_global;
47
		if (Array.forEach) {
48
			Array.forEach(q, fn, s);
49
		} else {
50
			for (var i = 0; i < q.length; i++) {
51
				fn.call(s, q[i], i, q);
52
			}
53
		}
54
	};
55
	this.getIterator = function () {
56
		return new dojo.collections.Iterator(q);
57
	};
58
	this.peek = function () {
59
		return q[0];
60
	};
61
	this.toArray = function () {
62
		return [].concat(q);
63
	};
64
};
65