|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--jrun.servlet.session.LRUTable
LRUTable
A table that maintains the Least Recently Used items. Consumers can add an object to be maintained (such as a unique key) and get a LRU key back. Whenever the owning object is used the table can be 'touched' using the LRU key. The least recently used object can always be returned by calling getLRU().
There is no limit to the number of items maintained in the table; the table will grow as needed.
This table is considered thread-safe
| Constructor Summary | |
LRUTable()
Construct a new LRUTable using the default initial size of the table (1000) |
|
LRUTable(int initialSize)
Construct a new LRUTable using the given initial size |
|
| Method Summary | |
int |
add(java.lang.Object key)
Add a new object to the LRU cache. |
protected int |
getElementIndex(int id)
Given the list id get the element in the vector where this id can be found |
java.lang.Object |
getKey(int id)
Returns the object for the given LRU object id |
int |
getLRU()
Returns the object id of the least recently used object |
protected int |
getRelativeIndex(int id)
Given the list id get the index into the vector object where the id is located |
protected void |
makeRoomForAdd()
Make sure we have a cache available for adding a new object |
void |
remove(int id)
Removes the given id from the table |
void |
removeAll()
Removes all elements from the table |
protected void |
setKey(int id,
java.lang.Object key)
Sets the key |
protected void |
setLinks(int id,
int prev,
int next)
Set the previous and next pointers for the given list id |
int |
size()
Returns the number of items in the table |
java.lang.String |
toString()
|
void |
touch(int id)
Touch the given id. |
protected void |
unplug(int elementIndex,
int relativeIndex,
int[] l)
Unplug the element from the linked list |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public LRUTable()
public LRUTable(int initialSize)
initialSize - The initial size of the table| Method Detail |
public int add(java.lang.Object key)
key - The object or object keypublic void touch(int id)
id - The LRU object idpublic int size()
public int getLRU()
public java.lang.Object getKey(int id)
id - The LRU object idpublic void removeAll()
public void remove(int id)
id - The LRU object idprotected void makeRoomForAdd()
protected void setLinks(int id,
int prev,
int next)
protected void setKey(int id,
java.lang.Object key)
protected int getElementIndex(int id)
protected int getRelativeIndex(int id)
protected void unplug(int elementIndex,
int relativeIndex,
int[] l)
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||