1 if(!dojo._hasResource["dojox.collections.Dictionary"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.collections.Dictionary"] = true;
3 dojo.provide("dojox.collections.Dictionary");
4 dojo.require("dojox.collections._base");
6 dojox.collections.Dictionary=function(/* dojox.collections.Dictionary? */dictionary){
8 // Returns an object of type dojox.collections.Dictionary
12 // comparator for property addition and access.
15 this.add=function(/* string */k, /* object */v){
17 // Add a new item to the Dictionary.
19 items[k]=new dojox.collections.DictionaryEntry(k,v);
24 this.clear=function(){
26 // Clears the internal dictionary.
30 this.clone=function(){
32 // Returns a new instance of dojox.collections.Dictionary; note the the dictionary is a clone but items might not be.
33 return new dojox.collections.Dictionary(this); // dojox.collections.Dictionary
35 this.contains=this.containsKey=function(/* string */k){
37 // Check to see if the dictionary has an entry at key "k".
41 return (items[k]!=null); // bool
43 this.containsValue=function(/* object */v){
45 // Check to see if the dictionary has an entry with value "v".
46 var e=this.getIterator();
48 if(e.element.value==v){
54 this.entry=function(/* string */k){
56 // Accessor method; similar to dojox.collections.Dictionary.item but returns the actual Entry object.
57 return items[k]; // dojox.collections.DictionaryEntry
59 this.forEach=function(/* function */ fn, /* object? */ scope){
61 // functional iterator, following the mozilla spec.
62 var a=[]; // Create an indexing array
65 a.push(items[p]); // fill it up
68 dojo.forEach(a, fn, scope);
70 this.getKeyList=function(){
72 // Returns an array of the keys in the dictionary.
73 return (this.getIterator()).map(function(entry){
77 this.getValueList=function(){
79 // Returns an array of the values in the dictionary.
80 return (this.getIterator()).map(function(entry){
84 this.item=function(/* string */k){
88 return items[k].valueOf(); // object
90 return undefined; // object
92 this.getIterator=function(){
94 // Gets a dojox.collections.DictionaryIterator for iteration purposes.
95 return new dojox.collections.DictionaryIterator(items); // dojox.collections.DictionaryIterator
97 this.remove=function(/* string */k){
99 // Removes the item at k from the internal collection.
100 if(k in items && !testObject[k]){
105 return false; // bool
109 var e=dictionary.getIterator();
111 this.add(e.element.key, e.element.value);