| 1 |
define(["dojo/_base/kernel", "dojo/_base/array", "./_base"], function(dojo, darray, dxc){ |
| 2 |
|
| 3 |
dxc.Dictionary=function( dictionary){ |
| 4 |
|
| 5 |
|
| 6 |
var items={}; |
| 7 |
this.count=0; |
| 8 |
|
| 9 |
|
| 10 |
var testObject={}; |
| 11 |
|
| 12 |
this.add=function( k, v){ |
| 13 |
|
| 14 |
|
| 15 |
var b=(k in items); |
| 16 |
items[k]=new dxc.DictionaryEntry(k,v); |
| 17 |
if(!b){ |
| 18 |
this.count++; |
| 19 |
} |
| 20 |
}; |
| 21 |
this.clear=function(){ |
| 22 |
|
| 23 |
|
| 24 |
items={}; |
| 25 |
this.count=0; |
| 26 |
}; |
| 27 |
this.clone=function(){ |
| 28 |
|
| 29 |
|
| 30 |
return new dxc.Dictionary(this); |
| 31 |
}; |
| 32 |
this.contains=this.containsKey=function( k){ |
| 33 |
|
| 34 |
|
| 35 |
if(testObject[k]){ |
| 36 |
return false; |
| 37 |
} |
| 38 |
return (items[k]!=null); |
| 39 |
}; |
| 40 |
this.containsValue=function( v){ |
| 41 |
|
| 42 |
|
| 43 |
var e=this.getIterator(); |
| 44 |
while(e.get()){ |
| 45 |
if(e.element.value==v){ |
| 46 |
return true; |
| 47 |
} |
| 48 |
} |
| 49 |
return false; |
| 50 |
}; |
| 51 |
this.entry=function( k){ |
| 52 |
|
| 53 |
|
| 54 |
return items[k]; |
| 55 |
}; |
| 56 |
this.forEach=function( fn, scope){ |
| 57 |
|
| 58 |
|
| 59 |
var a=[]; |
| 60 |
for(var p in items) { |
| 61 |
if(!testObject[p]){ |
| 62 |
a.push(items[p]); |
| 63 |
} |
| 64 |
} |
| 65 |
dojo.forEach(a, fn, scope); |
| 66 |
}; |
| 67 |
this.getKeyList=function(){ |
| 68 |
|
| 69 |
|
| 70 |
return (this.getIterator()).map(function(entry){ |
| 71 |
return entry.key; |
| 72 |
}); |
| 73 |
}; |
| 74 |
this.getValueList=function(){ |
| 75 |
|
| 76 |
|
| 77 |
return (this.getIterator()).map(function(entry){ |
| 78 |
return entry.value; |
| 79 |
}); |
| 80 |
}; |
| 81 |
this.item=function( k){ |
| 82 |
|
| 83 |
|
| 84 |
if(k in items){ |
| 85 |
return items[k].valueOf(); |
| 86 |
} |
| 87 |
return undefined; |
| 88 |
}; |
| 89 |
this.getIterator=function(){ |
| 90 |
|
| 91 |
|
| 92 |
return new dxc.DictionaryIterator(items); |
| 93 |
}; |
| 94 |
this.remove=function( k){ |
| 95 |
|
| 96 |
|
| 97 |
if(k in items && !testObject[k]){ |
| 98 |
delete items[k]; |
| 99 |
this.count--; |
| 100 |
return true; |
| 101 |
} |
| 102 |
return false; |
| 103 |
}; |
| 104 |
|
| 105 |
if (dictionary){ |
| 106 |
var e=dictionary.getIterator(); |
| 107 |
while(e.get()) { |
| 108 |
this.add(e.element.key, e.element.value); |
| 109 |
} |
| 110 |
} |
| 111 |
}; |
| 112 |
return dxc.Dictionary; |
| 113 |
}); |