comparison java/src/java/util/Map.d @ 10:eb8ff453285d

Added java.util collection classes.
author Frank Benoit <benoit@tionex.de>
date Fri, 13 Mar 2009 16:57:07 +0100
parents
children 9b96950f2c3c
comparison
equal deleted inserted replaced
9:950d84783eac 10:eb8ff453285d
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 int opEquals(Object o);
10 Object getKey();
11 Object getValue();
12 hash_t toHash();
13 Object setValue(Object value);
14 }
15 public void clear();
16 public bool containsKey(Object key);
17 public bool containsKey(String key);
18 public bool containsValue(Object value);
19 public Set entrySet();
20 public int opEquals(Object o);
21 public Object get(Object key);
22 public Object get(String key);
23 public hash_t toHash();
24 public bool isEmpty();
25 public Set keySet();
26 public Object put(Object key, Object value);
27 public Object put(String key, Object value);
28 public Object put(Object key, String value);
29 public Object put(String key, String value);
30 public void putAll(Map t);
31 public Object remove(Object key);
32 public Object remove(String key);
33 public int size();
34 public Collection values();
35
36 // only for D
37 public int opApply (int delegate(ref Object value) dg);
38 public int opApply (int delegate(ref Object key, ref Object value) dg);
39 }
40 class MapEntry : Map.Entry {
41 Map map;
42 Object key;
43 this( Map map, Object key){
44 this.map = map;
45 this.key = key;
46 }
47 public override int opEquals(Object o){
48 if( auto other = cast(MapEntry)o){
49
50 if(( getKey() is null ? other.getKey() is null : getKey() == other.getKey() ) &&
51 ( getValue() is null ? other.getValue() is null : getValue() == other.getValue() )){
52 return true;
53 }
54 return false;
55 }
56 return false;
57 }
58 public Object getKey(){
59 return key;
60 }
61 public Object getValue(){
62 return map.get(key);
63 }
64 public override hash_t toHash(){
65 return ( getKey() is null ? 0 : getKey().toHash() ) ^
66 ( getValue() is null ? 0 : getValue().toHash() );
67 }
68 public Object setValue(Object value){
69 return map.put( key, value );
70 }
71
72 }
73