Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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