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.Dictionary");
12
dojo.require("dojo.collections.Collections");
13
dojo.collections.Dictionary = function (dictionary) {
14
	var items = {};
15
	this.count = 0;
16
	var testObject = {};
17
	this.add = function (k, v) {
18
		var b = (k in items);
19
		items[k] = new dojo.collections.DictionaryEntry(k, v);
20
		if (!b) {
21
			this.count++;
22
		}
23
	};
24
	this.clear = function () {
25
		items = {};
26
		this.count = 0;
27
	};
28
	this.clone = function () {
29
		return new dojo.collections.Dictionary(this);
30
	};
31
	this.contains = this.containsKey = function (k) {
32
		if (testObject[k]) {
33
			return false;
34
		}
35
		return (items[k] != null);
36
	};
37
	this.containsValue = function (v) {
38
		var e = this.getIterator();
39
		while (e.get()) {
40
			if (e.element.value == v) {
41
				return true;
42
			}
43
		}
44
		return false;
45
	};
46
	this.entry = function (k) {
47
		return items[k];
48
	};
49
	this.forEach = function (fn, scope) {
50
		var a = [];
51
		for (var p in items) {
52
			if (!testObject[p]) {
53
				a.push(items[p]);
54
			}
55
		}
56
		var s = scope || dj_global;
57
		if (Array.forEach) {
58
			Array.forEach(a, fn, s);
59
		} else {
60
			for (var i = 0; i < a.length; i++) {
61
				fn.call(s, a[i], i, a);
62
			}
63
		}
64
	};
65
	this.getKeyList = function () {
66
		return (this.getIterator()).map(function (entry) {
67
			return entry.key;
68
		});
69
	};
70
	this.getValueList = function () {
71
		return (this.getIterator()).map(function (entry) {
72
			return entry.value;
73
		});
74
	};
75
	this.item = function (k) {
76
		if (k in items) {
77
			return items[k].valueOf();
78
		}
79
		return undefined;
80
	};
81
	this.getIterator = function () {
82
		return new dojo.collections.DictionaryIterator(items);
83
	};
84
	this.remove = function (k) {
85
		if (k in items && !testObject[k]) {
86
			delete items[k];
87
			this.count--;
88
			return true;
89
		}
90
		return false;
91
	};
92
	if (dictionary) {
93
		var e = dictionary.getIterator();
94
		while (e.get()) {
95
			this.add(e.element.key, e.element.value);
96
		}
97
	}
98
};
99