1 module java.util.Map;
2 
3 import java.lang.all;
4 import java.util.Set;
5 import java.util.Collection;
6 
7 interface Map {
8     interface Entry {
9         equals_t   opEquals(Object o);
10         Object     getKey();
11         Object     getValue();
12         version(Tango){
13             public hash_t   toHash();
14         } else { // Phobos
15             mixin(`@safe nothrow public hash_t   toHash();`);
16         }
17         Object     setValue(Object value);
18     }
19     public void clear();
20     public bool containsKey(Object key);
21     public bool containsKey(String key);
22     public bool containsValue(Object value);
23     public Set  entrySet();
24     public equals_t opEquals(Object o);
25     public Object get(Object key);
26     public Object get(String key);
27     version(Tango){
28         public hash_t   toHash();
29     } else { // Phobos
30         mixin(`@safe nothrow public hash_t   toHash();`);
31     }
32     public bool isEmpty();
33     public Set    keySet();
34     public Object put(Object key, Object value);
35     public Object put(String key, Object value);
36     public Object put(Object key, String value);
37     public Object put(String key, String value);
38     public void   putAll(Map t);
39     public Object remove(Object key);
40     public Object remove(String key);
41     public int    size();
42     public Collection values();
43 
44     // only for D
45     public int opApply (int delegate(ref Object value) dg);
46     public int opApply (int delegate(ref Object key, ref Object value) dg);
47 }
48 class MapEntry : Map.Entry {
49     Map map;
50     Object key;
51     this( Map map, Object key){
52         this.map = map;
53         this.key = key;
54     }
55     public override equals_t opEquals(Object o){
56         if( auto other = cast(MapEntry)o){
57 
58             if(( getKey() is null ? other.getKey() is null : getKey() == other.getKey() )  &&
59                ( getValue() is null ? other.getValue() is null : getValue() == other.getValue() )){
60                 return true;
61             }
62             return false;
63         }
64         return false;
65     }
66     public Object getKey(){
67         return key;
68     }
69     public Object getValue(){
70         return map.get(key);
71     }
72     public override hash_t toHash(){
73         return ( key   is null ? 0 : key.toHash()   ) ^
74                ( 0 );
75     }
76     public Object     setValue(Object value){
77         return map.put( key, value );
78     }
79 
80 }
81