Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
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:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.collections.Dictionary");
13
dojo.provide("dojo.collections.Dictionary");
12
dojo.require("dojo.collections.Collections");
14
dojo.require("dojo.collections.Collections");
13
dojo.collections.Dictionary = function (dictionary) {
15
dojo.collections.Dictionary = function (dictionary) {
14
	var items = {};
16
	var items = {};
15
	this.count = 0;
17
	this.count = 0;
16
	var testObject = {};
18
	var testObject = {};
17
	this.add = function (k, v) {
19
	this.add = function (k, v) {
18
		var b = (k in items);
20
		var b = (k in items);
19
		items[k] = new dojo.collections.DictionaryEntry(k, v);
21
		items[k] = new dojo.collections.DictionaryEntry(k, v);
20
		if (!b) {
22
		if (!b) {
21
			this.count++;
23
			this.count++;
22
		}
24
		}
23
	};
25
	};
24
	this.clear = function () {
26
	this.clear = function () {
25
		items = {};
27
		items = {};
26
		this.count = 0;
28
		this.count = 0;
27
	};
29
	};
28
	this.clone = function () {
30
	this.clone = function () {
29
		return new dojo.collections.Dictionary(this);
31
		return new dojo.collections.Dictionary(this);
30
	};
32
	};
31
	this.contains = this.containsKey = function (k) {
33
	this.contains = this.containsKey = function (k) {
32
		if (testObject[k]) {
34
		if (testObject[k]) {
33
			return false;
35
			return false;
34
		}
36
		}
35
		return (items[k] != null);
37
		return (items[k] != null);
36
	};
38
	};
37
	this.containsValue = function (v) {
39
	this.containsValue = function (v) {
38
		var e = this.getIterator();
40
		var e = this.getIterator();
39
		while (e.get()) {
41
		while (e.get()) {
40
			if (e.element.value == v) {
42
			if (e.element.value == v) {
41
				return true;
43
				return true;
42
			}
44
			}
43
		}
45
		}
44
		return false;
46
		return false;
45
	};
47
	};
46
	this.entry = function (k) {
48
	this.entry = function (k) {
47
		return items[k];
49
		return items[k];
48
	};
50
	};
49
	this.forEach = function (fn, scope) {
51
	this.forEach = function (fn, scope) {
50
		var a = [];
52
		var a = [];
51
		for (var p in items) {
53
		for (var p in items) {
52
			if (!testObject[p]) {
54
			if (!testObject[p]) {
53
				a.push(items[p]);
55
				a.push(items[p]);
54
			}
56
			}
55
		}
57
		}
56
		var s = scope || dj_global;
58
		var s = scope || dj_global;
57
		if (Array.forEach) {
59
		if (Array.forEach) {
58
			Array.forEach(a, fn, s);
60
			Array.forEach(a, fn, s);
59
		} else {
61
		} else {
60
			for (var i = 0; i < a.length; i++) {
62
			for (var i = 0; i < a.length; i++) {
61
				fn.call(s, a[i], i, a);
63
				fn.call(s, a[i], i, a);
62
			}
64
			}
63
		}
65
		}
64
	};
66
	};
65
	this.getKeyList = function () {
67
	this.getKeyList = function () {
66
		return (this.getIterator()).map(function (entry) {
68
		return (this.getIterator()).map(function (entry) {
67
			return entry.key;
69
			return entry.key;
68
		});
70
		});
69
	};
71
	};
70
	this.getValueList = function () {
72
	this.getValueList = function () {
71
		return (this.getIterator()).map(function (entry) {
73
		return (this.getIterator()).map(function (entry) {
72
			return entry.value;
74
			return entry.value;
73
		});
75
		});
74
	};
76
	};
75
	this.item = function (k) {
77
	this.item = function (k) {
76
		if (k in items) {
78
		if (k in items) {
77
			return items[k].valueOf();
79
			return items[k].valueOf();
78
		}
80
		}
79
		return undefined;
81
		return undefined;
80
	};
82
	};
81
	this.getIterator = function () {
83
	this.getIterator = function () {
82
		return new dojo.collections.DictionaryIterator(items);
84
		return new dojo.collections.DictionaryIterator(items);
83
	};
85
	};
84
	this.remove = function (k) {
86
	this.remove = function (k) {
85
		if (k in items && !testObject[k]) {
87
		if (k in items && !testObject[k]) {
86
			delete items[k];
88
			delete items[k];
87
			this.count--;
89
			this.count--;
88
			return true;
90
			return true;
89
		}
91
		}
90
		return false;
92
		return false;
91
	};
93
	};
92
	if (dictionary) {
94
	if (dictionary) {
93
		var e = dictionary.getIterator();
95
		var e = dictionary.getIterator();
94
		while (e.get()) {
96
		while (e.get()) {
95
			this.add(e.element.key, e.element.value);
97
			this.add(e.element.key, e.element.value);
96
		}
98
		}
97
	}
99
	}
98
};
100
};
99
 
101