### Question:
Int2IntOpenHashMapWritable extends Int2IntOpenHashMap implements Writable { public Int2IntMap.Entry[] getEntriesSortedByValue() { if (this.size() == 0) return null; Int2IntMap.Entry[] entries = new Int2IntMap.Entry[this.size()]; entries = this.int2IntEntrySet().toArray(entries); Arrays.sort(entries, new Comparator<Int2IntMap.Entry>() { public int compare(Int2IntMap.Entry e1, Int2IntMap.Entry e2) { if (e1.getIntValue() > e2.getIntValue()) { return -1; } else if (e1.getIntValue() < e2.getIntValue()) { return 1; } if (e1.getIntKey() == e2.getIntKey()) return 0; return e1.getIntKey() > e2.getIntKey() ? 1 : -1; } }); return entries; } Int2IntOpenHashMapWritable(); @Override void readFields(DataInput in); void decode(); boolean hasBeenDecoded(); @Override void write(DataOutput out); byte[] serialize(); static Int2IntOpenHashMapWritable create(DataInput in); static Int2IntOpenHashMapWritable create(byte[] bytes); void plus(Int2IntOpenHashMapWritable m); long dot(Int2IntOpenHashMapWritable m); void increment(int key); void increment(int key, int n); static void setLazyDecodeFlag(boolean b); static boolean getLazyDecodeFlag(); int[] getKeys(); int[] getValues(); void lazyplus(Int2IntOpenHashMapWritable m); Int2IntMap.Entry[] getEntriesSortedByValue(); Int2IntMap.Entry[] getEntriesSortedByValue(int k);  }### Answer:
@Test public void testSortedEntries1() { Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable(); m.put(1, 5); m.put(2, 2); m.put(3, 3); m.put(4, 3); m.put(5, 1); Int2IntMap.Entry[] e = m.getEntriesSortedByValue(); assertEquals(5, e.length); assertEquals(1, e[0].getIntKey()); assertEquals(5, e[0].getIntValue()); assertEquals(3, e[1].getIntKey()); assertEquals(3, e[1].getIntValue()); assertEquals(4, e[2].getIntKey()); assertEquals(3, e[2].getIntValue()); assertEquals(2, e[3].getIntKey()); assertEquals(2, e[3].getIntValue()); assertEquals(5, e[4].getIntKey()); assertEquals(1, e[4].getIntValue()); }
@Test public void testSortedEntries2() { Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable(); m.put(1, 5); m.put(2, 2); m.put(3, 3); m.put(4, 3); m.put(5, 1); Int2IntMap.Entry[] e = m.getEntriesSortedByValue(2); assertEquals(2, e.length); assertEquals(1, e[0].getIntKey()); assertEquals(5, e[0].getIntValue()); assertEquals(3, e[1].getIntKey()); assertEquals(3, e[1].getIntValue()); }
@Test public void testSortedEntries3() { Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable(); m.put(1, 5); m.put(2, 2); Int2IntMap.Entry[] e = m.getEntriesSortedByValue(5); assertEquals(2, e.length); assertEquals(1, e[0].getIntKey()); assertEquals(5, e[0].getIntValue()); assertEquals(2, e[1].getIntKey()); assertEquals(2, e[1].getIntValue()); }
@Test public void testSortedEntries4() { Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable(); Int2IntMap.Entry[] e = m.getEntriesSortedByValue(); assertTrue(e == null); }