Methods Summary |
---|
public void | clear()
first = null;
last = null;
|
public java.lang.Object | get(java.lang.Object key)
CacheNode node = (CacheNode)nodes.get(key);
if(node != null)
{
moveToHead(node);
return node.value;
}
else
{
return null;
}
|
private void | moveToHead(org.apache.tomcat.util.collections.LRUCache$CacheNode node)
if(node == first)
return;
if(node.prev != null)
node.prev.next = node.next;
if(node.next != null)
node.next.prev = node.prev;
if(last == node)
last = node.prev;
if(first != null)
{
node.next = first;
first.prev = node;
}
first = node;
node.prev = null;
if(last == null)
last = first;
|
public void | put(java.lang.Object key, java.lang.Object value)
CacheNode node = (CacheNode)nodes.get(key);
if(node == null)
{
if(currentSize >= cacheSize)
{
if(last != null)
nodes.remove(last.key);
removeLast();
}
else
{
currentSize++;
}
node = new CacheNode();
}
node.value = value;
node.key = key;
moveToHead(node);
nodes.put(key, node);
|
public java.lang.Object | remove(java.lang.Object key)
CacheNode node = (CacheNode)nodes.get(key);
if (node != null) {
if (node.prev != null) {
node.prev.next = node.next;
}
if (node.next != null) {
node.next.prev = node.prev;
}
if (last == node)
last = node.prev;
if (first == node)
first = node.next;
}
return node;
|
private void | removeLast()
if(last != null)
{
if(last.prev != null)
last.prev.next = null;
else
first = null;
last = last.prev;
}
|