ObjectHashTable.as

Go to the documentation of this file.
00001 import gugga.utils.HashUtil;
00002 import gugga.collections.IHashTable;
00003 import gugga.collections.IIterator;
00004 import gugga.collections.ArrayListIterator;
00005 import gugga.collections.ArrayList;
00006 
00018 class gugga.collections.ObjectHashTable extends Object implements IHashTable
00019 {
00026         public function add(aKey, aObject : Object) : Void
00027         {
00028                 var hash : String = HashUtil.hash(aKey);
00029                 this[hash] = aObject;
00030         }
00031         
00038         public function remove(aKey) : Object
00039         {
00040                 var hash : String = HashUtil.hash(aKey);
00041                 var result : Object = this[hash]; 
00042                 delete this[hash];
00043                 return result;
00044         }
00045         
00051         public function containsValue(aObject:Object) : Boolean
00052         {               
00053                 var result : Boolean = false;
00054                 
00055                 for(var hash : String in this)
00056                 {
00057                         if(this[hash] == aObject)
00058                         {
00059                                 result = true;
00060                         }
00061                 }
00062 
00063                 return result;
00064         }
00065         
00071         public function containsKey(aKey):Boolean
00072         {
00073                 var hash : String = HashUtil.hash(aKey);
00074                 
00075                 var result:Boolean = false;
00076                 if(this[hash] != undefined && this[hash] != null)
00077                 {
00078                         result = true;
00079                 }
00080                 
00081                 return result;
00082         }
00083         
00090         public function getKeyByValue(aValue:Object):String
00091         {
00092                 var result:String = null;
00093                 for(var hash:String in this) 
00094                 {
00095                         if(this[hash] == aValue)
00096                         {
00097                                 result = hash;
00098                                 break;
00099                         }
00100                 }
00101                 return result;
00102         }
00103         
00109         public function getValue (aKey) : Object
00110         {
00111                 var hash : String = HashUtil.hash(aKey);
00112                 return this[hash];
00113         }
00114         
00118         public function get IsEmpty():Boolean
00119         {
00120                 for(var key:String in this) 
00121                 {
00122                         return false;
00123                 }
00124                 return true;
00125         }
00126         
00130         public function get count():Number
00131         {
00132                 var itemsCount:Number = 0;
00133                 for(var key:String in this)
00134                 {
00135                         itemsCount++;
00136                 }
00137                 return itemsCount;
00138         }
00139         
00143         public function clone() : IHashTable
00144         {
00145                 var result : ObjectHashTable = new ObjectHashTable();
00146                 for (var key : String in this)
00147                 {
00148                         result.addWithStringKey(key, this[key]);
00149                 }
00150                 
00151                 return result;
00152         }
00153         
00160         private function addWithStringKey (aKey : String, aObject : Object) : Void
00161         {
00162                 this[aKey] = aObject;
00163         }
00164         
00168         private function getAllElements() : Array
00169         {
00170                 var result:Array = new Array();
00171                 for (var i : String in this) 
00172                 {
00173                         result.push(this[i]);
00174                 }
00175                 
00176                 return result;
00177         }
00178         
00182         public function getIterator () : IIterator
00183         {
00184                 var list : ArrayList = new ArrayList();
00185                 list.addAll(this.getAllElements());
00186                 return new ArrayListIterator(list);     
00187         }
00188 }

Generated on Fri May 11 17:12:43 2007 for GuggaFramework by  doxygen 1.5.2