@Test public void lruCacheTest() { LRUCache<String, String> lruCache = createLRUCache(2); lruCache.put(KEY1, VALUE1); Assert.assertEquals(VALUE1, lruCache.get(KEY1)); Assert.assertFalse(lruCache.containsKey(KEY2)); Assert.assertFalse(lruCache.containsKey(KEY3)); lruCache.put(KEY2, VALUE2); Assert.assertEquals(VALUE1, lruCache.get(KEY1)); Assert.assertEquals(VALUE2, lruCache.get(KEY2)); Assert.assertFalse(lruCache.containsKey(KEY3)); lruCache.put(KEY3, VALUE3); Assert.assertFalse(lruCache.containsKey(KEY1)); Assert.assertEquals(VALUE2, lruCache.get(KEY2)); Assert.assertEquals(VALUE3, lruCache.get(KEY3)); lruCache.put(KEY1, VALUE1); Assert.assertEquals(VALUE1, lruCache.get(KEY1)); Assert.assertFalse(lruCache.containsKey(KEY2)); Assert.assertEquals(VALUE3, lruCache.get(KEY3)); }
public LRUCache(int capacity) { super(calculateInitialCapacity(capacity), LOAD_FACTOR, true); this.capacity = capacity; }
LRUCache extends LinkedHashMap<K, V> { public LRUCache(int capacity) { super(calculateInitialCapacity(capacity), LOAD_FACTOR, true); this.capacity = capacity; } }
LRUCache extends LinkedHashMap<K, V> { public LRUCache(int capacity) { super(calculateInitialCapacity(capacity), LOAD_FACTOR, true); this.capacity = capacity; } LRUCache(int capacity); }
LRUCache extends LinkedHashMap<K, V> { public LRUCache(int capacity) { super(calculateInitialCapacity(capacity), LOAD_FACTOR, true); this.capacity = capacity; } LRUCache(int capacity);  }
LRUCache extends LinkedHashMap<K, V> { public LRUCache(int capacity) { super(calculateInitialCapacity(capacity), LOAD_FACTOR, true); this.capacity = capacity; } LRUCache(int capacity);   }