simple.util.cache
Class CacheList

java.lang.Object
  extended by simple.util.cache.CacheList

public class CacheList
extends java.lang.Object

This is a LRU, Least Recently Used, list that will store a limited number of objects. When there is an attempt to store an object into this list when the list is full then the Least Recently Used objects are removed from the list, In fact this will remove twenty percent of the Least Recently Used objects, this will ensure that there is not a removal of an object for each insert into the list, this may or may not increase the performance.

Author:
Niall Gallagher

Constructor Summary
CacheList()
          This will create an list with a maximum allowed number of objects to be inserted into the list.
CacheList(int maxSize)
          This will create an list with a maximum allowed number of objects to be inserted into the list.
 
Method Summary
 int capacity()
          This is used to that the capacity of the list can be determined.
 void clear()
          This is a simple method that will purge all entrys from this list.
 boolean contains(java.lang.Object key)
          This method will search the list to see if there is an object stored in the list under that name.
 void insert(java.lang.Object key, java.lang.Object obj)
          This uses a doubly linked list to store the object within this list.
 int length()
          This will simply return the number of items in the list.
 java.lang.Object lookup(java.lang.Object key)
          This method will search to see if it can find the object stored under the key specified and return it.
 java.lang.Object remove(java.lang.Object key)
          This method will search the list to see if there is an object stored in the list under that name.
 void resize(int maxSize)
          This simply specifies the maximum size that this list can grow and then purges the Least Recently Used items in the list, that is items at the tail.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheList

public CacheList()
This will create an list with a maximum allowed number of objects to be inserted into the list. If there are further inserts after the list fills, then the least hit objects will be removed from the list, the lookup method is a hit.


CacheList

public CacheList(int maxSize)
This will create an list with a maximum allowed number of objects to be inserted into the list. If there are further inserts after the list fills, then the least hit objects will be removed from the list, the lookup method is a hit.

Parameters:
maxSize - the maximum allowed number of objects
Method Detail

insert

public void insert(java.lang.Object key,
                   java.lang.Object obj)
This uses a doubly linked list to store the object within this list. This uses the key specified to store the object in the CacheList. Should not use a duplicate key in the list.

Parameters:
key - a unique key, that is not used by any other object
obj - the object that is being stored in the list

contains

public boolean contains(java.lang.Object key)
This method will search the list to see if there is an object stored in the list under that name. If there is an object stored within the list using the key specified this returns true otherwise false.

Parameters:
key - the reference to the list object
Returns:
true only if the object is in the list

lookup

public java.lang.Object lookup(java.lang.Object key)
This method will search to see if it can find the object stored under the key specified and return it.

Parameters:
key - the reference to the stored object
Returns:
the object if it is stored otherwise null

remove

public java.lang.Object remove(java.lang.Object key)
This method will search the list to see if there is an object stored in the list under that name. If there is an object stored within the list using the key specified this removes that object.

Parameters:
key - the reference to the list object

resize

public void resize(int maxSize)
This simply specifies the maximum size that this list can grow and then purges the Least Recently Used items in the list, that is items at the tail.

Parameters:
maxSize - the max size allowed for the list

length

public int length()
This will simply return the number of items in the list. Because this is a Least Recently Used list this should never return a length greater that the maximum size.

Returns:
the number of items that are in this list.

capacity

public int capacity()
This is used to that the capacity of the list can be determined. The capacity indicates at what point entrys are pushed off the list. Only capacity entrys can fit into the list before the least recently used is removed.

Returns:
this returns the number of possible entrys

clear

public void clear()
This is a simple method that will purge all entrys from this list. This basically deletes the linked list and emptys the HashMap and sets the item count to zero. The garbage collector can collect all objects that were previously referenced by this list.