# HG changeset patch # User Frank Benoit # Date 1233513673 -3600 # Node ID 6d35b9960800b00551b0c357c37112b13cda5fdf # Parent a785420fe9cab73534fc6c5f34d7606c32206a92 Crash in jface snippet 11, workaround tango HashMap cannot store null values. diff -r a785420fe9ca -r 6d35b9960800 dwtx/dwtxhelper/Collection.d --- a/dwtx/dwtxhelper/Collection.d Sat Nov 15 09:20:02 2008 +0100 +++ b/dwtx/dwtxhelper/Collection.d Sun Feb 01 19:41:13 2009 +0100 @@ -235,17 +235,21 @@ } class HashMap : Map { + //FIXME "NULL" is used to work around tango ticket 1468. + static Object NULL; // The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. alias tango.util.container.HashMap.HashMap!(Object,Object) MapType; private MapType map; public this(){ + if( NULL is null ) NULL = new Object(); map = new MapType(); } public this(int initialCapacity){ this(); } public this(int initialCapacity, float loadFactor){ + if( NULL is null ) NULL = new Object(); map = new MapType(loadFactor); } public this(Map m){ @@ -263,7 +267,8 @@ return containsKey(stringcast(key)); } public bool containsValue(Object value){ - return map.contains(value); + Object v = (value is null) ? NULL : value; + return map.contains(v); } public Set entrySet(){ HashSet res = new HashSet(); @@ -289,6 +294,7 @@ } public Object get(Object key){ if( auto v = key in map ){ + if( *v is NULL ) return null; return *v; } return null; @@ -310,11 +316,12 @@ return res; } public Object put(Object key, Object value){ + Object v = (value is null) ? NULL : value; Object res = null; if( auto vold = key in map ){ res = *vold; } - map[ key ] = value; + map[ key ] = v; return res; } public Object put(String key, Object value){ @@ -328,13 +335,15 @@ } public void putAll(Map t){ foreach( k, v; t ){ - map[k] = v; + Object vi = (v is null) ? NULL : v; + map[k] = vi; } } public Object remove(Object key){ if( auto v = key in map ){ Object res = *v; map.remove(key); + if( res is NULL ) return null; return res; } map.remove(key); @@ -773,7 +782,7 @@ return res; } public override int opEquals(Object o){ - if( auto other = cast(HashMap) o ){ + if( auto other = cast(TreeMap) o ){ if( other.size() !is size() ){ return false; }