Subversion Repositories Applications.papyrus

Rev

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