MapWritable extends AbstractMapWritable implements Map<Writable, Writable> { public MapWritable() { super(); this.instance = new HashMap<Writable, Writable>(); } MapWritable();  MapWritable(MapWritable other); @Override void clear(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Map.Entry<Writable, Writable>> entrySet(); @Override boolean equals(Object obj); @Override Writable get(Object key); @Override int hashCode(); @Override boolean isEmpty(); @Override Set<Writable> keySet(); @Override Writable put(Writable key, Writable value); @Override void putAll(Map<? extends Writable, ? extends Writable> t); @Override Writable remove(Object key); @Override int size(); @Override Collection<Writable> values(); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override String toString();  }
@SuppressWarnings("unchecked") @Test public void testMapWritable() { Text[] keys = { new Text("key1"), new Text("key2"), new Text("Key3"), }; BytesWritable[] values = { new BytesWritable("value1".getBytes()), new BytesWritable("value2".getBytes()), new BytesWritable("value3".getBytes()) }; MapWritable inMap = new MapWritable(); for (int i = 0; i < keys.length; i++) { inMap.put(keys[i], values[i]); } MapWritable outMap = new MapWritable(inMap); assertEquals(inMap.size(), outMap.size()); for (Map.Entry<Writable, Writable> e: inMap.entrySet()) { assertTrue(outMap.containsKey(e.getKey())); assertEquals(0, ((WritableComparable) outMap.get(e.getKey())).compareTo( e.getValue())); } Text[] maps = { new Text("map1"), new Text("map2") }; MapWritable mapOfMaps = new MapWritable(); mapOfMaps.put(maps[0], inMap); mapOfMaps.put(maps[1], outMap); MapWritable copyOfMapOfMaps = new MapWritable(mapOfMaps); for (int i = 0; i < maps.length; i++) { assertTrue(copyOfMapOfMaps.containsKey(maps[i])); MapWritable a = (MapWritable) mapOfMaps.get(maps[i]); MapWritable b = (MapWritable) copyOfMapOfMaps.get(maps[i]); assertEquals(a.size(), b.size()); for (Writable key: a.keySet()) { assertTrue(b.containsKey(key)); WritableComparable aValue = (WritableComparable) a.get(key); WritableComparable bValue = (WritableComparable) b.get(key); assertEquals(0, aValue.compareTo(bValue)); } } }