SortedMapWritable extends AbstractMapWritable implements SortedMap<K, Writable> { public SortedMapWritable() { super(); this.instance = new TreeMap<K, Writable>(); } SortedMapWritable();  SortedMapWritable(SortedMapWritable<K> other); @Override Comparator<? super K> comparator(); @Override K firstKey(); @Override SortedMap<K, Writable> headMap(K toKey); @Override K lastKey(); @Override SortedMap<K, Writable> subMap(K fromKey, K toKey); @Override SortedMap<K, Writable> tailMap(K fromKey); @Override void clear(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override Set<Map.Entry<K, Writable>> entrySet(); @Override Writable get(Object key); @Override boolean isEmpty(); @Override Set<K> keySet(); @Override Writable put(K key, Writable value); @Override void putAll(Map<? extends K, ? extends Writable> t); @Override Writable remove(Object key); @Override int size(); @Override Collection<Writable> values(); @SuppressWarnings("unchecked") @Override void readFields(DataInput in); @Override void write(DataOutput out); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test @SuppressWarnings("unchecked") public void testSortedMapWritable() { 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()) }; SortedMapWritable<Text> inMap = new SortedMapWritable<Text>(); for (int i = 0; i < keys.length; i++) { inMap.put(keys[i], values[i]); } assertEquals(0, inMap.firstKey().compareTo(keys[0])); assertEquals(0, inMap.lastKey().compareTo(keys[2])); SortedMapWritable<Text> outMap = new SortedMapWritable<Text>(inMap); assertEquals(inMap.size(), outMap.size()); for (Map.Entry<Text, Writable> e: inMap.entrySet()) { assertTrue(outMap.containsKey(e.getKey())); WritableComparable<WritableComparable<?>> aValue = (WritableComparable<WritableComparable<?>>) outMap.get(e.getKey()); WritableComparable<WritableComparable<?>> bValue = (WritableComparable<WritableComparable<?>>) e.getValue(); assertEquals(0, aValue.compareTo(bValue)); } Text[] maps = { new Text("map1"), new Text("map2") }; SortedMapWritable<Text> mapOfMaps = new SortedMapWritable<Text>(); mapOfMaps.put(maps[0], inMap); mapOfMaps.put(maps[1], outMap); SortedMapWritable<Text> copyOfMapOfMaps = new SortedMapWritable<Text>(mapOfMaps); for (int i = 0; i < maps.length; i++) { assertTrue(copyOfMapOfMaps.containsKey(maps[i])); SortedMapWritable<Text> a = (SortedMapWritable<Text>) mapOfMaps.get(maps[i]); SortedMapWritable<Text> b = (SortedMapWritable<Text>) copyOfMapOfMaps.get(maps[i]); assertEquals(a.size(), b.size()); for (Writable key: a.keySet()) { assertTrue(b.containsKey(key)); WritableComparable<WritableComparable<?>> aValue = (WritableComparable<WritableComparable<?>>) a.get(key); WritableComparable<WritableComparable<?>> bValue = (WritableComparable<WritableComparable<?>>) b.get(key); assertEquals(0, aValue.compareTo(bValue)); } } }