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.Stack");
14
dojo.require("dojo.collections.Collections");
15
dojo.collections.Stack = 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.Stack(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.forEach = function (fn, scope) {
40
		var s = scope || dj_global;
41
		if (Array.forEach) {
42
			Array.forEach(q, fn, s);
43
		} else {
44
			for (var i = 0; i < q.length; i++) {
45
				fn.call(s, q[i], i, q);
46
			}
47
		}
48
	};
49
	this.getIterator = function () {
50
		return new dojo.collections.Iterator(q);
51
	};
52
	this.peek = function () {
53
		return q[(q.length - 1)];
54
	};
55
	this.pop = function () {
56
		var r = q.pop();
57
		this.count = q.length;
58
		return r;
59
	};
60
	this.push = function (o) {
61
		this.count = q.push(o);
62
	};
63
	this.toArray = function () {
64
		return [].concat(q);
65
	};
66
};
67