Merge branch 'master' of https://github.com/systemed/potlatch2
[potlatch2.git] / hxasm / Hash.as
1 package  hxasm{
2         import flash.utils.Dictionary;
3         
4         public class Hash {
5                 public function Hash() : void {
6                         this.h = new Dictionary();
7                 }
8                 public function set(key : String,value : *) : void {
9                         this.h["$" + key] = value;
10                 }
11                 public function get(key : String) : * {
12                         return this.h["$" + key];
13                 }
14                 public function exists(key : String) : Boolean {
15                         return this.h.hasOwnProperty("$" + key);
16                 }
17                 public function remove(key : String) : Boolean {
18                         key = "$" + key;
19                         if(!this.h.hasOwnProperty(key)) return false;
20                         delete(this.h[key]);
21                         return true;
22                 }
23                 public function keys() : * {
24                         return (function($this:Hash) : * {
25                                 var $r : *;
26                                 $r = new Array();
27                                 for(var $k : String in $this.h) $r.push($k.substr(1));
28                                 return $r;
29                         }(this)).iterator();
30                 }
31                 public function iterator() : * {
32                         return { ref : this.h, it : function($this:Hash) : * {
33                                 var $r : *;
34                                 $r = new Array();
35                                 for(var $k : String in $this.h) $r.push($k);
36                                 return $r;
37                         }(this).iterator(), hasNext : function() : * {
38                                 return this.it.hasNext();
39                         }, next : function() : * {
40                                 var i : * = this.it.next();
41                                 return this.ref[i];
42                         }}
43                 }
44                 public function toString() : String {
45                         var s : StringBuf = new StringBuf();
46                         s.add("{");
47                         var it : * = this.keys();
48                         { var $it : * = it;
49                         while( $it.hasNext() ) { var i : String = $it.next();
50                         {
51                                 s.add(i);
52                                 s.add(" => ");
53                                 s.add((this.get(i)).toString());
54                                 if(it.hasNext()) s.add(", ");
55                         }
56                         }}
57                         s.add("}");
58                         return s.toString();
59                 }
60                 protected var h : *;
61         }
62 }