Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | 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.Collections");
14
dojo.collections.DictionaryEntry = function (k, v) {
15
	this.key = k;
16
	this.value = v;
17
	this.valueOf = function () {
18
		return this.value;
19
	};
20
	this.toString = function () {
21
		return String(this.value);
22
	};
23
};
24
dojo.collections.Iterator = function (arr) {
25
	var a = arr;
26
	var position = 0;
27
	this.element = a[position] || null;
28
	this.atEnd = function () {
29
		return (position >= a.length);
30
	};
31
	this.get = function () {
32
		if (this.atEnd()) {
33
			return null;
34
		}
35
		this.element = a[position++];
36
		return this.element;
37
	};
38
	this.map = function (fn, scope) {
39
		var s = scope || dj_global;
40
		if (Array.map) {
41
			return Array.map(a, fn, s);
42
		} else {
43
			var arr = [];
44
			for (var i = 0; i < a.length; i++) {
45
				arr.push(fn.call(s, a[i]));
46
			}
47
			return arr;
48
		}
49
	};
50
	this.reset = function () {
51
		position = 0;
52
		this.element = a[position];
53
	};
54
};
55
dojo.collections.DictionaryIterator = function (obj) {
56
	var a = [];
57
	var testObject = {};
58
	for (var p in obj) {
59
		if (!testObject[p]) {
60
			a.push(obj[p]);
61
		}
62
	}
63
	var position = 0;
64
	this.element = a[position] || null;
65
	this.atEnd = function () {
66
		return (position >= a.length);
67
	};
68
	this.get = function () {
69
		if (this.atEnd()) {
70
			return null;
71
		}
72
		this.element = a[position++];
73
		return this.element;
74
	};
75
	this.map = function (fn, scope) {
76
		var s = scope || dj_global;
77
		if (Array.map) {
78
			return Array.map(a, fn, s);
79
		} else {
80
			var arr = [];
81
			for (var i = 0; i < a.length; i++) {
82
				arr.push(fn.call(s, a[i]));
83
			}
84
			return arr;
85
		}
86
	};
87
	this.reset = function () {
88
		position = 0;
89
		this.element = a[position];
90
	};
91
};
92