diff base/src/java/util/Map.d @ 27:1bf55a6eb092

Renamed java tree to base
author Frank Benoit <benoit@tionex.de>
date Sat, 21 Mar 2009 11:33:57 +0100
parents java/src/java/util/Map.d@9b96950f2c3c
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/src/java/util/Map.d	Sat Mar 21 11:33:57 2009 +0100
@@ -0,0 +1,73 @@
+module java.util.Map;
+
+import java.lang.all;
+import java.util.Set;
+import java.util.Collection;
+
+interface Map {
+    interface Entry {
+        int   opEquals(Object o);
+        Object     getKey();
+        Object     getValue();
+        hash_t     toHash();
+        Object     setValue(Object value);
+    }
+    public void clear();
+    public bool containsKey(Object key);
+    public bool containsKey(String key);
+    public bool containsValue(Object value);
+    public Set  entrySet();
+    public equals_t opEquals(Object o);
+    public Object get(Object key);
+    public Object get(String key);
+    public hash_t toHash();
+    public bool isEmpty();
+    public Set    keySet();
+    public Object put(Object key, Object value);
+    public Object put(String key, Object value);
+    public Object put(Object key, String value);
+    public Object put(String key, String value);
+    public void   putAll(Map t);
+    public Object remove(Object key);
+    public Object remove(String key);
+    public int    size();
+    public Collection values();
+
+    // only for D
+    public int opApply (int delegate(ref Object value) dg);
+    public int opApply (int delegate(ref Object key, ref Object value) dg);
+}
+class MapEntry : Map.Entry {
+    Map map;
+    Object key;
+    this( Map map, Object key){
+        this.map = map;
+        this.key = key;
+    }
+    public override equals_t opEquals(Object o){
+        if( auto other = cast(MapEntry)o){
+
+            if(( getKey() is null ? other.getKey() is null : getKey() == other.getKey() )  &&
+               ( getValue() is null ? other.getValue() is null : getValue() == other.getValue() )){
+                return true;
+            }
+            return false;
+        }
+        return false;
+    }
+    public Object getKey(){
+        return key;
+    }
+    public Object getValue(){
+        return map.get(key);
+    }
+    public override hash_t toHash(){
+        return ( getKey()   is null ? 0 : getKey().toHash()   ) ^
+               ( getValue() is null ? 0 : getValue().toHash() );
+    }
+    public Object     setValue(Object value){
+        return map.put( key, value );
+    }
+
+}
+