Subversion Repositories Applications.papyrus

Rev

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