1 if(!dojo._hasResource["dojox.collections.SortedList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.collections.SortedList"] = true;
3 dojo.provide("dojox.collections.SortedList");
4 dojo.require("dojox.collections._base");
6 dojox.collections.SortedList=function(/* object? */ dictionary){
8 // creates a collection that acts like a dictionary but is also internally sorted.
9 // Note that the act of adding any elements forces an internal resort, making this object potentially slow.
13 var sorter=function(a,b){
14 if (a.key > b.key) return 1;
15 if (a.key < b.key) return -1;
20 var e=_this.getIterator();
29 this.add=function(/* string */ k,/* object */v){
31 // add the passed value to the dictionary at location k
33 items[k]=new dojox.collections.DictionaryEntry(k,v);
34 this.count=q.push(items[k]);
38 this.clear=function(){
40 // clear the internal collections
45 this.clone=function(){
47 // create a clone of this sorted list
48 return new dojox.collections.SortedList(this); // dojox.collections.SortedList
50 this.contains=this.containsKey=function(/* string */ k){
52 // Check to see if the list has a location k
56 return (items[k]!=null); // bool
58 this.containsValue=function(/* object */ o){
60 // Check to see if this list contains the passed object
61 var e=this.getIterator();
70 this.copyTo=function(/* array */ arr, /* int */ i){
72 // copy the contents of the list into array arr at index i
73 var e=this.getIterator();
76 arr.splice(idx,0,e.get());
80 this.entry=function(/* string */ k){
82 // return the object at location k
83 return items[k]; // dojox.collections.DictionaryEntry
85 this.forEach=function(/* function */ fn, /* object? */ scope){
87 // functional iterator, following the mozilla spec.
88 dojo.forEach(q, fn, scope);
90 this.getByIndex=function(/* int */ i){
92 // return the item at index i
93 return q[i].valueOf(); // object
95 this.getIterator=function(){
97 // get an iterator for this object
98 return new dojox.collections.DictionaryIterator(items); // dojox.collections.DictionaryIterator
100 this.getKey=function(/* int */ i){
102 // return the key of the item at index i
105 this.getKeyList=function(){
107 // return an array of the keys set in this list
109 var e=this.getIterator();
111 arr.push(e.get().key);
115 this.getValueList=function(){
117 // return an array of values in this list
119 var e=this.getIterator();
121 arr.push(e.get().value);
125 this.indexOfKey=function(/* string */ k){
127 // return the index of the passed key.
128 for (var i=0; i<q.length; i++){
135 this.indexOfValue=function(/* object */ o){
137 // return the first index of object o
138 for (var i=0; i<q.length; i++){
145 this.item=function(/* string */ k){
147 // return the value of the object at location k.
148 if(k in items && !testObject[k]){
149 return items[k].valueOf(); // object
151 return undefined; // object
153 this.remove=function(/* string */k){
155 // remove the item at location k and rebuild the internal collections.
160 this.removeAt=function(/* int */ i){
162 // remove the item at index i, and rebuild the internal collections.
163 delete items[q[i].key];
167 this.replace=function(/* string */ k, /* object */ v){
169 // Replace an existing item if it's there, and add a new one if not.
171 // we're adding a new object, return false
173 return false; // bool
175 // we're replacing an object, return true
176 items[k]=new dojox.collections.DictionaryEntry(k,v);
181 this.setByIndex=function(/* int */ i, /* object */ o){
183 // set an item by index
184 items[q[i].key].value=o;
189 var e=dictionary.getIterator();
192 q[q.length]=items[item.key]=new dojox.collections.DictionaryEntry(item.key,item.value);