### Question:
LRUCache { public List<K> getKeysSortedByValue( final Comparator<V> comparator ) { synchronized ( _map ) { @SuppressWarnings( "unchecked" ) final Entry<K, ManagedItem<V>>[] a = _map.entrySet().toArray( new Map.Entry[_map.size()] ); final Comparator<Entry<K, ManagedItem<V>>> c = new Comparator<Entry<K, ManagedItem<V>>>() { @Override public int compare( final Entry<K, ManagedItem<V>> o1, final Entry<K, ManagedItem<V>> o2 ) { return comparator.compare( o1.getValue()._value, o2.getValue()._value ); } }; Arrays.sort(a, c); return new LRUCache.ArrayList<K, V>( a ); } } LRUCache( final int size );  LRUCache( final int size, final long ttlInMillis ); void clear(); V put( final K key, final V value ); V putIfDifferent( final K key, final V value ); V remove( final K key ); V get( final K key ); boolean containsKey( final K key ); List<K> getKeys(); List<K> getKeysSortedByValue( final Comparator<V> comparator );  }### Answer:
@Test public void testGetKeysSortedByValue() { final LRUCache<String,Integer> cut = new LRUCache<String, Integer>( 3 ); final String f = "foo"; final String br = "bar"; cut.put(f, 1); cut.put(br, 2); final Comparator<Integer> c = new Comparator<Integer>() { @Override public int compare( final Integer o1, final Integer o2 ) { return o1.compareTo( o2 ); } }; Assert.assertTrue( Arrays.equals( new String[]{ f, br }, cut.getKeysSortedByValue( c ).toArray() ), "invalid order of items, the keys are not order by their values" ); cut.put(f, 3); Assert.assertTrue( Arrays.equals( new String[]{ br, f }, cut.getKeysSortedByValue( c ).toArray() ), "invalid order of items, the keys are not order by their values" ); }