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._base"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.collections._base"] = true;
3
dojo.provide("dojox.collections._base");
4
 
5
dojox.collections.DictionaryEntry=function(/* string */k, /* object */v){
6
	//	summary
7
	//	return an object of type dojox.collections.DictionaryEntry
8
	this.key=k;
9
	this.value=v;
10
	this.valueOf=function(){
11
		return this.value; 	//	object
12
	};
13
	this.toString=function(){
14
		return String(this.value);	//	string
15
	};
16
}
17
 
18
/*	Iterators
19
 *	The collections.Iterators (Iterator and DictionaryIterator) are built to
20
 *	work with the Collections included in this module.  However, they *can*
21
 *	be used with arrays and objects, respectively, should one choose to do so.
22
 */
23
dojox.collections.Iterator=function(/* array */arr){
24
	//	summary
25
	//	return an object of type dojox.collections.Iterator
26
	var a=arr;
27
	var position=0;
28
	this.element=a[position]||null;
29
	this.atEnd=function(){
30
		//	summary
31
		//	Test to see if the internal cursor has reached the end of the internal collection.
32
		return (position>=a.length);	//	bool
33
	};
34
	this.get=function(){
35
		//	summary
36
		//	Get the next member in the collection.
37
		if(this.atEnd()){
38
			return null;		//	object
39
		}
40
		this.element=a[position++];
41
		return this.element;	//	object
42
	};
43
	this.map=function(/* function */fn, /* object? */scope){
44
		//	summary
45
		//	Functional iteration with optional scope.
46
		return dojo.map(a, fn, scope);
47
	};
48
	this.reset=function(){
49
		//	summary
50
		//	reset the internal cursor.
51
		position=0;
52
		this.element=a[position];
53
	};
54
}
55
 
56
/*	Notes:
57
 *	The DictionaryIterator no longer supports a key and value property;
58
 *	the reality is that you can use this to iterate over a JS object
59
 *	being used as a hashtable.
60
 */
61
dojox.collections.DictionaryIterator=function(/* object */obj){
62
	//	summary
63
	//	return an object of type dojox.collections.DictionaryIterator
64
	var a=[];	//	Create an indexing array
65
	var testObject={};
66
	for(var p in obj){
67
		if(!testObject[p]){
68
			a.push(obj[p]);	//	fill it up
69
		}
70
	}
71
	var position=0;
72
	this.element=a[position]||null;
73
	this.atEnd=function(){
74
		//	summary
75
		//	Test to see if the internal cursor has reached the end of the internal collection.
76
		return (position>=a.length);	//	bool
77
	};
78
	this.get=function(){
79
		//	summary
80
		//	Get the next member in the collection.
81
		if(this.atEnd()){
82
			return null;		//	object
83
		}
84
		this.element=a[position++];
85
		return this.element;	//	object
86
	};
87
	this.map=function(/* function */fn, /* object? */scope){
88
		//	summary
89
		//	Functional iteration with optional scope.
90
		return dojo.map(a, fn, scope);
91
	};
92
	this.reset=function() {
93
		//	summary
94
		//	reset the internal cursor.
95
		position=0;
96
		this.element=a[position];
97
	};
98
};
99
 
100
}